-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
167a00c
commit 39b78c2
Showing
2 changed files
with
107 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from datetime import date | ||
|
||
from django.urls import reverse | ||
|
||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
|
||
from objecttypes.core.constants import ObjectVersionStatus | ||
from objecttypes.core.models import ObjectVersion | ||
from objecttypes.core.tests.factories import ObjectTypeFactory, ObjectVersionFactory | ||
from objecttypes.utils.test import TokenAuthMixin | ||
|
||
JSON_SCHEMA = { | ||
"type": "object", | ||
"title": "Tree", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"required": ["diameter"], | ||
"properties": {"diameter": {"type": "integer", "description": "size in cm."}}, | ||
} | ||
|
||
|
||
class ObjectVersionAPITests(TokenAuthMixin, APITestCase): | ||
def test_get_versions(self): | ||
object_type = ObjectTypeFactory.create() | ||
object_version = ObjectVersionFactory.create(object_type=object_type) | ||
url = reverse("objectversion-list", args=[object_type.uuid]) | ||
|
||
response = self.client.get(url) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual( | ||
response.json(), | ||
[ | ||
{ | ||
"url": f"http://testserver{reverse('objectversion-detail', args=[object_type.uuid, object_version.version])}", | ||
"version": object_version.version, | ||
"objectType": f"http://testserver{reverse('objecttype-detail', args=[object_version.object_type.uuid])}", | ||
"publicationDate": object_version.publication_date.isoformat(), | ||
"status": object_version.status, | ||
"jsonSchema": JSON_SCHEMA, | ||
} | ||
], | ||
) | ||
|
||
def test_create_version(self): | ||
object_type = ObjectTypeFactory.create() | ||
data = {"jsonSchema": JSON_SCHEMA} | ||
url = reverse("objectversion-list", args=[object_type.uuid]) | ||
|
||
response = self.client.post(url, data) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(ObjectVersion.objects.count(), 1) | ||
|
||
object_version = ObjectVersion.objects.get() | ||
|
||
self.assertEqual(object_version.object_type, object_type) | ||
self.assertEqual(object_version.json_schema, JSON_SCHEMA) | ||
self.assertEqual(object_version.version, 1) | ||
self.assertEqual(object_version.publication_date, date.today()) | ||
self.assertEqual(object_version.status, ObjectVersionStatus.draft) | ||
|
||
def test_update_version(self): | ||
object_type = ObjectTypeFactory.create() | ||
object_version = ObjectVersionFactory.create(object_type=object_type) | ||
url = reverse( | ||
"objectversion-detail", args=[object_type.uuid, object_version.version] | ||
) | ||
new_json_schema = { | ||
"type": "object", | ||
"title": "Tree", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"required": ["diameter"], | ||
"properties": {"diameter": {"type": "number"}}, | ||
} | ||
|
||
response = self.client.put(url, {"jsonSchema": new_json_schema}) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_delete_version_not_supported(self): | ||
object_type = ObjectTypeFactory.create() | ||
object_version = ObjectVersionFactory.create(object_type=object_type) | ||
url = reverse( | ||
"objectversion-detail", args=[object_type.uuid, object_version.version] | ||
) | ||
|
||
response = self.client.delete(url) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) | ||
|
||
def test_publish_version(self): | ||
object_type = ObjectTypeFactory.create() | ||
object_version = ObjectVersionFactory.create(object_type=object_type) | ||
url = reverse( | ||
"objectversion-publish", args=[object_type.uuid, object_version.version] | ||
) | ||
|
||
response = self.client.post(url) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
object_version.refresh_from_db() | ||
|
||
self.assertEqual(object_version.status, ObjectVersionStatus.published) |