working on ordering products

This commit is contained in:
Sam
2021-02-23 13:55:05 +00:00
parent 4f39963691
commit afb67006bc
2 changed files with 28 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ class ProductSerializer(TaggitSerializer, serializers.ModelSerializer):
class Meta:
model = Product
exclude = ['created', 'updated', 'creator']
exclude = ['updated', 'creator']
class SearchResultSerializer(TaggitSerializer, serializers.ModelSerializer):

View File

@@ -191,6 +191,33 @@ class ProductViewSetTest(APITestCase):
# Assert number of instnaces in response
self.assertEquals(len(expected_instance), len(payload))
def test_anon_user_can_order_products(self):
# create instances
company = CompanyFactory()
unexpected_instance = [
self.factory(category='roperos', tags="zapatos, azules"),
self.factory(category='enropados', tags="xxl")
]
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)
]
# prepare url
url = f"{self.endpoint}?ordering=created"
# Request list
response = self.client.get(url)
payload = response.json()
# Assert access is granted
self.assertEqual(response.status_code, status.HTTP_200_OK)
# TODO: assert correct order
previous_date = datetime.datetime.now()
for instance in payload:
self.assertTrue(datetime.datetime.fromisoformat(instance['created'][:-1]) < previous_date)
previous_date = datetime.datetime.fromisoformat(instance['created'][:-1])
# authenticated user
def test_auth_user_can_list_instances(self):
"""Regular logged-in user can list instance