Skip to content
Snippets Groups Projects
Commit 4d37ddd8 authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

Task LSMR-14: Fixed functional tests to work with new choices implementation

parent d6898834
No related branches found
No related tags found
1 merge request!87Lsmr epic
...@@ -87,7 +87,7 @@ DATABASES = { ...@@ -87,7 +87,7 @@ DATABASES = {
'USER': 'lsmruser', 'USER': 'lsmruser',
'PASS': 'lsmrpass2', 'PASS': 'lsmrpass2',
'HOST': 'localhost', 'HOST': 'localhost',
'PORT': 5432, 'PORT': 7666,
} }
} }
......
...@@ -54,7 +54,7 @@ def _call_API_and_assert_expected_response(self, url, call, data, expected_code, ...@@ -54,7 +54,7 @@ def _call_API_and_assert_expected_response(self, url, call, data, expected_code,
raise ValueError("The provided call '%s' is not a valid API method choice" % call) raise ValueError("The provided call '%s' is not a valid API method choice" % call)
if response.status_code is not expected_code: if response.status_code is not expected_code:
print(response.content) print("[%s] - %s %s: %s" % (self.id(), call, url, response.content))
self.assertEqual(response.status_code, expected_code) self.assertEqual(response.status_code, expected_code)
r_dict = json.loads(response.content.decode('utf-8')) r_dict = json.loads(response.content.decode('utf-8'))
for item in expected_content.items(): for item in expected_content.items():
...@@ -103,12 +103,12 @@ def DELETE_and_assert_gone(self, url): ...@@ -103,12 +103,12 @@ def DELETE_and_assert_gone(self, url):
""" """
response = requests.delete(url) response = requests.delete(url)
if response.status_code is not 204: if response.status_code is not 204:
print(response.content) print("[%s] - %s %s: %s" % (self.id(), 'DELETE', url, response.content))
self.assertEqual(response.status_code, 204) self.assertEqual(response.status_code, 204)
response = requests.get(url) response = requests.get(url)
if response.status_code is not 404: if response.status_code is not 404:
print(response.content) print("[%s] - %s %s: %s" % (self.id(), 'GET', url, response.content))
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
...@@ -155,7 +155,7 @@ class GeneratorTemplateTestCase(unittest.TestCase): ...@@ -155,7 +155,7 @@ class GeneratorTemplateTestCase(unittest.TestCase):
# POST and GET a new item and assert correctness # POST and GET a new item and assert correctness
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/generator_template/', self.test_data_1, 201, self.test_data_1) r_dict = POST_and_assert_expected_response(self, BASE_URL + '/generator_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url'] url = r_dict['url']
GET_and_assert_expected_response(self, url+'?format=json', 200, self.test_data_1) GET_and_assert_expected_response(self, url, 200, self.test_data_1)
def test_generator_template_PUT_invalid_raises_error(self): def test_generator_template_PUT_invalid_raises_error(self):
PUT_and_assert_expected_response(self, BASE_URL + '/generator_template/9876789876/', self.test_data_1, 404, {}) PUT_and_assert_expected_response(self, BASE_URL + '/generator_template/9876789876/', self.test_data_1, 404, {})
...@@ -420,22 +420,22 @@ class WorkRelationSelectionTemplateTestCase(unittest.TestCase): ...@@ -420,22 +420,22 @@ class WorkRelationSelectionTemplateTestCase(unittest.TestCase):
class WorkIORolesTestCase(unittest.TestCase): class WorkIORolesTestCase(unittest.TestCase):
# test data # test data
test_data_1 = {"role": "CALIBRATOR", test_data_1 = {"role": BASE_URL + '/role_choice/correlator/',
"datatype": "INSTRUMENT_MODEL", "datatype": BASE_URL + '/datatype_choice/image/',
"dataformat": ['HDF5'], "dataformat": BASE_URL + '/dataformat_choice/HDF5/',
"outputs": None, "outputs": None,
"inputs": None "inputs": None
} }
test_data_2 = {"role": "TARGET", test_data_2 = {"role": BASE_URL + '/role_choice/target/',
"datatype": "VISIBILITIES", "datatype": BASE_URL + '/datatype_choice/visibilities/',
"dataformat": ['MEASUREMENTSET'], "dataformat": BASE_URL + '/dataformat_choice/MeasurementSet/',
"outputs": None, "outputs": None,
"inputs": None "inputs": None
} }
test_patch = {"role": 'CORRELATOR', test_patch = {"role": BASE_URL + '/role_choice/calibrator/',
"dataformat": ['MEASUREMENTSET', "HDF5"] "dataformat": BASE_URL + '/dataformat_choice/MeasurementSet/'
} }
def test_work_io_roles_list_apiformat(self): def test_work_io_roles_list_apiformat(self):
...@@ -450,31 +450,31 @@ class WorkIORolesTestCase(unittest.TestCase): ...@@ -450,31 +450,31 @@ class WorkIORolesTestCase(unittest.TestCase):
# POST and GET a new item and assert correctness # POST and GET a new item and assert correctness
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', self.test_data_1, 201, self.test_data_1) r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url'] url = r_dict['url']
GET_and_assert_expected_response(self, url + '?format=json', 200, self.test_data_1) GET_and_assert_expected_response(self, url, 200, self.test_data_1)
def test_work_io_roles_POST_invalid_role_raises_error(self): def test_work_io_roles_POST_invalid_role_raises_error(self):
# POST a new item with invalid choice # POST a new item with invalid choice
test_data_invalid_role = dict(self.test_data_1) test_data_invalid_role = dict(self.test_data_1)
test_data_invalid_role['role'] = 'forbidden' test_data_invalid_role['role'] = BASE_URL + '/role_choice/forbidden/'
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid_role, 400, {}) r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid_role, 400, {})
self.assertTrue('not a valid choice' in str(r_dict['role'])) self.assertTrue('Invalid hyperlink' in str(r_dict['role']))
def test_work_io_roles_POST_invalid_datatype_raises_error(self): def test_work_io_roles_POST_invalid_datatype_raises_error(self):
# POST a new item with invalid choice # POST a new item with invalid choice
test_data_invalid = dict(self.test_data_1) test_data_invalid = dict(self.test_data_1)
test_data_invalid['datatype'] = 'forbidden' test_data_invalid['datatype'] = BASE_URL + '/datatype_choice/forbidden/'
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {}) r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {})
self.assertTrue('not a valid choice' in str(r_dict['datatype'])) self.assertTrue('Invalid hyperlink' in str(r_dict['datatype']))
def test_work_io_roles_POST_invalid_dataformat_raises_error(self): def test_work_io_roles_POST_invalid_dataformat_raises_error(self):
# POST a new item with invalid choice # POST a new item with invalid choice
test_data_invalid = dict(self.test_data_1) test_data_invalid = dict(self.test_data_1)
test_data_invalid['dataformat'] = ['forbidden', "HDF5"] test_data_invalid['dataformat'] = BASE_URL + '/dataformat_choice/forbidden/'
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {}) r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_io_roles/', test_data_invalid, 400, {})
self.assertTrue('not a valid choice' in str(r_dict['dataformat'])) self.assertTrue('Invalid hyperlink' in str(r_dict['dataformat']))
def test_work_io_roles_POST_nonexistant_inputs_raises_error(self): def test_work_io_roles_POST_nonexistant_inputs_raises_error(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment