bunch of stuff
This commit is contained in:
@@ -312,12 +312,11 @@ class MyCompanyViewTest(APITestCase):
|
||||
self.user.set_password(self.password)
|
||||
self.user.save()
|
||||
|
||||
def tearDown(self):
|
||||
self.model.objects.all().delete()
|
||||
|
||||
def test_auth_user_gets_data(self):
|
||||
# create instance
|
||||
user_instances = [self.factory(creator=self.user) for i in range(5)]
|
||||
company = CompanyFactory()
|
||||
self.user.company = company
|
||||
self.user.save()
|
||||
|
||||
# Authenticate
|
||||
token = get_tokens_for_user(self.user)
|
||||
@@ -325,32 +324,10 @@ class MyCompanyViewTest(APITestCase):
|
||||
|
||||
# Query endpoint
|
||||
response = self.client.get(self.endpoint)
|
||||
payload = response.json()
|
||||
|
||||
# Assert forbidden code
|
||||
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['results']))
|
||||
self.assertEquals(payload['company']['id'], company.id)
|
||||
|
||||
def test_anon_user_cannot_access(self):
|
||||
# send in request
|
||||
|
||||
Reference in New Issue
Block a user