Skip to content

Commit

Permalink
added get_view list function
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Jan 10, 2024
1 parent 6a0b0df commit 98a89ae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pepdbagent/modules/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SUBMISSION_DATE_KEY,
LAST_UPDATE_DATE_KEY,
)
from pepdbagent.db_utils import BaseEngine, Projects
from pepdbagent.db_utils import BaseEngine, Projects, Views
from pepdbagent.exceptions import FilterError, ProjectNotFoundError, RegistryPathError
from pepdbagent.models import AnnotationList, AnnotationModel
from pepdbagent.utils import convert_date_string_to_date, registry_path_converter, tuple_converter
Expand Down Expand Up @@ -572,3 +572,26 @@ def get_by_rp_list(

else:
return self.get_by_rp(registry_paths, admin)

def get_views(self, namespace: str, name: str, tag: str = DEFAULT_TAG) -> List[str]:
"""
Get list of views of the project
:param namespace: namespace of the project
:param name: name of the project
:param tag: tag of the project
:return: list of views of the project
"""
statement = select(Views.name).where(
Views.project_mapping.has(namespace=namespace, name=name, tag=tag),
and_(
Projects.name == name,
Projects.namespace == namespace,
Projects.tag == tag,
),
)
views = self._pep_db_engine.session_execute(statement).all()
if views:
return [v[0] for v in views]
else:
return []
20 changes: 20 additions & 0 deletions tests/test_pepagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,3 +1172,23 @@ def test_get_snap_view(self, initiate_pepdb_con, namespace, name, sample_name, v
)

assert len(snap_project.samples) == 2

@pytest.mark.parametrize(
"namespace, name, sample_name, view_name",
[
["namespace1", "amendments1", "pig_0h", "view1"],
],
)
def test_get_view_list_from_project(
self, initiate_pepdb_con, namespace, name, sample_name, view_name
):
initiate_pepdb_con.view.create(
"view1",
{
"project_namespace": namespace,
"project_name": name,
"project_tag": "default",
"sample_list": [sample_name, "pig_1h"],
},
)
assert initiate_pepdb_con.annotation.get_views(namespace, name, "default")[0] == "view1"

0 comments on commit 98a89ae

Please sign in to comment.