Skip to content

Commit 644d024

Browse files
committed
Fix for test_get_objectid
Changes to be committed: modified: api/scripts/method_specific/GET_published_object_by_id.py modified: api/urls.py modified: api/views.py modified: tests/fixtures/test_data.json modified: tests/test_views/test_get_objectid.py
1 parent d811fa4 commit 644d024

File tree

5 files changed

+252
-36
lines changed

5 files changed

+252
-36
lines changed

api/scripts/method_specific/GET_published_object_by_id.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# The BCO model
2-
from api.models import BCO
1+
#!/usr/bin/env python3
32

4-
# Responses
3+
import re
4+
import json
5+
from api.models import BCO
6+
from django.forms.models import model_to_dict
57
from rest_framework import status
68
from rest_framework.response import Response
7-
8-
# Below is helper code to deal with how we are allowing non standard versions (i.e. 1.2 instead of 1.2.0, etc).
9-
import re
109
from semver import VersionInfo as Version
1110
from typing import Optional, Tuple
1211

13-
# TODO: This should be put into a universal place to grab from - also duplicated in POST_api_objects_drafts_token.py
12+
# TODO: This should be put into a universal place to grab from - also
13+
# duplicated in POST_api_objects_drafts_token.py
1414

1515
BASEVERSION = re.compile(
1616
r"""[vV]?
@@ -41,6 +41,7 @@ def coerce(version: str) -> Tuple[Version, Optional[str]]:
4141
belong to a basic version.
4242
:rtype: tuple(:class:`Version` | None, str)
4343
"""
44+
4445
match = BASEVERSION.search(version)
4546
if not match:
4647
return (None, version)
@@ -79,7 +80,6 @@ def GET_published_object_by_id(oi_root):
7980
object_id__regex=rf"(.*?)/{oi_root}/", state="PUBLISHED"
8081
).values_list("object_id", flat=True)
8182
)
82-
8383
# Get the latest version for this object if we have any.
8484
if len(all_versions) > 0:
8585

@@ -88,20 +88,20 @@ def GET_published_object_by_id(oi_root):
8888
# not a version was also passed.
8989

9090
# First find the latest version of the object.
91-
latest_version = [i.split("/")[-1:][0] for i in all_versions]
92-
l_version, _ = coerce(max(latest_version, key=coerce))
93-
91+
latest_versions = [i.split("/")[-1:][0] for i in all_versions]
92+
l_version, _ = coerce(max(latest_versions, key=coerce))
93+
latest_version = latest_versions[-1]
9494
# Kick back the latest version.
9595
return Response(
96-
data=BCO.objects.filter(
97-
object_id__regex=rf"{oi_root}/{l_version.major}.{l_version.minor}?.?{l_version.patch}",
96+
data=model_to_dict(BCO.objects.get(
97+
# object_id__regex=rf"{oi_root}/{l_version.major}.{l_version.minor}?.?{l_version.patch}",
98+
object_id__regex=f'{oi_root}/{latest_version}',
9899
state="PUBLISHED",
99-
).values_list("contents", flat=True),
100+
)),
100101
status=status.HTTP_200_OK,
101102
)
102103

103104
else:
104-
105105
# If all_versions has 0 length, then the
106106
# the root ID does not exist at all.
107107
print("No objects were found for the root ID provided.")

api/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@
123123
name="schema-redoc",
124124
),
125125
path("<str:object_id>/DRAFT", DraftObjectId.as_view()),
126-
path("<str:object_id_root>", ObjectIdRootObjectId.as_view()),
127126
path(
128127
"<str:object_id_root>/<str:object_id_version>",
129128
ObjectIdRootObjectIdVersion.as_view(),
130129
),
130+
path("<str:object_id_root>", ObjectIdRootObjectId.as_view()),
131131
path(
132132
"api/accounts/activate/<str:username>/<str:temp_identifier>",
133133
ApiAccountsActivateUsernameTempIdentifier.as_view(),

api/views.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,9 +1718,6 @@ class ObjectIdRootObjectId(APIView):
17181718
def get(self, request, object_id_root):
17191719
return GET_published_object_by_id(object_id_root)
17201720

1721-
1722-
# Allow anyone to view published objects.
1723-
# Source: https://www.django-rest-framework.org/api-guide/permissions/#setting-the-permission-policy
17241721
class ObjectIdRootObjectIdVersion(APIView):
17251722
"""
17261723
View Published BCO by ID and Version

tests/fixtures/test_data.json

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6297,6 +6297,236 @@
62976297
{
62986298
"model": "api.bco",
62996299
"pk": 12,
6300+
"fields": {
6301+
"contents": {
6302+
"object_id": "http://127.0.0.1:8000/TEST_000001/1.0",
6303+
"spec_version": "https://w3id.org/ieee/ieee-2791-schema/2791object.json",
6304+
"etag": "998f0b8a499bd88952f945367c17d62e95611c9d026fb0713b84a5fa9bfb745d",
6305+
"provenance_domain": {
6306+
"name": "ARGOSdb QC related annotation data property list",
6307+
"version": "1.0",
6308+
"created": "2022-02-07T17:36:05.872Z",
6309+
"modified": "2022-02-15T14:35:54.116922",
6310+
"contributors": [
6311+
{
6312+
"contribution": [
6313+
"createdBy",
6314+
"authoredBy",
6315+
"contributedBy"
6316+
],
6317+
"name": "Charles Hadley King",
6318+
"affiliation": "George Washington University",
6319+
"email": "[email protected]",
6320+
"orcid": "https://orcid.org/0000-0003-1409-4549"
6321+
},
6322+
{
6323+
"contribution": [
6324+
"curatedBy",
6325+
"contributedBy"
6326+
],
6327+
"name": "Stephanie Singleton",
6328+
"affiliation": "The George Washington University ",
6329+
"email": "[email protected]"
6330+
},
6331+
{
6332+
"contribution": [
6333+
"createdBy",
6334+
"curatedBy"
6335+
],
6336+
"name": "Jonathon Keeney",
6337+
"affiliation": "The George Washington University ",
6338+
"email": "[email protected]"
6339+
},
6340+
{
6341+
"name": "Raja Mazumder",
6342+
"contribution": [
6343+
"curatedBy"
6344+
],
6345+
"affiliation": "The George Washington University ",
6346+
"email": "[email protected]",
6347+
"orcid": "https://orcid.org/0000-0001-8823-9945"
6348+
}
6349+
],
6350+
"license": "https://github.com/FDA-ARGOS/data.argosdb/blob/v0.4_Feb/LICENSE"
6351+
},
6352+
"usability_domain": [
6353+
"List of controlled vocabulary terms for ARGOSdb annotation and metadata table data properties.",
6354+
"This sheet was created to aid in the integration of ARGOS data from many disparate sources. Each of the column headers in each of the respective data sheets displayed on www.data.argosdb.org was recommended by project members and collaborators from the FDA. The resulting list was manually curated to combine similar terms, and provide a consistent representation across all datasets in ARGOSdb.",
6355+
"The final result here is a list of properties and descriptive information about the property. The following are the column headers and their meaning: Property - consensus name for data property described in row. Data Object Type - The dataset this property is used in. Optional/Required - indicates if the property is REQUIRED to hava a valid data row. $id - For JSON schema conversion. Title - Human readable name for property. Default is the same as property. Type - property type as defined by JSON types. default - a default value for property. examples - and example for the property. pattern - the regular expression evaluation for this property. description - A definition and additional information about the property.",
6356+
"The primary use case for this property definition list is to ensure all data submitted to data.argosdb.org is following a consistent representation, and adhears to a controlled vocabulary of data properties."
6357+
],
6358+
"description_domain": {
6359+
"keywords": [
6360+
"curation",
6361+
"definitions",
6362+
"ontology",
6363+
"controlled vocabulary"
6364+
],
6365+
"pipeline_steps": [
6366+
{
6367+
"step_number": 1,
6368+
"name": "Header download",
6369+
"description": "Create a text file with the headers from each data sheet published for v0.3. Using the command `head -1 > ~/headers.txt`",
6370+
"prerequisite": [],
6371+
"input_list": [
6372+
{
6373+
"uri": "http://data.argosdb.org/ln2downloads/argosdb_qc/02_15_2022/SRA_ngsQC.tsv",
6374+
"filename": "SRA_ngsQC.tsv"
6375+
},
6376+
{
6377+
"uri": "http://data.argosdb.org/ln2downloads/argosdb_qc/02_15_2022/PRJNA231221_AssemblyUpdated.tsv",
6378+
"filename": "PRJNA231221_AssemblyUpdated.tsv"
6379+
},
6380+
{
6381+
"uri": "http://data.argosdb.org/ln2downloads/argosdb_qc/02_15_2022/sars-cov-2_lineage_mutations.tsv",
6382+
"filename": "sars-cov-2_lineage_mutations.tsv"
6383+
}
6384+
],
6385+
"output_list": [
6386+
{
6387+
"uri": "https://argosdb-vm-dev/software/argosdb/home/headers.txt",
6388+
"filename": "headers.txt"
6389+
}
6390+
]
6391+
},
6392+
{
6393+
"step_number": 2,
6394+
"name": "Manual Curation",
6395+
"description": "Manual curation of headers.txt into a curated list of terms with definitions.",
6396+
"prerequisite": [],
6397+
"input_list": [
6398+
{
6399+
"uri": "https://argosdb-vm-dev/software/argosdb/home/headers.txt"
6400+
}
6401+
],
6402+
"output_list": [
6403+
{
6404+
"uri": "https://data.argosdb.org/ ln2data/02_15_2022/annotation_property_list.tsv",
6405+
"access_time": "2022-02-03T13:42:44-0500",
6406+
"filename": "annotation_property_list.tsv"
6407+
}
6408+
]
6409+
}
6410+
]
6411+
},
6412+
"execution_domain": {
6413+
"script": [
6414+
{
6415+
"uri": {
6416+
"uri": "https://docs.google.com/spreadsheets/d/1EbHiGSmv6ZTGk6erQCl1oH8ye7EFuQPwKfWS5_7Cn60/edit#gid=0",
6417+
"filename": "FINAL_v0.3_argos_dict"
6418+
}
6419+
}
6420+
],
6421+
"script_driver": "Google Drive/Sheets",
6422+
"software_prerequisites": [
6423+
{
6424+
"name": "Microsof Excel",
6425+
"version": "16.57",
6426+
"uri": {
6427+
"uri": "https://www.microsoft.com/en-us/microsoft-365/excel"
6428+
}
6429+
}
6430+
],
6431+
"external_data_endpoints": [
6432+
{
6433+
"name": "data.ARGOSdb.org",
6434+
"url": "data.ARGOSdb.org"
6435+
},
6436+
{
6437+
"name": "Google Drive",
6438+
"url": "https://drive.google.com/drive/u/3/folders/1uUa4UYG3dd6yTOdxiyoav6qktit4-J-9"
6439+
}
6440+
],
6441+
"environment_variables": {}
6442+
},
6443+
"io_domain": {
6444+
"input_subdomain": [
6445+
{
6446+
"uri": {
6447+
"uri": "http://data.argosdb.org/ln2downloads/argosdb_qc/02_15_2022/SRA_ngsQC.tsv",
6448+
"filename": "SRA_ngsQC.tsv"
6449+
}
6450+
},
6451+
{
6452+
"uri": {
6453+
"uri": "http://data.argosdb.org/ln2downloads/argosdb_qc/02_15_2022/PRJNA231221_AssemblyUpdated.tsv",
6454+
"filename": "PRJNA231221_AssemblyUpdated.tsv"
6455+
}
6456+
},
6457+
{
6458+
"uri": {
6459+
"uri": "http://data.argosdb.org/ln2downloads/argosdb_qc/02_15_2022/sars-cov-2_lineage_mutations.tsv",
6460+
"filename": "sars-cov-2_lineage_mutations.tsv"
6461+
}
6462+
}
6463+
],
6464+
"output_subdomain": [
6465+
{
6466+
"mediatype": "text/tsv",
6467+
"uri": {
6468+
"uri": "https://data.argosdb.org/ ln2data/02_15_2022/annotation_property_list.tsv",
6469+
"access_time": "2022-02-03T13:42:44-0500",
6470+
"filename": "annotation_property_list.tsv"
6471+
}
6472+
}
6473+
]
6474+
},
6475+
"parametric_domain": [],
6476+
"error_domain": {
6477+
"empirical_error": {},
6478+
"algorithmic_error": {}
6479+
},
6480+
"extension_domain": [
6481+
{
6482+
"extension_schema": "http://www.w3id.org/biocompute/extension_domain/1.2.0/dataset/dataset_extension.json",
6483+
"dataset_extension": {
6484+
"additional_license": {
6485+
"data_license": "https://creativecommons.org/licenses/by/4.0/",
6486+
"script_license": "https://www.gnu.org/licenses/gpl-3.0.en.html"
6487+
},
6488+
"dataset_categories": [
6489+
{
6490+
"category_value": "Other",
6491+
"category_name": "species"
6492+
},
6493+
{
6494+
"category_value": "Other",
6495+
"category_name": "molecule"
6496+
},
6497+
{
6498+
"category_value": "non-core",
6499+
"category_name": "priority"
6500+
},
6501+
{
6502+
"category_value": "Dictionary",
6503+
"category_name": "species"
6504+
},
6505+
{
6506+
"category_value": "tsv",
6507+
"category_name": "file_type"
6508+
},
6509+
{
6510+
"category_value": "reviewed",
6511+
"category_name": "status"
6512+
}
6513+
]
6514+
}
6515+
}
6516+
]
6517+
},
6518+
"object_class": null,
6519+
"object_id": "http://127.0.0.1:8000/TEST_000001/1.0",
6520+
"owner_group": "bco_api_user",
6521+
"owner_user": "test50",
6522+
"prefix": "TEST",
6523+
"schema": "IEEE",
6524+
"state": "PUBLISHED",
6525+
"last_update": "2022-06-28T23:44:58.161Z"
6526+
}
6527+
}, {
6528+
"model": "api.bco",
6529+
"pk": 13,
63006530
"fields": {
63016531
"contents": {
63026532
"object_id": "http://127.0.0.1:8000/TEST_000001/1.2",

tests/test_views/test_get_objectid.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,16 @@ def setUp(self):
1616
self.client = APIClient()
1717

1818
def test_view_published_bco_success(self):
19-
# Successful request with valid object ID
19+
"""Successful request with valid object ID
20+
"""
21+
2022
object_id = "TEST_000001"
21-
response = self.client.get(f'/api/{object_id}/')
23+
response = self.client.get(f'/{object_id}')
24+
import pdb; pdb.set_trace()
2225
self.assertEqual(response.status_code, 200)
2326

2427
def test_view_published_bco_not_found(self):
2528
# Request with a non-existent object ID
2629
object_id = "invalid_object_id"
27-
response = self.client.get(f'/api/{object_id}/')
30+
response = self.client.get(f'{object_id}/')
2831
self.assertEqual(response.status_code, 404)
29-
30-
def test_view_published_bco_unauthorized(self):
31-
# Request without authentication credentials
32-
response = self.client.get('/api/TEST_000001/')
33-
self.assertEqual(response.status_code, 401)
34-
35-
def test_view_published_bco_forbidden(self):
36-
# Request with valid object ID but unauthorized user
37-
# (ie-user without sufficient permissions to access the BCO)
38-
object_id = "TEST_000001"
39-
# Authenticate as a user without sufficient permissions ??
40-
# self.client.credentials(HTTP_AUTHORIZATION='Token your_invalid_token_here')
41-
response = self.client.get(f'/api/{object_id}/')
42-
self.assertEqual(response.status_code, 403)

0 commit comments

Comments
 (0)