Skip to content

Commit

Permalink
Connection creates uri + test
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Sep 20, 2024
1 parent 15c3da7 commit 966737f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion omnipath_metabo/schema/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def _from_file(self) -> None:

self._param = yaml.load(fp, Loader = yaml.FullLoader)

@property
def _uri(self) -> str:

return f'postgresql://'
return (
'postgresql://{user}:{password}@'
'{host}:{port}/{database}'.format(**self._param)
)
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ def dummy_connection_config(testtmp, dummy_con_param):
fp.write(yaml.dump(dummy_con_param))

return path


@pytest.fixture
def dummy_con_uri():

return 'postgresql://testuser:testpw@myhost:5432/testdb'
8 changes: 7 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ def test_param_dict(dummy_con_param):

con = _connection.Connection(dummy_con_param)

assert con._param == dummy_con_param
assert con._param == dummy_con_param

def test_uri(dummy_con_param, dummy_con_uri):

con = _connection.Connection(dummy_con_param)

assert con._uri == dummy_con_uri

0 comments on commit 966737f

Please sign in to comment.