Update tests

Update view
This commit is contained in:
littlewolf 2019-09-27 07:52:57 +03:00
parent 5793eaad32
commit 4f2bca78f9
2 changed files with 16 additions and 13 deletions

View File

@ -89,17 +89,20 @@ class CollectionWebHomeTests(CollectionDetailTests):
super().setUp()
self.establishment_type = EstablishmentType.objects.create(name="Test establishment type")
self.establishment = Establishment.objects.create(
name="Test establishment",
establishment_type_id=self.establishment_type.id,
is_publish=True,
slug="test"
)
for i in range(1, 5):
setattr(self, f"establishment{i}",
Establishment.objects.create(
name=f"Test establishment {i}",
establishment_type_id=self.establishment_type.id,
is_publish=True,
slug=f"test-establishment-{i}"
)
)
self.establishment.collections.add(self.collection)
self.establishment.save()
getattr(self, f"establishment{i}").collections.add(self.collection)
def test_collection_list_filter(self):
print("========================================================================================")
response = self.client.get('/api/web/collections/', format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.get('/api/web/collections/?country_code=en', format='json')
data = response.json()
self.assertIn('count', data)
self.assertGreater(data['count'], 0)

View File

@ -46,8 +46,8 @@ class CollectionHomePageView(CollectionViewMixin, generics.ListAPIView):
"""Override get_queryset method"""
queryset = models.Collection.objects.published()\
.by_country_code(code=self.request.country_code)\
.annotate_related_objects_count() \
.filter_related_gt(3) \
.annotate_related_objects_count()\
.filter_related_gt(3)\
.order_by('-on_top', '-created')
return queryset