diff --git a/src/objecttypes/api/serializers.py b/src/objecttypes/api/serializers.py index f88ce5ee..155c6d2c 100644 --- a/src/objecttypes/api/serializers.py +++ b/src/objecttypes/api/serializers.py @@ -33,7 +33,6 @@ class Meta: "source": "json_schema", "validators": [JsonSchemaValidator()], }, - "status": {"read_only": True}, } validators = [VersionUpdateValidator()] diff --git a/src/objecttypes/api/views.py b/src/objecttypes/api/views.py index f7bea0cc..b074e749 100644 --- a/src/objecttypes/api/views.py +++ b/src/objecttypes/api/views.py @@ -29,14 +29,3 @@ class ObjectVersionViewSet( queryset = ObjectVersion.objects.order_by("object_type", "-version") serializer_class = ObjectVersionSerializer lookup_field = "version" - - @swagger_auto_schema(request_body=no_body) - @action(detail=True, methods=["post"]) - def publish(self, request, *args, **kwargs): - instance = self.get_object() - instance.status = ObjectVersionStatus.published - instance.save() - - serializer = self.get_serializer(instance) - - return Response(serializer.data) diff --git a/src/objecttypes/tests/test_version_api.py b/src/objecttypes/tests/test_version_api.py index 2dd8969a..17fb1c94 100644 --- a/src/objecttypes/tests/test_version_api.py +++ b/src/objecttypes/tests/test_version_api.py @@ -44,7 +44,7 @@ def test_get_versions(self): def test_create_version(self): object_type = ObjectTypeFactory.create() - data = {"jsonSchema": JSON_SCHEMA} + data = {"jsonSchema": JSON_SCHEMA, "status": ObjectVersionStatus.published} url = reverse("objectversion-list", args=[object_type.uuid]) response = self.client.post(url, data) @@ -58,7 +58,7 @@ def test_create_version(self): 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) + self.assertEqual(object_version.status, ObjectVersionStatus.published) def test_update_version(self): object_type = ObjectTypeFactory.create() @@ -74,10 +74,18 @@ def test_update_version(self): "properties": {"diameter": {"type": "number"}}, } - response = self.client.put(url, {"jsonSchema": new_json_schema}) + response = self.client.put( + url, + {"jsonSchema": new_json_schema, "status": ObjectVersionStatus.published}, + ) self.assertEqual(response.status_code, status.HTTP_200_OK) + object_version.refresh_from_db() + + self.assertEqual(object_version.json_schema, new_json_schema) + self.assertEqual(object_version.status, ObjectVersionStatus.published) + def test_delete_version_not_supported(self): object_type = ObjectTypeFactory.create() object_version = ObjectVersionFactory.create(object_type=object_type) @@ -88,18 +96,3 @@ def test_delete_version_not_supported(self): 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)