[bitbake-devel] [PATCH 03/11] toaster: rewrite test for LayerSource model
Michael Wood
michael.g.wood at intel.com
Mon Aug 10 11:21:26 UTC 2015
From: Ed Bartosh <ed.bartosh at linux.intel.com>
Rewritten LayerSourceVerifyInheritanceSaveLoad class from scratch.
Signed-off-by: Ed Bartosh <ed.bartosh at linux.intel.com>
Signed-off-by: Michael Wood <michael.g.wood at intel.com>
---
lib/toaster/orm/tests.py | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/lib/toaster/orm/tests.py b/lib/toaster/orm/tests.py
index 8bb5dec..b0c01db 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):
--
2.1.4
More information about the bitbake-devel
mailing list