Commit 2d325cbf authored by Łukasz Nowak's avatar Łukasz Nowak

Factorise even more.

Simplify test method names. Put components in different test cases.
parent 38c5727a
...@@ -141,7 +141,7 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase): ...@@ -141,7 +141,7 @@ class VifibSlaposRestAPIV1Mixin(ERP5TypeTestCase):
self.assertEqual(args, recargs) self.assertEqual(args, recargs)
self.assertEqual(kwargs, reckwargs) self.assertEqual(kwargs, reckwargs)
class TestVifibSlaposRestAPIV1InstanceRequest(VifibSlaposRestAPIV1Mixin): class TestInstanceRequest(VifibSlaposRestAPIV1Mixin):
def test_not_logged_in(self): def test_not_logged_in(self):
self.connection.request(method='POST', self.connection.request(method='POST',
url='/'.join([self.api_path, 'instance'])) url='/'.join([self.api_path, 'instance']))
...@@ -364,7 +364,21 @@ class TestVifibSlaposRestAPIV1InstanceRequest(VifibSlaposRestAPIV1Mixin): ...@@ -364,7 +364,21 @@ class TestVifibSlaposRestAPIV1InstanceRequest(VifibSlaposRestAPIV1Mixin):
self.assertSimulatorEmpty() self.assertSimulatorEmpty()
# and with correct ones are set by default # and with correct ones are set by default
class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): class TestInstanceOPTIONS(VifibSlaposRestAPIV1Mixin):
def test_OPTIONS_not_logged_in(self):
self.connection = CustomHeaderHTTPConnection(host=self.api_netloc,
custom_header={
'Access-Control-Allow-Headers': self.access_control_allow_headers
})
self.connection.request(method='OPTIONS',
url='/'.join([self.api_path, 'instance']))
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(204)
self.assertResponseNoContentType()
self.assertSimulatorEmpty()
class VifibSlaposRestAPIV1InstanceMixin(VifibSlaposRestAPIV1Mixin):
def afterSetUp(self): def afterSetUp(self):
VifibSlaposRestAPIV1Mixin.afterSetUp(self) VifibSlaposRestAPIV1Mixin.afterSetUp(self)
self.software_instance = self.createSoftwareInstance(self.customer) self.software_instance = self.createSoftwareInstance(self.customer)
...@@ -397,20 +411,15 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -397,20 +411,15 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
software_instance.recursiveImmediateReindexObject() software_instance.recursiveImmediateReindexObject()
return software_instance return software_instance
def test_OPTIONS_not_logged_in(self): # needed to avoid calling interaction and being able to destroy XML
self.connection = CustomHeaderHTTPConnection(host=self.api_netloc, @WorkflowMethod.disable
custom_header={ def _destroySoftwareInstanceTextContentXml(self, software_instance):
'Access-Control-Allow-Headers': self.access_control_allow_headers software_instance.setTextContent('This is bad XML')
}) transaction.commit()
self.connection.request(method='OPTIONS', software_instance.recursiveImmediateReindexObject()
url='/'.join([self.api_path, 'instance']))
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(204)
self.assertResponseNoContentType()
self.assertSimulatorEmpty()
def test_software_instance_GET_non_existing(self): class TestInstanceGET(VifibSlaposRestAPIV1InstanceMixin):
def test_non_existing(self):
non_existing = 'software_instance_module/' + self.generateNewId() non_existing = 'software_instance_module/' + self.generateNewId()
try: try:
self.portal.restrictedTraverse(non_existing) self.portal.restrictedTraverse(non_existing)
...@@ -426,7 +435,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -426,7 +435,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
self.assertBasicResponse() self.assertBasicResponse()
self.assertResponseCode(404) self.assertResponseCode(404)
def test_software_instance_GET_something_else(self): def test_something_else(self):
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
self.software_instance.getPredecessorRelatedValue().getRelativeUrl()]), self.software_instance.getPredecessorRelatedValue().getRelativeUrl()]),
...@@ -435,14 +444,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -435,14 +444,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
self.assertBasicResponse() self.assertBasicResponse()
self.assertResponseCode(404) self.assertResponseCode(404)
# needed to avoid calling interaction and being able to destroy XML def test_bad_xml(self):
@WorkflowMethod.disable
def _destroySoftwareInstanceTextContentXml(self, software_instance):
software_instance.setTextContent('This is bad XML')
transaction.commit()
software_instance.recursiveImmediateReindexObject()
def test_software_instance_GET_bad_xml(self):
self._destroySoftwareInstanceTextContentXml(self.software_instance) self._destroySoftwareInstanceTextContentXml(self.software_instance)
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
...@@ -456,7 +458,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -456,7 +458,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
"error": "There is system issue, please try again later."}, "error": "There is system issue, please try again later."},
self.json_response) self.json_response)
def test_software_instance_GET(self): def test(self):
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
self.software_instance.getRelativeUrl()]), self.software_instance.getRelativeUrl()]),
...@@ -485,7 +487,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -485,7 +487,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
"sla": {"computer_guid": "SOMECOMP"}}, "sla": {"computer_guid": "SOMECOMP"}},
self.json_response) self.json_response)
def test_software_instance_GET_other_one(self): def test_other_one(self):
person, person_reference = self.createPerson() person, person_reference = self.createPerson()
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
...@@ -495,7 +497,8 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -495,7 +497,8 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
self.assertBasicResponse() self.assertBasicResponse()
self.assertResponseCode(404) self.assertResponseCode(404)
def test_software_instance_GET_certificate(self): class TestInstanceGETcertificate(VifibSlaposRestAPIV1InstanceMixin):
def test(self):
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
self.software_instance.getRelativeUrl(), 'certificate']), self.software_instance.getRelativeUrl(), 'certificate']),
...@@ -510,7 +513,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -510,7 +513,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
}, },
self.json_response) self.json_response)
def test_software_instance_GET_certificate_bad_xml(self): def test_bad_xml(self):
self._destroySoftwareInstanceTextContentXml(self.software_instance) self._destroySoftwareInstanceTextContentXml(self.software_instance)
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
...@@ -526,7 +529,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -526,7 +529,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
}, },
self.json_response) self.json_response)
def test_software_instance_GET_certificate_non_existing(self): def test_non_existing(self):
non_existing = 'software_instance_module/' + self.generateNewId() non_existing = 'software_instance_module/' + self.generateNewId()
try: try:
self.portal.restrictedTraverse(non_existing) self.portal.restrictedTraverse(non_existing)
...@@ -542,7 +545,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -542,7 +545,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
self.assertBasicResponse() self.assertBasicResponse()
self.assertResponseCode(404) self.assertResponseCode(404)
def test_software_instance_GET_certificate_something_else(self): def test_something_else(self):
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
self.software_instance.getPredecessorRelatedValue().getRelativeUrl(), self.software_instance.getPredecessorRelatedValue().getRelativeUrl(),
...@@ -552,7 +555,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -552,7 +555,7 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
self.assertBasicResponse() self.assertBasicResponse()
self.assertResponseCode(404) self.assertResponseCode(404)
def test_software_instance_GET_certificate_other_one(self): def test_other_one(self):
person, person_reference = self.createPerson() person, person_reference = self.createPerson()
self.connection.request(method='GET', self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', url='/'.join([self.api_path, 'instance',
...@@ -561,5 +564,3 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin): ...@@ -561,5 +564,3 @@ class TestVifibSlaposRestAPIV1Instance(VifibSlaposRestAPIV1Mixin):
self.prepareResponse() self.prepareResponse()
self.assertBasicResponse() self.assertBasicResponse()
self.assertResponseCode(404) self.assertResponseCode(404)
19 20
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment