Skip to content

Commit

Permalink
fix: register tools without tool class identifier (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
kushagra189 committed Nov 10, 2021
1 parent 9db63dc commit 63424fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/ga4gh/trs/endpoints/test_register_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ def test_register_metadata_with_tool_class_validation_BadRequest(self):
tool = RegisterTool(data=data)
tool.register_metadata()

def test_register_metadata_without_tool_class_identifier(self):
"""Test for creating a tool with tool class without an identifier."""
app = Flask(__name__)
app.config['FOCA'] = Config(
db=MongoConfig(**MONGO_CONFIG),
endpoints=ENDPOINT_CONFIG_TOOL_CLASS_VALIDATION,
)
app.config['FOCA'].db.dbs['trsStore'].collections['tools'] \
.client = MagicMock()
app.config['FOCA'].db.dbs['trsStore'].collections['toolclasses'] \
.client = MagicMock()

data = deepcopy(MOCK_TOOL_VERSION_ID)
data["toolclass"].pop("id")
with app.app_context():
tool = RegisterTool(data=data)
tool.register_metadata()
assert isinstance(tool.data['id'], str)

def test_register_metadata_tool_duplicate_key(self):
"""Test for creating a tool; duplicate key error occurs."""
app = Flask(__name__)
Expand Down
9 changes: 9 additions & 0 deletions trs_filer/ga4gh/trs/endpoints/register_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ def register_metadata(self) -> None:
f"{self.api_path}/tools/{self.data['id']}"
)

# set tool class identifier if not present
tool_class_id = self.data['toolclass'].get('id', None)
if tool_class_id is None:
tool_class_id = generate_id(
charset=self.id_charset,
length=self.id_length
)
self.data['toolclass']['id'] = tool_class_id

# process version information
version_list = [
v.get('id', None) for v in self.data['versions']
Expand Down

0 comments on commit 63424fb

Please sign in to comment.