[PATCH 30 of 54] Refactor tests dir

Wald Commits scm-commit at wald.intevation.org
Wed Jan 7 10:56:47 CET 2015


# HG changeset patch
# User Benoît Allard <benoit.allard at greenbone.net>
# Date 1414406922 -3600
# Node ID e3ee542a89be25377cc4863d9c92475667d3e315
# Parent  e317097af486a4e032af713d3efc31b923ba37ec
Refactor tests dir

diff -r e317097af486 -r e3ee542a89be tests/testProductIdRename.py
--- a/tests/testProductIdRename.py	Mon Oct 27 11:23:33 2014 +0100
+++ b/tests/testProductIdRename.py	Mon Oct 27 11:48:42 2014 +0100
@@ -1,21 +1,9 @@
-import unittest
-
 from datetime import datetime
 
-from farolluz.cvrf import CVRF, CVRFPublisher, CVRFTracking, CVRFTrackingID, CVRFRevision, CVRFFullProductName, CVRFVulnerability, CVRFProductStatus, CVRFRelationship
+from tests.utils import TestCase
+from farolluz.cvrf import CVRFFullProductName, CVRFVulnerability, CVRFProductStatus, CVRFRelationship
 
-class TestProductIdRename(unittest.TestCase):
-
-    def setUp(self):
-        self.doc = CVRF('title', 'type')
-        self.doc.setPublisher(CVRFPublisher('Other'))
-        initial = datetime.now()
-        current = datetime.now()
-        track = CVRFTracking(CVRFTrackingID('1234'), 'Draft', (0,0), initial, current)
-        track.addRevision(CVRFRevision((0,0), current, '1st'))
-        self.doc.setTracking(track)
-        self.doc.validate()
-
+class TestProductIdRename(TestCase):
 
     def testChangeProductId(self):
         ptree = self.doc.createProductTree()
@@ -26,10 +14,10 @@
         st.addProductID('1')
         vuln.addProductStatus(st)
         self.doc.addVulnerability(vuln)
-        self.doc.validate()
+        self._validate()
         prod._productid = '2'
         self.doc.changeProductID('1', '2')
-        self.doc.validate()
+        self._validate()
 
     def testChangeProductIdRelation(self):
         ptree = self.doc.createProductTree()
@@ -39,10 +27,10 @@
         ptree.addProduct(prod2)
         rel = CVRFRelationship('1', 'Installed On', '2')
         ptree.addRelationship(rel)
-        self.doc.validate()
+        self._validate()
         prod1._productid = '3'
         self.doc.changeProductID('1', '3')
         self.doc.validate()
         prod2._productid = '1'
         self.doc.changeProductID('2', '1')
-        self.doc.validate()
+        self._validate()
diff -r e317097af486 -r e3ee542a89be tests/utils.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/utils.py	Mon Oct 27 11:48:42 2014 +0100
@@ -0,0 +1,28 @@
+import unittest
+
+from datetime import datetime
+
+from farolluz.cvrf import CVRF, CVRFPublisher, CVRFTracking, CVRFTrackingID, CVRFRevision, ValidationError
+
+def minimalDoc():
+    """ create a minimal valid document """
+    doc = CVRF('title', 'type')
+    doc.setPublisher(CVRFPublisher('Other'))
+    initial = datetime.now()
+    current = datetime.now()
+    track = CVRFTracking(CVRFTrackingID('1234'), 'Draft', (0,0), initial, current)
+    track.addRevision(CVRFRevision((0,0), current, '1st'))
+    doc.setTracking(track)
+    return doc
+
+class TestCase(unittest.TestCase):
+
+
+    def _validate(self):
+        try: self.doc.validate()
+        except ValidationError as e: self.fail(e)
+
+    def setUp(self):
+        self.doc = minimalDoc()
+        self._validate()
+


More information about the Farol-commits mailing list