From e945bd72a3199e1a3b4a4777421e95abb219e313 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 23 Feb 2021 13:13:49 +0000 Subject: [PATCH] compnay filter for products, not working --- products/serializers.py | 1 - products/tests.py | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/products/serializers.py b/products/serializers.py index 6bd7497..76f8871 100644 --- a/products/serializers.py +++ b/products/serializers.py @@ -11,7 +11,6 @@ class ProductSerializer(TaggitSerializer, serializers.ModelSerializer): tags = TagListSerializerField(required=False) category = SingleTagSerializerField(required=False) # main tag category attributes = TagListSerializerField(required=False) - # image = serializers.SerializerMethodField() class Meta: model = Product diff --git a/products/tests.py b/products/tests.py index d32e1f6..f721c94 100644 --- a/products/tests.py +++ b/products/tests.py @@ -163,6 +163,31 @@ class ProductViewSetTest(APITestCase): # Assert number of instnaces in response self.assertEquals(len(expected_instance), len(payload)) + def test_anon_user_can_filter_company(self): + # create instances + company = CompanyFactory() + expected_instance = [ + self.factory(category='ropa', tags="zapatos, rojos", company=company), + self.factory(category='ropa', tags="rojos", company=company), + self.factory(category='ropa', tags="colores/rojos", company=company) + ] + unexpected_instance = [ + self.factory(category='roperos', tags="zapatos, azules"), + self.factory(category='enropados', tags="xxl") + ] + # prepare url + url = f"{self.endpoint}?company={company.id}" + + # 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(len(expected_instance), len(payload)) + # authenticated user def test_auth_user_can_list_instances(self): """Regular logged-in user can list instance