advances in TrackUserViewTest
This commit is contained in:
@@ -7,6 +7,9 @@ from rest_framework import status
|
||||
from core.factories import CustomUserFactory
|
||||
from core.utils import get_tokens_for_user
|
||||
|
||||
from products.factories import ProductFactory
|
||||
from companies.factories import CompanyFactory
|
||||
|
||||
from .models import StatsLog
|
||||
from .factories import StatsLogFactory
|
||||
|
||||
@@ -28,40 +31,58 @@ class TrackUserViewTest(APITestCase):
|
||||
|
||||
# anon user
|
||||
def test_anon_user_can_only_post(self):
|
||||
"""Not logged-in user cannot create new instance
|
||||
"""Not logged-in user can only POST data
|
||||
"""
|
||||
# Create instance
|
||||
product = ProductFactory()
|
||||
|
||||
data = {
|
||||
'action': 'VIEW',
|
||||
'action_object': {
|
||||
'model': 'product',
|
||||
'id': product.id,
|
||||
},
|
||||
}
|
||||
|
||||
# Query endpoint
|
||||
response = self.client.get(self.endpoint, data={})
|
||||
response = self.client.get(self.endpoint)
|
||||
# Assert access is forbidden
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
# Query endpoint
|
||||
response = self.client.put(self.endpoint, data={})
|
||||
# Assert access is forbidden
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
# Query endpoint
|
||||
response = self.client.delete(self.endpoint, data={})
|
||||
# Assert access is forbidden
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
|
||||
|
||||
# Query endpoint
|
||||
response = self.client.post(self.endpoint, data={})
|
||||
response = self.client.post(self.endpoint, data=data, format='json')
|
||||
# Assert access is forbidden
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
def test_anon_user_can_register_product_action(self):
|
||||
"""Not logged-in user cannot modify existing instance
|
||||
"""
|
||||
# Create instance
|
||||
instance = self.factory()
|
||||
product = ProductFactory()
|
||||
|
||||
data = {
|
||||
'action': 'VIEW',
|
||||
'action_object': {
|
||||
'model': 'product',
|
||||
'id': product.id,
|
||||
},
|
||||
}
|
||||
|
||||
# Query endpoint
|
||||
url = self.endpoint + f'{instance.pk}/'
|
||||
response = self.client.put(url, {}, format='json')
|
||||
response = self.client.post(self.endpoint, data=data, format='json')
|
||||
|
||||
# Assert forbidden code
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
def test_anon_user_can_register_company_action(self):
|
||||
"""Not logged-in user cannot modify existing instance
|
||||
|
||||
Reference in New Issue
Block a user