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

Task LSMR-13: Completed functional tests for all templates

parent 850a5c50
No related branches found
No related tags found
1 merge request!87Lsmr epic
......@@ -22,10 +22,9 @@
# This functional test talks to the API like a regular user would.
# It is supposed to cover all REST http methods for all ViewSets.
# todo: For now I only covered one of the templates as they are mostly identical. I am still a bit under the impression
# todo: ...that we re-test Django functionality that we can expect to just work with some of these tests. On the other
# todo: ...hand a lot of these provide us a nice basis for differentiating out behavior in a controlled way.
# todo: So if this is generally how we want to test, we should probably still cover the other templates.
# todo: I am still a bit under the impression that we re-test Django functionality that we can expect to just work
# todo: with some of these tests. On the other hand a lot of these provide us a nice basis for differentiating out
# todo: behavior in a controlled way.
# todo: We should probably also fully test behavior wrt mandatory and nullable fields.
......@@ -197,8 +196,76 @@ class GeneratorTemplateTestCase(unittest.TestCase):
class RunTemplateTestCase(unittest.TestCase):
# todo
pass
test_data_1 = {"name": "observation",
"description": 'My one observation',
"default_version": False,
"version": 'v0.314159265359',
"schema": {"mykey": "my value"},
"tags": ["LSMR", "TESTING"]}
test_data_2 = {"name": "observation",
"description": 'My other observation',
"default_version": False,
"version": 'v3.14159265359',
"schema": {"mykey": "my other value"},
"tags": []}
test_patch = {"version": 'v6.28318530718',
"schema": {"mykey": "my better value"},
}
def test_run_template_list_apiformat(self):
r = requests.get(BASE_URL + '/run_template/?format=api')
self.assertEqual(r.status_code, 200)
self.assertTrue("Run Template List" in r.content.decode('utf8'))
def test_run_template_GET_nonexistant_raises_error(self):
GET_and_assert_expected_response(self, BASE_URL + '/run_template/1234321/', 404, {})
def test_run_template_POST_and_GET(self):
# POST and GET a new item and assert correctness
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/run_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url+'?format=json', 200, self.test_data_1)
def test_run_template_PUT_invalid_raises_error(self):
PUT_and_assert_expected_response(self, BASE_URL + '/run_template/9876789876/', self.test_data_1, 404, {})
def test_run_template_PUT(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/run_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# PUT new values, verify
PUT_and_assert_expected_response(self, url, self.test_data_2, 200, self.test_data_2)
GET_and_assert_expected_response(self, url, 200, self.test_data_2)
def test_run_template_PATCH(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/run_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# PATCH item and verify
PATCH_and_assert_expected_response(self, url, self.test_patch, 200, self.test_patch)
expected_data = dict(self.test_data_1)
expected_data.update(self.test_patch)
GET_and_assert_expected_response(self, url, 200, expected_data)
def test_run_template_DELETE(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/run_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# DELETE and check it's gone
DELETE_and_assert_gone(self, url)
class WorkRequestTemplateTestCase(unittest.TestCase):
......@@ -211,11 +278,143 @@ class WorkRequestTemplateTestCase(unittest.TestCase):
"tags": ["LSMR", "TESTING"],
"validation_code_js": "???"}
# todo
test_data_2 = {"name": "observation",
"description": 'My one observation',
"default_version": False,
"version": 'v3.14159265359',
"schema": {"mykey": "my other value"},
"tags": [],
"validation_code_js": "!!!"}
test_patch = {"version": 'v6.28318530718',
"schema": {"mykey": "my better value"},
}
def test_work_request_template_list_apiformat(self):
r = requests.get(BASE_URL + '/work_request_template/?format=api')
self.assertEqual(r.status_code, 200)
self.assertTrue("Work Request Template List" in r.content.decode('utf8'))
def test_work_request_template_GET_nonexistant_raises_error(self):
GET_and_assert_expected_response(self, BASE_URL + '/work_request_template/1234321/', 404, {})
def test_work_request_template_POST_and_GET(self):
# POST and GET a new item and assert correctness
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_request_template/', self.test_data_1, 201,
self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url + '?format=json', 200, self.test_data_1)
def test_work_request_template_PUT_invalid_raises_error(self):
PUT_and_assert_expected_response(self, BASE_URL + '/work_request_template/9876789876/', self.test_data_1, 404, {})
def test_work_request_template_PUT(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_request_template/', self.test_data_1, 201,
self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# PUT new values, verify
PUT_and_assert_expected_response(self, url, self.test_data_2, 200, self.test_data_2)
GET_and_assert_expected_response(self, url, 200, self.test_data_2)
def test_work_request_template_PATCH(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_request_template/', self.test_data_1, 201,
self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# PATCH item and verify
PATCH_and_assert_expected_response(self, url, self.test_patch, 200, self.test_patch)
expected_data = dict(self.test_data_1)
expected_data.update(self.test_patch)
GET_and_assert_expected_response(self, url, 200, expected_data)
def test_work_request_template_DELETE(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_request_template/', self.test_data_1, 201,
self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# DELETE and check it's gone
DELETE_and_assert_gone(self, url)
class WorkRelationSelectionTemplateTestCase(unittest.TestCase):
# todo
pass
# test data
test_data_1 = {"name": "observation",
"description": 'My one observation',
"default_version": False,
"version": 'v0.314159265359',
"schema": {"mykey": "my value"},
"tags": ["LSMR", "TESTING"]}
test_data_2 = {"name": "observation",
"description": 'My other observation',
"default_version": False,
"version": 'v3.14159265359',
"schema": {"mykey": "my other value"},
"tags": []}
test_patch = {"version": 'v6.28318530718',
"schema": {"mykey": "my better value"},
}
def test_work_relation_selection_template_list_apiformat(self):
r = requests.get(BASE_URL + '/work_relation_selection_template/?format=api')
self.assertEqual(r.status_code, 200)
self.assertTrue("Work Relation Selection Template List" in r.content.decode('utf8'))
def test_work_relation_selection_template_GET_nonexistant_raises_error(self):
GET_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/1234321/', 404, {})
def test_work_relation_selection_template_POST_and_GET(self):
# POST and GET a new item and assert correctness
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url+'?format=json', 200, self.test_data_1)
def test_work_relation_selection_template_PUT_invalid_raises_error(self):
PUT_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/9876789876/', self.test_data_1, 404, {})
def test_work_relation_selection_template_PUT(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# PUT new values, verify
PUT_and_assert_expected_response(self, url, self.test_data_2, 200, self.test_data_2)
GET_and_assert_expected_response(self, url, 200, self.test_data_2)
def test_work_relation_selection_template_PATCH(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# PATCH item and verify
PATCH_and_assert_expected_response(self, url, self.test_patch, 200, self.test_patch)
expected_data = dict(self.test_data_1)
expected_data.update(self.test_patch)
GET_and_assert_expected_response(self, url, 200, expected_data)
def test_work_relation_selection_template_DELETE(self):
# POST new item, verify
r_dict = POST_and_assert_expected_response(self, BASE_URL + '/work_relation_selection_template/', self.test_data_1, 201, self.test_data_1)
url = r_dict['url']
GET_and_assert_expected_response(self, url, 200, self.test_data_1)
# DELETE and check it's gone
DELETE_and_assert_gone(self, url)
class WorkIORolesTestCase(unittest.TestCase):
......
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