More unit tests.

pull/7/head
Ferry Boender 10 years ago
parent 2a5157d198
commit 9f7b7ddc16
  1. 30
      test/test.py
  2. 10
      test/test_upload.sh
  3. 13
      test/test_webapp.json

@ -90,7 +90,6 @@ class FormDefinitionTest(unittest.TestCase):
def testRequired(self):
fd = self.fc.get_form_def('test_required')
form_values = {}
errors, values = fd.validate(form_values)
self.assertIn('string', errors)
@ -234,14 +233,24 @@ class WebAppTest(unittest.TestCase):
r = requests.get('http://localhost:8002/')
self.assertEqual(r.status_code, 401)
def testAuthFormNoAuth(self):
def testAuthFormNoAuthGet(self):
r = requests.get('http://localhost:8002/form?form_name=admin_only')
self.assertEqual(r.status_code, 401)
def testAuthFormWrongAuth(self):
def testAuthFormNoAuthPost(self):
data = {"form_name": 'admin_only'}
r = requests.post('http://localhost:8002/submit', data)
self.assertEqual(r.status_code, 401)
def testAuthFormWrongAuthGet(self):
r = requests.get('http://localhost:8002/form?form_name=admin_only', auth=self.auth_user)
self.assertEqual(r.status_code, 401)
def testAuthFormWrongAuthPost(self):
data = {"form_name": 'admin_only'}
r = requests.post('http://localhost:8002/submit', data, auth=self.auth_user)
self.assertEqual(r.status_code, 401)
def testHidden(self):
"""Hidden forms shouldn't appear in the output"""
r = requests.get('http://localhost:8002/', auth=self.auth_user)
@ -275,6 +284,21 @@ class WebAppTest(unittest.TestCase):
r = requests.post('http://localhost:8002/submit', data, auth=self.auth_user)
self.assertIn('string=<foo>', r.text)
def testUpload(self):
import random
f = file('data.raw', 'w')
for i in range(1024):
f.write(chr(random.randint(0, 255)))
f.close()
data = {
"form_name": "upload"
}
files = {'file': open('data.raw', 'rb')}
r = requests.post("http://localhost:8002/submit", files=files, data=data, auth=self.auth_user)
self.assertIn('SAME', r.text)
os.unlink('data.raw')
if __name__ == '__main__':
import coverage

@ -0,0 +1,10 @@
#!/bin/sh
MD5_UPLOAD=$(md5sum ${file} | cut -d" " -f1)
MD5_ORIG=$(md5sum "data.raw" | cut -d" " -f1)
if [ "$MD5_UPLOAD" = "$MD5_ORIG" ]; then
echo "SAME"
else
echo "DIFFERENT"
fi

@ -125,6 +125,19 @@
"extensions": ["csv"]
}
]
},
{
"name": "upload",
"title": "Upload",
"description": "Upload",
"script": "test_upload.sh",
"fields": [
{
"name": "file",
"title": "File upload",
"type": "file"
}
]
}
]
}

Loading…
Cancel
Save