Commit bd711df6 authored by Romain Courteaud's avatar Romain Courteaud

Test availability check

parent 64a6cf01
......@@ -825,6 +825,271 @@ class TestInstanceGETcertificate(VifibSlaposRestAPIV1InstanceMixin):
self.assertBasicResponse()
self.assertResponseCode(404)
class TestInstanceAllocableGET(VifibSlaposRestAPIV1InstanceMixin):
def test_not_logged_in(self):
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']))
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(401)
self.assertTrue(self.response.getheader('Location') is not None)
auth = self.response.getheader('WWW-Authenticate')
self.assertTrue(auth is not None)
self.assertTrue('Bearer realm="' in auth)
self.assertPersonRequestSimulatorEmpty()
def test_no_json(self):
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({'error': "Data is not json object."}, self.json_response)
self.assertPersonRequestSimulatorEmpty()
def test_bad_json(self):
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body='This is not JSON',
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({'error': "Data is not json object."}, self.json_response)
self.assertPersonRequestSimulatorEmpty()
def test_empty_json(self):
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body='{}',
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({
"status": "Missing.",
"slave": "Missing.",
"title": "Missing.",
"software_release": "Missing.",
"software_type": "Missing.",
"parameter": "Missing.",
"sla": "Missing."},
self.json_response)
self.assertPersonRequestSimulatorEmpty()
def test_status_slave_missing_json(self):
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body="""
{
"title": "My unique instance",
"software_release": "http://example.com/example.cfg",
"software_type": "type_provided_by_the_software",
"parameter": {
"Custom1": "one string",
"Custom2": "one float",
"Custom3": [
"abc",
"def"
]
},
"sla": {
"computer_id": "COMP-0"
}
}""",
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({
"status": "Missing.",
"slave": "Missing."
},
self.json_response)
self.assertPersonRequestSimulatorEmpty()
def test_slave_not_bool(self):
kwargs = {
'parameter': {
'Custom1': 'one string',
'Custom2': 'one float',
'Custom3': ['abc', 'def']},
'title': 'My unique instance',
'software_release': 'http://example.com/example.cfg',
'status': 'started',
'sla': {
'computer_id': 'COMP-0'},
'software_type': 'type_provided_by_the_software',
'slave': "True"}
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body=json.dumps(kwargs),
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({
"slave": "unicode is not bool.",
},
self.json_response)
self.assertPersonRequestSimulatorEmpty()
def test_incorrect_status(self):
kwargs = {
'parameter': {
'Custom1': 'one string',
'Custom2': 'one float',
'Custom3': ['abc', 'def']},
'title': 'My unique instance',
'software_release': 'http://example.com/example.cfg',
'status': 'badstatus',
'sla': {
'computer_id': 'COMP-0'},
'software_type': 'type_provided_by_the_software',
'slave': True}
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body=json.dumps(kwargs),
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({
"status": "Status shall be one of: started, stopped, destroyed.",
},
self.json_response)
self.assertPersonRequestSimulatorEmpty()
def test_correct(self):
kwargs = {
'parameter': {
'Custom1': 'one string',
'Custom2': 'one float',
'Custom3': ['abc', 'def']},
'title': 'My unique instance',
'software_release': 'http://example.com/example.cfg',
'status': 'started',
'sla': {
'computer_id': 'COMP-0'},
'software_type': 'type_provided_by_the_software',
'slave': True}
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body=json.dumps(kwargs),
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(200)
self.assertResponseJson()
def test_additional_key_json(self):
kw_request = {
'parameter': {
'Custom1': 'one string',
'Custom2': 'one float',
'Custom3': ['abc', 'def']},
'title': 'My unique instance',
'software_release': 'http://example.com/example.cfg',
'status': 'started',
'sla': {
'computer_id': 'COMP-0'},
'software_type': 'type_provided_by_the_software',
'slave': True}
kwargs = kw_request.copy()
kwargs.update(**{'wrong_key': 'Be ignored'})
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body=json.dumps(kwargs),
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(200)
self.assertResponseJson()
# def test_correct_server_side_raise(self):
# self.customer.requestSoftwareInstance = \
# RaisingSimulator(AttributeError)
# transaction.commit()
# kwargs = {
# 'parameter': {
# 'Custom1': 'one string',
# 'Custom2': 'one float',
# 'Custom3': ['abc', 'def']},
# 'title': 'My unique instance',
# 'software_release': 'http://example.com/example.cfg',
# 'status': 'started',
# 'sla': {
# 'computer_id': 'COMP-0'},
# 'software_type': 'type_provided_by_the_software',
# 'slave': True}
# self.connection.request(method='GET',
# url='/'.join([self.api_path, 'instance', 'request']),
# body=json.dumps(kwargs),
# headers={'REMOTE_USER': self.customer_reference})
# self.prepareResponse()
# self.assertBasicResponse()
# self.assertResponseCode(500)
# self.assertResponseJson()
# self.assertEqual({
# "error": "There is system issue, please try again later.",
# },
# self.json_response)
# self.assertPersonRequestSimulatorEmpty()
def test_content_negotiation_headers(self):
self.connection = CustomHeaderHTTPConnection(host=self.api_netloc,
custom_header={
'Access-Control-Request-Headers': self.access_control_allow_headers
})
kwargs = {
'parameter': {
'Custom1': 'one string',
'Custom2': 'one float',
'Custom3': ['abc', 'def']},
'title': 'My unique instance',
'software_release': 'http://example.com/example.cfg',
'status': 'started',
'sla': {
'computer_id': 'COMP-0'},
'software_type': 'type_provided_by_the_software',
'slave': True}
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body=json.dumps(kwargs),
headers={'REMOTE_USER': self.customer_reference})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({
'Content-Type': "Header with value '^application/json.*' is required."},
self.json_response)
self.assertPersonRequestSimulatorEmpty()
# now check with incorrect headers
self.connection.request(method='GET',
url='/'.join([self.api_path, 'instance', 'request']),
body=json.dumps(kwargs),
headers={'REMOTE_USER': self.customer_reference,
'Content-Type': 'please/complain',
'Accept': 'be/silent'})
self.prepareResponse()
self.assertBasicResponse()
self.assertResponseCode(400)
self.assertResponseJson()
self.assertEqual({
'Content-Type': "Header with value '^application/json.*' is required."},
self.json_response)
self.assertPersonRequestSimulatorEmpty()
# and with correct ones are set by default
def VifibSlaposRestAPIV1BangMixin_afterSetUp(self):
VifibSlaposRestAPIV1BangMixin_afterSetUp(self)
self.instance_bang_simulator = tempfile.mkstemp()[1]
......
79
\ No newline at end of file
80
\ 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