change company view to descending order by created date

This commit is contained in:
Sam
2021-03-05 11:06:05 +00:00
parent cdb18ea157
commit 7825810448
2 changed files with 20 additions and 1 deletions

View File

@@ -274,6 +274,25 @@ class CompanyViewSetTest(APITestCase):
# Assert instance doesn't exists anymore on db
self.assertFalse(self.model.objects.filter(id=instance.pk).exists())
# functionalities
def test_descending_order(self):
instances = [self.factory(), self.factory()]
# Authenticate user
token = get_tokens_for_user(self.user)
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {token['access']}")
# Request list
response = self.client.get(self.endpoint)
# Assert access is allowed
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Assert all instances are returned
self.assertEqual(len(instances), len(response.data))
# check order
self.assertTrue(response.data[0]['id'] > response.data[1]['id'])
class MyCompanyViewTest(APITestCase):
"""CompanyViewset tests