Some simple and proposed tests for the ScriptDB object. These pass OK with ./manage.py test, at least after running the server at least once.

This commit is contained in:
Russell Jones 2014-05-05 19:03:33 +01:00
parent 12c2402dac
commit 2b2d222e83

View file

@ -1,19 +1,58 @@
try:
# this is an optimized version only available in later Django versions
from django.utils.unittest import TestCase
except ImportError:
# if the first fails, we use the old version
from django.test import TestCase
from src.scripts.models import ScriptDB, ObjectDoesNotExist
from src.utils.create import create_script
from src.scripts import DoNothing
import unittest
from django.conf import settings
class TestScriptDB(unittest.TestCase):
def test___init__(self):
# script_d_b = ScriptDB(*args, **kwargs)
assert True # TODO: implement your test here
def test_at_typeclass_error(self):
# script_d_b = ScriptDB(*args, **kwargs)
# self.assertEqual(expected, script_d_b.at_typeclass_error())
assert True # TODO: implement your test here
class TestScriptDB(TestCase):
"Check the singleton/static ScriptDB object works correctly"
def setUp(self):
self.scr = create_script(DoNothing)
def tearDown(self):
self.scr.delete()
del self.scr
def test_delete(self):
# script_d_b = ScriptDB(*args, **kwargs)
# self.assertEqual(expected, script_d_b.delete())
assert True # TODO: implement your test here
"Check the script is removed from the database"
self.scr.delete()
self.assertFalse(self.scr in ScriptDB.objects.get_all_scripts())
def test_double_delete(self):
"What should happen? Isn't it already deleted?"
self.scr.delete()
self.scr.delete()
@unittest.skip("not implemented")
def test___init__fails(self): # Users should be told not to do this
with self.assertRaises(Exception):
ScriptDB()
@unittest.skip("not implemented")
def test_deleted_script_fails_start(self):
"Would it ever be necessary to start a deleted script?"
self.scr.delete()
with self.assertRaises(ObjectDoesNotExist): # See issue #509
self.scr.start()
# Check the script is not recreated as a side-effect
self.assertFalse(self.scr in ScriptDB.objects.get_all_scripts())
self.scr = create_script(DoNothing) # for tearDown()
@unittest.skip("not implemented")
def test_deleted_script_is_invalid(self):
"Can deleted scripts be said to be valid?"
self.scr.delete()
self.assertFalse(self.scr.is_valid()) # assertRaises? See issue #509
self.scr = create_script(DoNothing) # for tearDown()
if __name__ == '__main__':
unittest.main()