Skip to content

Commit 444831b

Browse files
committed
feat: catalog functions implemented
1 parent e9f82ba commit 444831b

5 files changed

Lines changed: 341 additions & 84 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
install:
22
uv sync --all-extras
33

4+
update:
5+
rm uv.lock
6+
uv sync
7+
48
test:
59
uv run --all-extras pytest
610

datashield_opal/impl.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def __init__(self, name: str, loginInfo: OpalClient.LoginInfo, profile: str = "d
142142
self.rsession = None
143143
self.rsession_started = False
144144

145+
def get_name(self):
146+
"""Get the name of the connection."""
147+
return self.name
148+
145149
def check_user(self) -> bool:
146150
"""Check if the user can authenticate by trying to retrieve the current subject profile."""
147151
try:
@@ -169,6 +173,30 @@ def has_table(self, name: str) -> bool:
169173
response = self._get(UriBuilder(["datasource", parts[0], "table", parts[1]]).build()).send()
170174
return response.code == 200
171175

176+
def list_table_variables(self, table) -> list:
177+
tokens = table.split(".")
178+
project_name = tokens[0]
179+
table_name = tokens[1]
180+
return (
181+
self
182+
._get(UriBuilder(["datasource", project_name, "table", table_name, "variables"]).build())
183+
.fail_on_error()
184+
.send()
185+
.from_json()
186+
)
187+
188+
def list_taxonomies(self) -> list:
189+
return self._get(UriBuilder(["system", "conf", "taxonomies"]).build()).fail_on_error().send().from_json()
190+
191+
def search_variables(self, query) -> list:
192+
return (
193+
self
194+
._get(UriBuilder(["datasources", "variables", "_search"]).query("query", query).build())
195+
.fail_on_error()
196+
.send()
197+
.from_json()
198+
)
199+
172200
def list_resources(self) -> list:
173201
response = self._get("/projects").fail_on_error().send()
174202
projects = response.from_json()

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "datashield-opal"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
description = ""
55
authors = [
66
{name = "Yannick Marcon", email = "yannick.marcon@obiba.org"}
@@ -23,7 +23,7 @@ classifiers = [
2323
"Programming Language :: Python :: 3.13",
2424
]
2525
dependencies = [
26-
"datashield>=0.2.0",
26+
"datashield @ git+https://github.com/datashield/datashield-python.git@catalog",
2727
"obiba_opal>=6.0.2"
2828
]
2929

tests/test_impl.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def test_tables(self):
8585
assert "CNSIM.CNSIM1" in tables
8686
assert conn.has_table("CNSIM.CNSIM1")
8787

88+
@pytest.mark.integration
89+
def test_table_variables(self):
90+
conn = self.conn
91+
variables = conn.list_table_variables("CNSIM.CNSIM1")
92+
assert type(variables) is list
93+
assert "LAB_TSC" in [v.get("name") for v in variables]
94+
8895
@pytest.mark.integration
8996
def test_resources(self):
9097
conn = self.conn

0 commit comments

Comments
 (0)