query params filter working with tags in Product

This commit is contained in:
Sam
2021-02-12 11:28:55 +00:00
parent 9a6a30553a
commit 0a61cea599
4 changed files with 52 additions and 13 deletions

View File

@@ -106,8 +106,7 @@ class ProductViewSetTest(APITestCase):
self.factory(name='sadfdsa', tags="zapatos, azules"),
self.factory(name='qwerw', tags="xxl")
]
# prepare url
url = f"{self.endpoint}?tags=rojos"
# Request list
@@ -119,6 +118,49 @@ class ProductViewSetTest(APITestCase):
# Assert number of instnaces in response
self.assertEquals(len(expected_instance), len(payload))
def test_anon_user_can_filter_attributes(self):
# create instances
expected_instance = [
self.factory(attributes='xxl', tags="zapatos, rojos"),
self.factory(attributes='blue, xxl', tags="rojos")
]
unexpected_instance = [
self.factory(name='sadfdsa', tags="zapatos, azules"),
self.factory(name='qwerw', tags="xxl")
]
# prepare url
url = f"{self.endpoint}?attributes=xxl"
# 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(len(expected_instance), len(payload))
def test_anon_user_can_filter_category(self):
# create instances
expected_instance = [
self.factory(category='ropa', tags="zapatos, rojos"),
self.factory(category='ropa', tags="rojos")
]
unexpected_instance = [
self.factory(category='roperos', tags="zapatos, azules"),
self.factory(category='enropados', tags="xxl")
]
# prepare url
url = f"{self.endpoint}?category=ropa"
# 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(len(expected_instance), len(payload))
# authenticated user
def test_auth_user_can_list_instances(self):