Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated rest api tests to fix issue of random sorting list entries of same type #2106

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 38 additions & 30 deletions aiida/backends/tests/restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,9 @@ def process_test(self, node_type, url, full_list=False, empty_list=False,
self.assertTrue(
len(response["data"][result_name]) == len(expected_data))

for expected_node, response_node in zip(expected_data,
response["data"][
result_name]):

self.assertTrue(all(item in response_node.items()
for item in expected_node.items()))
expected_node_uuids = [node['uuid'] for node in expected_data]
result_node_uuids = [node['uuid'] for node in response["data"][result_name]]
self.assertEqual(expected_node_uuids, result_node_uuids)

self.compare_extra_response_data(node_type, url, response, uuid)

Expand All @@ -298,10 +295,10 @@ def test_computers_details(self):
"""
Requests the details of single computer
"""
node_uuid = self.get_dummy_data()["computers"][0]["uuid"]
node_uuid = self.get_dummy_data()["computers"][1]["uuid"]
RESTApiTestCase.process_test(self, "computers",
"/computers/" + str(node_uuid),
expected_list_ids=[0], uuid=node_uuid)
expected_list_ids=[1], uuid=node_uuid)

############### full list with limit, offset, page, perpage #############
def test_computers_list(self):
Expand Down Expand Up @@ -416,10 +413,10 @@ def test_computers_filter_id1(self):
Add filter on the id of computer and get the filtered computer
list (e.g. id=1)
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
node_pk = self.get_dummy_data()["computers"][1]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?id=" + str(node_pk),
expected_list_ids=[0])
expected_list_ids=[1])

def test_computers_filter_id2(self):
"""
Expand All @@ -436,10 +433,10 @@ def test_computers_filter_pk(self):
Add filter on the id of computer and get the filtered computer
list (e.g. id=1)
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
node_pk = self.get_dummy_data()["computers"][1]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?pk=" + str(node_pk),
expected_list_ids=[0])
expected_list_ids=[1])

def test_computers_filter_name(self):
"""
Expand All @@ -466,8 +463,8 @@ def test_computers_filter_transport_type(self):
list
"""
RESTApiTestCase.process_test(self, "computers",
'/computers?transport_type="local"&orderby=+id',
expected_list_ids=[0, 3])
'/computers?transport_type="local"&name="test3"&orderby=+id',
expected_list_ids=[3])

############### list orderby ########################
def test_computers_orderby_id_asc(self):
Expand Down Expand Up @@ -501,54 +498,63 @@ def test_computers_orderby_name_asc(self):
Returns the computers list ordered by "name" in ascending
order
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=name",
full_list=True)
'/computers?pk>' + str(node_pk)+'&orderby=name',
expected_list_ids=[1, 2, 3, 4])

def test_computers_orderby_name_asc_sign(self):
"""
Returns the computers list ordered by "+name" in ascending
order
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=+name",
full_list=True)
'/computers?pk>' + str(node_pk)+'&orderby=+name',
expected_list_ids=[1, 2, 3, 4])

def test_computers_orderby_name_desc(self):
"""
Returns the computers list ordered by "name" in descending
order
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=-name",
expected_list_ids=[4, 3, 2, 1, 0])
'/computers?pk>' + str(node_pk)+'&orderby=-name',
expected_list_ids=[4, 3, 2, 1])

def test_computers_orderby_scheduler_type_asc(self):
"""
Returns the computers list ordered by "scheduler_type" in ascending
order
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=scheduler_type",
expected_list_ids=[0, 1, 3, 4, 2])
'/computers?transport_type="ssh"&pk>' +
str(node_pk)+'&orderby=scheduler_type',
expected_list_ids=[1, 4, 2])

def test_computers_orderby_scheduler_type_asc_sign(self):
"""
Returns the computers list ordered by "+scheduler_type" in ascending
order
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=+scheduler_type",
expected_list_ids=[0, 1, 3, 4, 2])
'/computers?transport_type="ssh"&pk>' +
str(node_pk)+'&orderby=+scheduler_type',
expected_list_ids=[1, 4, 2])

def test_computers_orderby_scheduler_type_desc(self):
"""
Returns the computers list ordered by "scheduler_type" in descending
order
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=-scheduler_type",
expected_list_ids=[2, 3, 4, 0, 1])
'/computers?pk>' + str(node_pk) +
'&transport_type="ssh"&orderby=-scheduler_type',
expected_list_ids=[2, 4, 1])

############### list orderby combinations #######################
def test_computers_orderby_mixed1(self):
Expand All @@ -557,19 +563,21 @@ def test_computers_orderby_mixed1(self):
ascending order and if it is having same transport_type, order it
by "id"
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=transport_type,id",
expected_list_ids=[0, 3, 1, 2, 4])
'/computers?pk>'+str(node_pk)+'&orderby=transport_type,id',
expected_list_ids=[3, 1, 2, 4])

def test_computers_orderby_mixed2(self):
"""
Returns the computers list first order by "scheduler_type" in
descending order and if it is having same scheduler_type, order it
by "name"
"""
node_pk = self.get_dummy_data()["computers"][0]["id"]
RESTApiTestCase.process_test(self, "computers",
"/computers?orderby=-scheduler_type,name",
expected_list_ids=[2, 3, 4, 0, 1])
'/computers?pk>'+str(node_pk)+'&orderby=-scheduler_type,name',
expected_list_ids=[2, 3, 4, 1])

def test_computers_orderby_mixed3(self):
"""
Expand Down