From 4202eb679b5a938d0a454cfcffa11b429cd05578 Mon Sep 17 00:00:00 2001 From: dormantman Date: Wed, 4 Dec 2019 15:48:54 +0300 Subject: [PATCH] Corrections for tests --- apps/establishment/tests.py | 18 +++++++++--------- apps/establishment/views/web.py | 1 + apps/tag/serializers.py | 1 + apps/utils/views.py | 11 +++++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/establishment/tests.py b/apps/establishment/tests.py index 6bc23ccc..f46cccc3 100644 --- a/apps/establishment/tests.py +++ b/apps/establishment/tests.py @@ -410,21 +410,21 @@ class EstablishmentWebTagTests(BaseTestCase): class EstablishmentWebSlugTests(ChildTestCase): def test_slug_Read(self): - response = self.client.get(f'/api/web/establishments/{self.establishment.id}/', format='json') + response = self.client.get(f'/api/web/establishments/slug/{self.establishment.slug}/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) class EstablishmentWebSimilarTests(ChildTestCase): def test_similar_Read(self): - response = self.client.get(f'/api/web/establishments/{self.establishment.id}/similar/', format='json') + response = self.client.get(f'/api/web/establishments/slug/{self.establishment.slug}/similar/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) class EstablishmentWebCommentsTests(ChildTestCase): def test_comments_CRUD(self): - response = self.client.get(f'/api/web/establishments/{self.establishment.id}/comments/', format='json') + response = self.client.get(f'/api/web/establishments/slug/{self.establishment.slug}/comments/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) data = { @@ -433,13 +433,13 @@ class EstablishmentWebCommentsTests(ChildTestCase): 'mark': 4 } - response = self.client.post(f'/api/web/establishments/{self.establishment.id}/comments/create/', + response = self.client.post(f'/api/web/establishments/slug/{self.establishment.slug}/comments/create/', data=data) comment = response.json() self.assertEqual(response.status_code, status.HTTP_201_CREATED) - response = self.client.get(f'/api/web/establishments/{self.establishment.id}/comments/{comment["id"]}/', + response = self.client.get(f'/api/web/establishments/slug/{self.establishment.slug}/comments/{comment["id"]}/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -448,12 +448,12 @@ class EstablishmentWebCommentsTests(ChildTestCase): } response = self.client.patch( - f'/api/web/establishments/{self.establishment.id}/comments/{comment["id"]}/', + f'/api/web/establishments/slug/{self.establishment.slug}/comments/{comment["id"]}/', data=update_data) self.assertEqual(response.status_code, status.HTTP_200_OK) response = self.client.delete( - f'/api/web/establishments/{self.establishment.id}/comments/{comment["id"]}/', + f'/api/web/establishments/slug/{self.establishment.slug}/comments/{comment["id"]}/', format='json') self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) @@ -466,13 +466,13 @@ class EstablishmentWebFavoriteTests(ChildTestCase): "object_id": self.establishment.id } - response = self.client.post(f'/api/web/establishments/{self.establishment.id}/favorites/', + response = self.client.post(f'/api/web/establishments/slug/{self.establishment.slug}/favorites/', data=data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) response = self.client.delete( - f'/api/web/establishments/{self.establishment.id}/favorites/', + f'/api/web/establishments/slug/{self.establishment.slug}/favorites/', format='json') self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) diff --git a/apps/establishment/views/web.py b/apps/establishment/views/web.py index bd826e4e..65a56a5b 100644 --- a/apps/establishment/views/web.py +++ b/apps/establishment/views/web.py @@ -142,6 +142,7 @@ class EstablishmentFavoritesCreateDestroyView(FavoritesCreateDestroyMixinView): class EstablishmentCarouselCreateDestroyView(CarouselCreateDestroyMixinView): """View for create/destroy establishment from carousel.""" + lookup_field = 'slug' _model = models.Establishment serializer_class = serializers.EstablishmentCarouselCreateSerializer diff --git a/apps/tag/serializers.py b/apps/tag/serializers.py index 2cc818a9..27590b18 100644 --- a/apps/tag/serializers.py +++ b/apps/tag/serializers.py @@ -37,6 +37,7 @@ class TagBackOfficeSerializer(TagBaseSerializer): 'category' ) + class TagCategoryProductSerializer(serializers.ModelSerializer): """SHORT Serializer for TagCategory""" diff --git a/apps/utils/views.py b/apps/utils/views.py index db10dbfd..e158357e 100644 --- a/apps/utils/views.py +++ b/apps/utils/views.py @@ -158,10 +158,10 @@ class CarouselCreateDestroyMixinView(BaseCreateDestroyMixinView): lookup_field = 'id' def get_base_object(self): - search_kwargs = { - 'id': self.kwargs.get('pk'), - 'slug': self.kwargs.get('slug'), - } + establishment_pk = self.kwargs.get('pk') + establishment_slug = self.kwargs.get('slug') + + search_kwargs = {'id': establishment_pk} if establishment_pk else {'slug': establishment_slug} return get_object_or_404(self._model, **search_kwargs) def get_object(self): @@ -175,6 +175,9 @@ class CarouselCreateDestroyMixinView(BaseCreateDestroyMixinView): # self.check_object_permissions(self.request, carousels) return carousels + def perform_destroy(self, instance): + instance.delete() + self.es_update_base_object() # BackOffice user`s views & viewsets class BindObjectMixin: