Mercurial > farol > farolluz
changeset 29:e3ee542a89be
Refactor tests dir
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Mon, 27 Oct 2014 11:48:42 +0100 |
parents | e317097af486 |
children | b15022ae484a |
files | tests/testProductIdRename.py tests/utils.py |
diffstat | 2 files changed, 35 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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 - -class TestProductIdRename(unittest.TestCase): +from tests.utils import TestCase +from farolluz.cvrf import CVRFFullProductName, CVRFVulnerability, CVRFProductStatus, CVRFRelationship - 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()
--- /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() +