Skip to content

Commit

Permalink
Test transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
madwort committed Oct 10, 2024
1 parent 44e7c07 commit 0f050ed
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/lib/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
migrate_db,
query_params_to_sql,
select_values,
transaction,
update,
upsert,
)
Expand All @@ -42,6 +43,38 @@ def test_basic_roundtrip(tmp_work_dir):
assert job.output_spec == j.output_spec


def test_insert_in_transaction_success(tmp_work_dir):
job = Job(
id="foo123",
job_request_id="bar123",
state=State.RUNNING,
output_spec={"hello": [1, 2, 3]},
)

with transaction():
insert(job)
j = find_one(Job, job_request_id__in=["bar123", "baz123"])
assert job.id == j.id
assert job.output_spec == j.output_spec


def test_insert_in_transaction_fail(tmp_work_dir):
job = Job(
id="foo123",
job_request_id="bar123",
state=State.RUNNING,
output_spec={"hello": [1, 2, 3]},
)

with transaction():
insert(job)
conn = get_connection()
conn.execute("ROLLBACK")

with pytest.raises(ValueError):
find_one(Job, job_request_id__in=["bar123", "baz123"])


def test_generate_insert_sql(tmp_work_dir):
job = Job(id="foo123", action="foo")
sql, _ = generate_insert_sql(job)
Expand Down

0 comments on commit 0f050ed

Please sign in to comment.