Merge commit 'f7c5c99'

pull/7/head
Ferry Boender 10 years ago
commit 93064be2e7
  1. 51
      test/test.py

@ -8,6 +8,8 @@ import os
import copy import copy
import thread import thread
import time import time
import requests
import StringIO
base_config = { base_config = {
"title": "test", "title": "test",
@ -32,45 +34,42 @@ def run_server(sf):
if sf.running: if sf.running:
break break
class FormConfigTestCase(unittest.TestCase):
class FormConfigTestCase(unittest.TestCase):
def testMissing(self): def testMissing(self):
"""Missing script callbacks should raise an OSError""" """Missing script callbacks should raise an OSError"""
config = copy.deepcopy(base_config) self.assertRaises(OSError, scriptform.ScriptForm, 'test_formconfig_missingscript.json')
config["forms"][0]["script"] = "nonexisting.sh"
file('test.json', 'w').write(json.dumps(config))
self.assertRaises(OSError, scriptform.ScriptForm, 'test.json')
def testNoExec(self): def testNoExec(self):
"""Nonn-executable script callbacks should raise an ScriptFormError""" """Non-executable script callbacks should raise an ScriptFormError"""
config = copy.deepcopy(base_config) self.assertRaises(scriptform.ScriptFormError, scriptform.ScriptForm, 'test_formconfig_noexec.json')
config["forms"][0]["script"] = "test_noexec.sh"
file('test.json', 'w').write(json.dumps(config))
self.assertRaises(scriptform.ScriptFormError, scriptform.ScriptForm, 'test.json')
def testHidden(self): def testHidden(self):
"""Hidden forms should not show up in the list of forms""" """Hidden forms should not show up in the list of forms"""
config = copy.deepcopy(base_config) sf = scriptform.ScriptForm('test_formconfig_hidden.json')
config["forms"][0]["hidden"] = True
file('test.json', 'w').write(json.dumps(config))
sf = scriptform.ScriptForm('test.json')
fc = sf.get_form_config() fc = sf.get_form_config()
self.assertTrue(fc.get_visible_forms() == []) self.assertTrue(fc.get_visible_forms() == [])
class ScriptFormTestCase(unittest.TestCase): def testCallbackStore(self):
def setUp(self): sf = scriptform.ScriptForm('test_formconfig_callback.json')
config = copy.deepcopy(base_config) fc = sf.get_form_config()
file('test.json', 'w').write(json.dumps(config)) res = fc.callback('test_store', {})
self.sf = scriptform.ScriptForm('test.json', cache=False) self.assertEquals(res['exitcode'], 33)
run_server(self.sf) self.assertTrue('stdout' in res['stdout'])
self.assertTrue('stderr' in res['stderr'])
def tearDown(self): #def testCallbackRaw(self):
self.sf.shutdown() # sf = scriptform.ScriptForm('test_formconfig_callback.json')
# fc = sf.get_form_config()
# stdout = StringIO.StringIO()
# stderr = StringIO.StringIO()
# res = fc.callback('test_raw', {}, stdout, stderr)
# stdout.seek(0)
# stderr.seek(0)
# self.assertTrue(res['exitcode'] == 33)
# print stdout.read()
# self.assertTrue('stdout' in stdout.read())
def testShutdown(self):
self.assertTrue(True)
if os.path.exists('test.json'):
os.unlink('test.json')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save