Skip to content

Commit

Permalink
Create account for experiment owner
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhigley committed Sep 4, 2024
1 parent 1ef6939 commit 8a0c773
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/poprox_storage/repositories/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ def fetch_account_by_email(self, email: str) -> Account | None:
return accounts[0]
return None

def store_account(self, account: Account) -> UUID | None:
account_tbl = self.tables["accounts"]
query = (
sqlalchemy.insert(account_tbl)
.values(
account_id=account.account_id,
email=account.email,
source=account.source,
status="new_account",
)
.returning(account_tbl.c.account_id)
)
row = self.conn.execute(query).one_or_none()
return row.account_id

def store_new_account(self, email: str, source: str) -> Account:
account_tbl = self.tables["accounts"]
query = (
Expand Down
13 changes: 12 additions & 1 deletion tests/repositories/test_experiments.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from uuid import UUID

from poprox_concepts.domain import Account
from poprox_storage.concepts.manifest import manifest_to_experiment, parse_manifest_toml
from poprox_storage.paths import project_root
from poprox_storage.repositories import DbExperimentRepository
from poprox_storage.repositories import DbAccountRepository, DbExperimentRepository
from poprox_storage.repositories.data_stores.db import DB_ENGINE


Expand All @@ -13,6 +14,16 @@ def test_store_experiment():
experiment = manifest_to_experiment(manifest)

with DB_ENGINE.connect() as conn:
account_repo = DbAccountRepository(conn)
account_repo.store_account(
Account(
account_id=experiment.owner.members[0],
email="[email protected]",
source="test",
status="test",
)
)

experiment_repo = DbExperimentRepository(conn)
experiment_id = experiment_repo.store_experiment(experiment)

Expand Down

0 comments on commit 8a0c773

Please sign in to comment.