implemented pagination for my_products and my_company
This commit is contained in:
@@ -33,8 +33,6 @@ class CompanyViewSetTest(APITestCase):
|
||||
def test_anon_user_cannot_create_instance(self):
|
||||
"""Not logged-in user cannot create new instance
|
||||
"""
|
||||
instances = [self.factory() for n in range(random.randint(1,5))]
|
||||
|
||||
# Query endpoint
|
||||
response = self.client.post(self.endpoint, data={})
|
||||
# Assert access is forbidden
|
||||
@@ -76,6 +74,20 @@ class CompanyViewSetTest(APITestCase):
|
||||
# Assert access is forbidden
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_anon_user_can_paginate_instances(self):
|
||||
"""Not logged-in user can paginate instances
|
||||
"""
|
||||
instances = [self.factory() for n in range(12)]
|
||||
# Request list
|
||||
url = f"{self.endpoint}?limit=5&offset=10"
|
||||
response = self.client.get(url)
|
||||
|
||||
# Assert access is allowed
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
# assert only 2 instances in response
|
||||
payload = response.json()
|
||||
self.assertEquals(2, len(payload['results']))
|
||||
|
||||
def test_anon_user_can_filter_tags(self):
|
||||
# create instances
|
||||
expected_instance = [
|
||||
@@ -299,6 +311,27 @@ class MyCompanyViewTest(APITestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEquals(len(user_instances), len(payload))
|
||||
|
||||
def test_auth_user_can_paginate_instances(self):
|
||||
"""authenticated user can paginate instances
|
||||
"""
|
||||
|
||||
# Authenticate
|
||||
token = get_tokens_for_user(self.user)
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {token['access']}")
|
||||
|
||||
# create instances
|
||||
instances = [self.factory(creator=self.user) for n in range(12)]
|
||||
|
||||
# Request list
|
||||
url = f"{self.endpoint}?limit=5&offset=10"
|
||||
response = self.client.get(url)
|
||||
|
||||
# Assert access is allowed
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
# assert only 2 instances in response
|
||||
payload = response.json()
|
||||
self.assertEquals(2, len(payload))
|
||||
|
||||
def test_anon_user_cannot_access(self):
|
||||
# send in request
|
||||
response = self.client.get(self.endpoint)
|
||||
|
||||
Reference in New Issue
Block a user