Skip to content

Commit

Permalink
👌 process PR feedback - remove /publish endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
annashamray committed Nov 25, 2020
1 parent dc47659 commit bb0499f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/objecttypes/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Meta:
"source": "json_schema",
"validators": [JsonSchemaValidator()],
},
"status": {"read_only": True},
}
validators = [VersionUpdateValidator()]

Expand Down
11 changes: 0 additions & 11 deletions src/objecttypes/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
29 changes: 11 additions & 18 deletions src/objecttypes/tests/test_version_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)

0 comments on commit bb0499f

Please sign in to comment.