diff --git a/apps/location/models.py b/apps/location/models.py index 7f797811..2b7aa363 100644 --- a/apps/location/models.py +++ b/apps/location/models.py @@ -21,6 +21,10 @@ class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin): high_price = models.IntegerField(default=50, verbose_name=_('High price')) languages = models.ManyToManyField(Language, verbose_name=_('Languages')) + @property + def country_id(self): + return self.id + class Meta: """Meta class.""" diff --git a/apps/location/tests.py b/apps/location/tests.py index 0770227a..edb719bd 100644 --- a/apps/location/tests.py +++ b/apps/location/tests.py @@ -59,15 +59,25 @@ class CountryTests(BaseTestCase): def setUp(self): super().setUp() + def test_country_CRUD(self): data = { 'name': {"ru-RU":"Russia"}, 'code': 'test' } + response = self.client.post('/api/back/location/countries/', data=data, format='json') response_data = response.json() self.assertEqual(response.status_code, status.HTTP_201_CREATED) + country = Country.objects.get(pk=response_data["id"]) + role = Role.objects.create(role=Role.COUNTRY_ADMIN, country=country) + role.save() + + user_role = UserRole.objects.create(user=self.user, role=role) + + user_role.save() + response = self.client.get('/api/back/location/countries/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -94,6 +104,14 @@ class RegionTests(BaseTestCase): code="test" ) + role = Role.objects.create(role=Role.COUNTRY_ADMIN, country=self.country) + role.save() + + user_role = UserRole.objects.create(user=self.user, role=role) + + user_role.save() + + def test_region_CRUD(self): response = self.client.get('/api/back/location/regions/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -138,6 +156,13 @@ class CityTests(BaseTestCase): country=self.country ) + role = Role.objects.create(role=Role.COUNTRY_ADMIN, country=self.country) + role.save() + + user_role = UserRole.objects.create(user=self.user, role=role) + + user_role.save() + def test_city_CRUD(self): response = self.client.get('/api/back/location/cities/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) diff --git a/apps/location/views/back.py b/apps/location/views/back.py index 3a2739b2..cb8246a4 100644 --- a/apps/location/views/back.py +++ b/apps/location/views/back.py @@ -47,6 +47,7 @@ class RegionRUDView(common.RegionViewMixin, generics.RetrieveUpdateDestroyAPIVie # Country class CountryListCreateView(generics.ListCreateAPIView): """List/Create view for model Country.""" + queryset = models.Country.objects.all() serializer_class = serializers.CountryBackSerializer pagination_class = None permission_classes = [IsCountryAdmin] @@ -54,4 +55,5 @@ class CountryListCreateView(generics.ListCreateAPIView): class CountryRUDView(generics.RetrieveUpdateDestroyAPIView): """RUD view for model Country.""" serializer_class = serializers.CountryBackSerializer - permission_classes = [IsCountryAdmin] \ No newline at end of file + permission_classes = [IsCountryAdmin] + queryset = models.Country.objects.all() \ No newline at end of file