Corrections for tests

This commit is contained in:
dormantman 2019-12-04 15:48:54 +03:00
parent a81f3f079a
commit 4202eb679b
4 changed files with 18 additions and 13 deletions

View File

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

View File

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

View File

@ -37,6 +37,7 @@ class TagBackOfficeSerializer(TagBaseSerializer):
'category'
)
class TagCategoryProductSerializer(serializers.ModelSerializer):
"""SHORT Serializer for TagCategory"""

View File

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