added custom filter with tag support to products

This commit is contained in:
Sam
2021-02-12 11:09:32 +00:00
parent 77b1660fc3
commit 9a6a30553a
3 changed files with 19 additions and 9 deletions

View File

@@ -98,8 +98,15 @@ class ProductViewSetTest(APITestCase):
def test_anon_user_can_filter_tags(self):
# create instances
self.factory(name='product1', tags="zapatos, verdes")
self.factory(name='product2', tags="rojos")
expected_instance = [
self.factory(name='product1', tags="zapatos, rojos"),
self.factory(name='product2', tags="rojos")
]
unexpected_instance = [
self.factory(name='sadfdsa', tags="zapatos, azules"),
self.factory(name='qwerw', tags="xxl")
]
url = f"{self.endpoint}?tags=rojos"
@@ -107,12 +114,10 @@ class ProductViewSetTest(APITestCase):
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))
self.assertEquals(len(expected_instance), len(payload))
# authenticated user