compnay filter for products, not working

This commit is contained in:
Sam
2021-02-23 13:13:49 +00:00
parent e94e0c2dd5
commit e945bd72a3
2 changed files with 25 additions and 1 deletions

View File

@@ -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

View File

@@ -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