diff options
author | Serena Feng <feng.xiaowei@zte.com.cn> | 2018-01-04 08:59:41 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-01-04 08:59:41 +0000 |
commit | 8dbe224064851d439b18ad4254e119aff7f02e30 (patch) | |
tree | 939ff74837fe2593b532a455c65b06edba6ec957 /testapi/opnfv_testapi/tests/unit/handlers | |
parent | 6d98b992423084dd737e80322c9360e0712368a2 (diff) | |
parent | 8dd0bcd2e98d283619d12c9734c126b19757f065 (diff) |
Merge "simplify test_pod.py with eq"
Diffstat (limited to 'testapi/opnfv_testapi/tests/unit/handlers')
-rw-r--r-- | testapi/opnfv_testapi/tests/unit/handlers/test_base.py | 4 | ||||
-rw-r--r-- | testapi/opnfv_testapi/tests/unit/handlers/test_pod.py | 37 |
2 files changed, 13 insertions, 28 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_base.py b/testapi/opnfv_testapi/tests/unit/handlers/test_base.py index c98ed69..6436b8b 100644 --- a/testapi/opnfv_testapi/tests/unit/handlers/test_base.py +++ b/testapi/opnfv_testapi/tests/unit/handlers/test_base.py @@ -36,14 +36,14 @@ class TestBase(testing.AsyncHTTPTestCase): role='community-ci', _id=str(ObjectId()), owner='ValidUser', - create_date=str(datetime.now())) + creation_date=str(datetime.now())) self.pod_e = pod_models.Pod(name='zte-pod2', mode='metal', details='zte pod 2', role='production-ci', _id=str(ObjectId()), owner='ValidUser', - create_date=str(datetime.now())) + creation_date=str(datetime.now())) self.project_e = project_models.Project( name='functest', description='functest test', diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py b/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py index 95ed8ba..2818513 100644 --- a/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py +++ b/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py @@ -7,10 +7,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import httplib -import unittest from opnfv_testapi.common import message -from opnfv_testapi.models import pod_models +from opnfv_testapi.models import pod_models as pm from opnfv_testapi.tests.unit import executor from opnfv_testapi.tests.unit import fake_pymongo from opnfv_testapi.tests.unit.handlers import test_base as base @@ -19,26 +18,16 @@ from opnfv_testapi.tests.unit.handlers import test_base as base class TestPodBase(base.TestBase): def setUp(self): super(TestPodBase, self).setUp() - self.get_res = pod_models.Pod - self.list_res = pod_models.Pods + self.get_res = pm.Pod + self.list_res = pm.Pods self.basePath = '/api/v1/pods' - self.req_d = pod_models.PodCreateRequest(name=self.pod_d.name, - mode=self.pod_d.mode, - details=self.pod_d.details, - role=self.pod_d.role) - self.req_e = pod_models.PodCreateRequest(name=self.pod_e.name, - mode=self.pod_e.mode, - details=self.pod_e.details, - role=self.pod_e.role) + self.req_d = pm.PodCreateRequest.from_dict(self.pod_d.format()) + self.req_e = pm.PodCreateRequest.from_dict(self.pod_e.format()) def assert_get_body(self, pod, req=None): if not req: req = self.req_d - self.assertEqual(pod.owner, 'ValidUser') - self.assertEqual(pod.name, req.name) - self.assertEqual(pod.mode, req.mode) - self.assertEqual(pod.details, req.details) - self.assertEqual(pod.role, req.role) + self.assertEqual(pod, pm.Pod(owner='ValidUser', **req.format())) self.assertIsNotNone(pod.creation_date) self.assertIsNotNone(pod._id) @@ -61,12 +50,12 @@ class TestPodCreate(TestPodBase): @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_emptyName(self): - return pod_models.PodCreateRequest('') + return pm.PodCreateRequest('') @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_noneName(self): - return pod_models.PodCreateRequest(None) + return pm.PodCreateRequest(None) @executor.mock_valid_lfid() @executor.create(httplib.OK, 'assert_create_body') @@ -99,7 +88,7 @@ class TestPodGet(TestPodBase): @executor.get(httplib.OK, 'assert_get_body') def test_getOne(self): - return self.pod_d.name + return self.req_d.name @executor.get(httplib.OK, '_assert_list') def test_list(self): @@ -108,11 +97,7 @@ class TestPodGet(TestPodBase): def _assert_list(self, body): self.assertEqual(len(body.pods), 2) for pod in body.pods: - if self.pod_d.name == pod.name: + if self.req_d.name == pod.name: self.assert_get_body(pod) else: - self.assert_get_body(pod, self.pod_e) - - -if __name__ == '__main__': - unittest.main() + self.assert_get_body(pod, self.req_e) |