From f2743d25e550aebf98e99b2bcf37259b40c89a2f Mon Sep 17 00:00:00 2001 From: Hadley King Date: Thu, 27 Jul 2023 17:52:40 -0400 Subject: [PATCH] Get published object by (#201) * unit tests test_fixtures.py - Exports the database as a pytest fixture that can be used for testing * Add files via upload * New api test files * Fixed test_api_accounts_describe Changes to be committed: modified: api/apps.py modified: api/model/groups.py modified: api/model/prefix.py deleted: api/tests/test_bcos.json deleted: api/tests/test_forms.py deleted: api/tests/test_group_post_api.py deleted: api/tests/test_model_bco.py deleted: api/tests/test_model_groups.py deleted: api/tests/test_model_prefix.py deleted: api/tests/test_model_user.py deleted: api/tests/test_prefix_post_api.py deleted: api/tests/test_views.py deleted: api/tests_automated.py modified: api/views.py modified: bcodb/settings.py renamed: api/tests/__init__.py -> tests/__init__.py new file: tests/fixtures/test_data.json modified: tests/test_fixtures.py new file: tests/test_views/__init__.py modified: tests/test_views/test_api_accounts_describe.py * Fix Bulk Publish function Changes to be committed: modified: api/scripts/method_specific/POST_api_objects_publish.py modified: api/scripts/utilities/JsonUtils.py * Add reset_token API Issue #158 * Formatting for Add/Remove ORCID updated dev DB Related to https://github.com/biocompute-objects/portal_userdb/issues/90 Changes to be committed: modified: admin_only/db.sqlite3.dev modified: authentication/apis.py * Fix #134 Changes to be committed: modified: authentication/services.py * Bump django from 3.2.10 to 3.2.13 Bumps [django](https://github.com/django/django) from 3.2.10 to 3.2.13. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/3.2.10...3.2.13) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] * new test - auth/remove * conflicts solved and merged * new bracnh for conflict resolution Changes to be committed: modified: .github/workflows/django.yml modified: tests/test_views/test_api_objects_drafts_create.py * update (#198) * Fix Bulk Publish function Changes to be committed: modified: api/scripts/method_specific/POST_api_objects_publish.py modified: api/scripts/utilities/JsonUtils.py * Add reset_token API Issue #158 * Formatting for Add/Remove ORCID updated dev DB Related to https://github.com/biocompute-objects/portal_userdb/issues/90 Changes to be committed: modified: admin_only/db.sqlite3.dev modified: authentication/apis.py * Fix #134 Changes to be committed: modified: authentication/services.py * Bump django from 3.2.10 to 3.2.13 Bumps [django](https://github.com/django/django) from 3.2.10 to 3.2.13. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/3.2.10...3.2.13) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] * added new test file- api/auth/remove.py (#196) * unit tests test_fixtures.py - Exports the database as a pytest fixture that can be used for testing * Add files via upload * New api test files * Fixed test_api_accounts_describe Changes to be committed: modified: api/apps.py modified: api/model/groups.py modified: api/model/prefix.py deleted: api/tests/test_bcos.json deleted: api/tests/test_forms.py deleted: api/tests/test_group_post_api.py deleted: api/tests/test_model_bco.py deleted: api/tests/test_model_groups.py deleted: api/tests/test_model_prefix.py deleted: api/tests/test_model_user.py deleted: api/tests/test_prefix_post_api.py deleted: api/tests/test_views.py deleted: api/tests_automated.py modified: api/views.py modified: bcodb/settings.py renamed: api/tests/__init__.py -> tests/__init__.py new file: tests/fixtures/test_data.json modified: tests/test_fixtures.py new file: tests/test_views/__init__.py modified: tests/test_views/test_api_accounts_describe.py * Fix Bulk Publish function Changes to be committed: modified: api/scripts/method_specific/POST_api_objects_publish.py modified: api/scripts/utilities/JsonUtils.py * Add reset_token API Issue #158 * Formatting for Add/Remove ORCID updated dev DB Related to https://github.com/biocompute-objects/portal_userdb/issues/90 Changes to be committed: modified: admin_only/db.sqlite3.dev modified: authentication/apis.py * Fix #134 Changes to be committed: modified: authentication/services.py * Bump django from 3.2.10 to 3.2.13 Bumps [django](https://github.com/django/django) from 3.2.10 to 3.2.13. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/3.2.10...3.2.13) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] * new test - auth/remove * conflicts solved and merged --------- Signed-off-by: dependabot[bot] Co-authored-by: Hadley King Co-authored-by: hadleyking Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Reeya Gupta <56750374+Reeya123@users.noreply.github.com> * Fix Swagger for `GET_published_object_by_id` * tests and documentation for 'get_object_id' Fix #178 --------- Signed-off-by: dependabot[bot] Co-authored-by: Reeya Gupta Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Reeya Gupta <56750374+Reeya123@users.noreply.github.com> --- .../GET_published_object_by_id.py | 4 +-- api/views.py | 18 +++---------- .../test_views/test_published_object_by_id.py | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 tests/test_views/test_published_object_by_id.py diff --git a/api/scripts/method_specific/GET_published_object_by_id.py b/api/scripts/method_specific/GET_published_object_by_id.py index 58d15908..986cf98c 100755 --- a/api/scripts/method_specific/GET_published_object_by_id.py +++ b/api/scripts/method_specific/GET_published_object_by_id.py @@ -1,5 +1,5 @@ # The BCO model -from ...models import BCO +from api.models import BCO # Responses from rest_framework import status @@ -107,5 +107,5 @@ def GET_published_object_by_id(oi_root): print("No objects were found for the root ID provided.") return Response( data="No objects were found for the root ID provided.", - status=status.HTTP_400_BAD_REQUEST, + status=status.HTTP_404_NOT_FOUND, ) diff --git a/api/views.py b/api/views.py index 8a4ecad6..7dc90d4a 100755 --- a/api/views.py +++ b/api/views.py @@ -1669,19 +1669,10 @@ def get(self, request, object_id): class ObjectIdRootObjectId(APIView): """ View Published BCO by ID - -------------------- - - Reads and returns a published BCO based on an object ID. - + Reads and returns a published BCO based on an object ID. This will return the highest versioned object. """ - # For the success and error messages - # renderer_classes = [ - # TemplateHTMLRenderer - # ] - # template_name = 'api/account_activation_message.html' - auth = [] auth.append( openapi.Parameter( @@ -1692,17 +1683,14 @@ class ObjectIdRootObjectId(APIView): ) ) - # Anyone can view a published object authentication_classes = [] permission_classes = [] @swagger_auto_schema( manual_parameters=auth, responses={ - 201: "Account has been authorized.", - 208: "Account has already been authorized.", - 403: "Requestor's credentials were rejected.", - 424: "Account has not been registered.", + 200: "Object returned.", + 404: "Object not found." }, tags=["BCO Management"], ) diff --git a/tests/test_views/test_published_object_by_id.py b/tests/test_views/test_published_object_by_id.py new file mode 100644 index 00000000..d5a599cc --- /dev/null +++ b/tests/test_views/test_published_object_by_id.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +"""Root Object Id Testing +Tests for 'Object Found' (200) and 'Object Not Found'(404) +""" + +from django.test import TestCase +from rest_framework.test import APIClient + +class ObjectIdRootObjectIdTest(TestCase): + fixtures = ['tests/fixtures/test_data'] + + def test_seccussfull_retrieval(self): + """200: Object returned. + """ + + client = APIClient() + response = self.client.get('/BCO_000001') + self.assertEqual(response.status_code, 200) + + def test_object_not_found(self): + """404: Object not found. + """ + + response = self.client.get('/BCO_001000') + self.assertEqual(response.status_code, 404) \ No newline at end of file