testing tag filtering
This commit is contained in:
@@ -80,6 +80,41 @@ class ProductViewSetTest(APITestCase):
|
||||
# Assert access is forbidden
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_anon_user_can_filter_name(self):
|
||||
# create instances
|
||||
self.factory(name='product1', tags="zapatos, verdes")
|
||||
self.factory(name='product2', tags="rojos")
|
||||
|
||||
url = f"{self.endpoint}?name=product1"
|
||||
|
||||
# Request list
|
||||
response = self.client.get(url)
|
||||
payload = response.json()
|
||||
|
||||
# Assert access is granted
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
# Assert number of instnaces in response
|
||||
self.assertEquals(1, len(payload))
|
||||
|
||||
def test_anon_user_can_filter_tags(self):
|
||||
# create instances
|
||||
self.factory(name='product1', tags="zapatos, verdes")
|
||||
self.factory(name='product2', tags="rojos")
|
||||
|
||||
url = f"{self.endpoint}?tags=rojos"
|
||||
|
||||
# Request list
|
||||
response = self.client.get(url)
|
||||
payload = response.json()
|
||||
|
||||
# import ipdb; ipdb.set_trace()
|
||||
|
||||
# Assert access is granted
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
# Assert number of instnaces in response
|
||||
self.assertEquals(1, len(payload))
|
||||
|
||||
|
||||
# authenticated user
|
||||
def test_auth_user_can_list_instances(self):
|
||||
"""Regular logged-in user can list instance
|
||||
|
||||
Reference in New Issue
Block a user