Skip to content

Commit

Permalink
Add background tasks to unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
JBorrow committed Feb 5, 2024
1 parent a024322 commit 6599985
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Server(BaseModel):
SQLALCHEMY_DATABASE_URI: str
PORT: str
ADD_STORES: str
LIBRARIAN_BACKGROUND_CHECK_INTEGRITY: str
LIBRARIAN_BACKGROUND_CREATE_LOCAL_CLONE: str
LIBRARIAN_BACKGROUND_SEND_CLONE: str
LIBRARIAN_BACKGROUND_RECIEVE_CLONE: str
process: str | None = None

@property
Expand All @@ -35,6 +39,10 @@ def env(self) -> dict[str, str]:
"ADD_STORES": self.ADD_STORES,
"ALEMBIC_CONFIG_PATH": str(Path(__file__).parent.parent),
"ALEMBIC_PATH": shutil.which("alembic"),
"LIBRARIAN_BACKGROUND_CHECK_INTEGRITY": self.LIBRARIAN_BACKGROUND_CHECK_INTEGRITY,
"LIBRARIAN_BACKGROUND_CREATE_LOCAL_CLONE": self.LIBRARIAN_BACKGROUND_CREATE_LOCAL_CLONE,
"LIBRARIAN_BACKGROUND_SEND_CLONE": self.LIBRARIAN_BACKGROUND_SEND_CLONE,
"LIBRARIAN_BACKGROUND_RECIEVE_CLONE": self.LIBRARIAN_BACKGROUND_RECIEVE_CLONE,
}


Expand Down Expand Up @@ -108,6 +116,29 @@ def server_setup(tmp_path_factory) -> Server:

add_stores = json.dumps(store_config)

check_integrity = json.dumps(
[
{
"task_name": "check",
"every": "00:01:00",
"age_in_days": 7,
"store_name": "local_store",
}
]
)

create_local_clone = json.dumps(
[
{
"task_name": "clone",
"every": "00:01:00",
"age_in_days": 7,
"clone_from": "local_store",
"clone_to": "local_clone",
}
]
)

return Server(
id=server_id_and_port,
base_path=tmp_path,
Expand All @@ -118,6 +149,10 @@ def server_setup(tmp_path_factory) -> Server:
SQLALCHEMY_DATABASE_URI=f"sqlite:///{database}",
PORT=str(server_id_and_port),
ADD_STORES=add_stores,
LIBRARIAN_BACKGROUND_CHECK_INTEGRITY=check_integrity,
LIBRARIAN_BACKGROUND_CREATE_LOCAL_CLONE=create_local_clone,
LIBRARIAN_BACKGROUND_SEND_CLONE="[]",
LIBRARIAN_BACKGROUND_RECIEVE_CLONE="[]",
)


Expand Down

0 comments on commit 6599985

Please sign in to comment.