|
4 | 4 | from rest_framework import status
|
5 | 5 | from rest_framework.test import APITestCase
|
6 | 6 |
|
| 7 | +from objects.core.models import ObjectType |
7 | 8 | from objects.core.tests.factories import (
|
8 | 9 | ObjectFactory,
|
9 | 10 | ObjectRecordFactory,
|
@@ -376,6 +377,52 @@ def test_create_superuser(self, m):
|
376 | 377 |
|
377 | 378 | self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
378 | 379 |
|
| 380 | + def test_create_superuser_no_service(self): |
| 381 | + url = reverse("object-list") |
| 382 | + data = { |
| 383 | + "type": f"{OBJECT_TYPES_API}objecttypes/8be76be2-6567-4f5c-a17b-05217ab6d7b2", |
| 384 | + "record": { |
| 385 | + "typeVersion": 1, |
| 386 | + "data": {"plantDate": "2020-04-12", "diameter": 30}, |
| 387 | + "startAt": "2020-01-01", |
| 388 | + }, |
| 389 | + } |
| 390 | + |
| 391 | + response = self.client.post(url, data, **GEO_WRITE_KWARGS) |
| 392 | + |
| 393 | + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) |
| 394 | + |
| 395 | + @requests_mock.Mocker() |
| 396 | + def test_create_superuser_no_object_type(self, m): |
| 397 | + objecttype_url = ( |
| 398 | + f"{OBJECT_TYPES_API}objecttypes/8be76be2-6567-4f5c-a17b-05217ab6d7b2" |
| 399 | + ) |
| 400 | + service = ServiceFactory.create(api_root=OBJECT_TYPES_API) |
| 401 | + url = reverse("object-list") |
| 402 | + data = { |
| 403 | + "type": objecttype_url, |
| 404 | + "record": { |
| 405 | + "typeVersion": 1, |
| 406 | + "data": {"plantDate": "2020-04-12", "diameter": 30}, |
| 407 | + "startAt": "2020-01-01", |
| 408 | + }, |
| 409 | + } |
| 410 | + # mocks |
| 411 | + mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes") |
| 412 | + m.get(objecttype_url, json=mock_objecttype(objecttype_url)) |
| 413 | + m.get( |
| 414 | + f"{objecttype_url}/versions/1", |
| 415 | + json=mock_objecttype_version(objecttype_url), |
| 416 | + ) |
| 417 | + |
| 418 | + response = self.client.post(url, data, **GEO_WRITE_KWARGS) |
| 419 | + |
| 420 | + self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
| 421 | + # check created object type |
| 422 | + object_type = ObjectType.objects.get() |
| 423 | + self.assertEqual(object_type.service, service) |
| 424 | + self.assertEqual(object_type.url, objecttype_url) |
| 425 | + |
379 | 426 | @requests_mock.Mocker()
|
380 | 427 | def test_update_superuser(self, m):
|
381 | 428 | object_type = ObjectTypeFactory(service__api_root=OBJECT_TYPES_API)
|
|
0 commit comments