diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2015-08-10 12:21:26 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-08-17 14:37:58 +0100 |
commit | 34ea4c661ee48e1986fe2375b94e5b1c5c16c8ee (patch) | |
tree | 8f757d8a4667187b153e02fdb4f188fb9db45a9a | |
parent | c1abc6f0905e4321668a483a3d5be7cef3c25401 (diff) |
toaster: rewrite test for LayerSource model
Rewritten LayerSourceVerifyInheritanceSaveLoad class from scratch.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | lib/toaster/orm/tests.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/toaster/orm/tests.py b/lib/toaster/orm/tests.py index 8bb5deca..b0c01db2 100644 --- a/lib/toaster/orm/tests.py +++ b/lib/toaster/orm/tests.py @@ -6,28 +6,34 @@ from orm.models import Project, Build, Layer, Layer_Version, Branch, ProjectLaye from orm.models import Release, ReleaseLayerSourcePriority, BitbakeVersion from django.utils import timezone +from django.db import IntegrityError import os # set TTS_LAYER_INDEX to the base url to use a different instance of the layer index -# tests to verify inheritance for the LayerSource proxy-inheritance classes class LayerSourceVerifyInheritanceSaveLoad(TestCase): + """ + Tests to verify inheritance for the LayerSource proxy-inheritance classes. + """ def test_object_creation(self): - lls = LayerSource.objects.create(name = "a1", sourcetype = LayerSource.TYPE_LOCAL, apiurl = "") - lils = LayerSource.objects.create(name = "a2", sourcetype = LayerSource.TYPE_LAYERINDEX, apiurl = "") - imls = LayerSource.objects.create(name = "a3", sourcetype = LayerSource.TYPE_IMPORTED, apiurl = "") + """Test LayerSource object creation.""" + for name, sourcetype in [("a1", LayerSource.TYPE_LOCAL), + ("a2", LayerSource.TYPE_LAYERINDEX), + ("a3", LayerSource.TYPE_IMPORTED)]: + LayerSource.objects.create(name=name, sourcetype=sourcetype) - self.assertTrue(True in map(lambda x: isinstance(x, LocalLayerSource), LayerSource.objects.all())) - self.assertTrue(True in map(lambda x: isinstance(x, LayerIndexLayerSource), LayerSource.objects.all())) - self.assertTrue(True in map(lambda x: isinstance(x, ImportedLayerSource), LayerSource.objects.all())) + objects = LayerSource.objects.all() + self.assertTrue(isinstance(objects[0], LocalLayerSource)) + self.assertTrue(isinstance(objects[1], LayerIndexLayerSource)) + self.assertTrue(isinstance(objects[2], ImportedLayerSource)) def test_duplicate_error(self): - def duplicate(): - LayerSource.objects.create(name = "a1", sourcetype = LayerSource.TYPE_LOCAL, apiurl = "") - LayerSource.objects.create(name = "a1", sourcetype = LayerSource.TYPE_LOCAL, apiurl = "") - - self.assertRaises(Exception, duplicate) + """Test creation of duplicate LayerSource objects.""" + stype = LayerSource.TYPE_LOCAL + LayerSource.objects.create(name="a1", sourcetype=stype) + with self.assertRaises(IntegrityError): + LayerSource.objects.create(name="a1", sourcetype=stype) class LILSUpdateTestCase(TransactionTestCase): |