diff --git a/apps/location/tests.py b/apps/location/tests.py index a3213e69..0d7803bc 100644 --- a/apps/location/tests.py +++ b/apps/location/tests.py @@ -27,6 +27,35 @@ class BaseTestCase(APITestCase): 'refresh_token': tokkens.get('refresh_token')}) +class CountryTests(BaseTestCase): + + def test_country_CRUD(self): + response = self.client.get('/api/back/location/countries/', format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + data = { + 'name': 'Test country', + '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) + + response = self.client.get(f'/api/back/location/countries/{response_data["id"]}/', format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + update_data = { + 'name': json.dumps({"en-GB": "Test new country"}) + } + + response = self.client.patch(f'/api/back/location/countries/{response_data["id"]}/', data=update_data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + response = self.client.delete(f'/api/back/location/countries/{response_data["id"]}/', format='json') + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + + class AddressTests(BaseTestCase): def setUp(self): @@ -65,18 +94,18 @@ class AddressTests(BaseTestCase): } response = self.client.post('/api/back/location/addresses/', data=data, format='json') - print(f"=========RESPONSE: {response.json()}") + response_data = response.json() self.assertEqual(response.status_code, status.HTTP_201_CREATED) - response = self.client.get('/api/back/location/addresses/1/', format='json') + response = self.client.get(f'/api/back/location/addresses/{response_data["id"]}/', format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) update_data = { 'number': '+79999991' } - response = self.client.patch('/api/back/location/addresses/1/', data=update_data) + response = self.client.patch(f'/api/back/location/addresses/{response_data["id"]}/', data=update_data) self.assertEqual(response.status_code, status.HTTP_200_OK) - response = self.client.delete('/api/back/location/addresses/1/', format='json') + response = self.client.delete(f'/api/back/location/addresses/{response_data["id"]}/', format='json') self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)