Skip to content

Commit

Permalink
feat: align with main, add get latest dataset method to get all model…
Browse files Browse the repository at this point in the history
…s api
  • Loading branch information
dtria91 committed Jun 25, 2024
1 parent b7935b0 commit eb475d6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/app/services/model_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@ def get_all_models(
self,
) -> List[ModelOut]:
models = self.model_dao.get_all()
return [ModelOut.from_model(model) for model in models]
model_out_list = []
for model in models:
latest_reference_uuid, latest_current_uuid = self.get_latest_dataset_uuids(
model.uuid
)
model_out = ModelOut.from_model(
model=model,
latest_reference_uuid=latest_reference_uuid,
latest_current_uuid=latest_current_uuid,
)
model_out_list.append(model_out)
return model_out_list

def get_all_models_paginated(
self,
Expand Down
22 changes: 22 additions & 0 deletions api/tests/services/model_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,27 @@ def test_get_all_models_paginated_ok(self):
assert result.items[1].name == 'model2'
assert result.items[2].name == 'model3'

def test_get_all_models_ok(self):
model1 = db_mock.get_sample_model(id=1, uuid=uuid.uuid4(), name='model1')
model2 = db_mock.get_sample_model(id=2, uuid=uuid.uuid4(), name='model2')
model3 = db_mock.get_sample_model(id=3, uuid=uuid.uuid4(), name='model3')
sample_models = [model1, model2, model3]
self.model_dao.get_all = MagicMock(return_value=sample_models)
self.rd_dao.get_latest_reference_dataset_by_model_uuid = MagicMock(
return_value=None
)
self.cd_dao.get_latest_current_dataset_by_model_uuid = MagicMock(
return_value=None
)

result = self.model_service.get_all_models()

self.model_dao.get_all.assert_called_once()

assert len(result) == 3
assert result[0].name == 'model1'
assert result[1].name == 'model2'
assert result[2].name == 'model3'


model_uuid = db_mock.MODEL_UUID

0 comments on commit eb475d6

Please sign in to comment.