diff options
| author | Max Nanis | 2026-02-27 17:52:14 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-27 17:52:14 -0500 |
| commit | 3fda1fcd7b610947b21fc20efcfeab1bf1add7b0 (patch) | |
| tree | ddceac4b3d9fda0443367dfd90abc703e6786cba /tests/fixtures/models.py | |
| parent | 7e63d94751135b4219cf6b974dfb26932dda505d (diff) | |
| download | amt-jb-3fda1fcd7b610947b21fc20efcfeab1bf1add7b0.tar.gz amt-jb-3fda1fcd7b610947b21fc20efcfeab1bf1add7b0.zip | |
try for FKVioloation constraint. Jenkins drops the DB, not critical (depending on subsequent tests)
Diffstat (limited to 'tests/fixtures/models.py')
| -rw-r--r-- | tests/fixtures/models.py | 73 |
1 files changed, 49 insertions, 24 deletions
diff --git a/tests/fixtures/models.py b/tests/fixtures/models.py index b53e25a..671c7b3 100644 --- a/tests/fixtures/models.py +++ b/tests/fixtures/models.py @@ -13,6 +13,7 @@ from generalresearchutils.currency import USDCent from jb.models.definitions import HitStatus, HitReviewStatus, AssignmentStatus from jb.models.hit import HitType, HitQuestion, Hit from tests import generate_amt_id +from psycopg.errors import ForeignKeyViolation if TYPE_CHECKING: from jb.managers.hit import HitQuestionManager, HitTypeManager, HitManager @@ -74,10 +75,14 @@ def hit_type_record( yield ht - with pg_config.make_connection() as conn: - with conn.cursor() as c: - c.execute("DELETE FROM mtwerk_hittype WHERE id=%s", (ht.id,)) - conn.commit() + try: + with pg_config.make_connection() as conn: + with conn.cursor() as c: + c.execute("DELETE FROM mtwerk_hittype WHERE id=%s", (ht.id,)) + conn.commit() + + except ForeignKeyViolation: + pass # DB gets dropped anyway, don't care @pytest.fixture @@ -93,10 +98,14 @@ def hit_type_record_with_amt_id( yield ht - with pg_config.make_connection() as conn: - with conn.cursor() as c: - c.execute("DELETE FROM mtwerk_hittype WHERE id=%s", (ht.id,)) - conn.commit() + try: + with pg_config.make_connection() as conn: + with conn.cursor() as c: + c.execute("DELETE FROM mtwerk_hittype WHERE id=%s", (ht.id,)) + conn.commit() + + except ForeignKeyViolation: + pass # DB gets dropped anyway, don't care # --- HIT --- @@ -156,20 +165,28 @@ def hit_record( yield hit - with pg_config.make_connection() as conn: - with conn.cursor() as c: - c.execute("DELETE FROM mtwerk_hit WHERE id=%s", (hit.id,)) - conn.commit() + try: + with pg_config.make_connection() as conn: + with conn.cursor() as c: + c.execute("DELETE FROM mtwerk_hit WHERE id=%s", (hit.id,)) + conn.commit() + + except ForeignKeyViolation: + pass # DB gets dropped anyway, don't care @pytest.fixture def hit_in_amt( - hm: "HitManager", question_record: HitQuestion, hit_type_record_with_amt_id: HitType + amtm: AMTManager, + hm: "HitManager", + question_record: HitQuestion, + hit_type_record_with_amt_id: HitType, ) -> Hit: # Actually create a new HIT in amt (sandbox) - hit = AMTManager.create_hit_with_hit_type( + hit = amtm.create_hit_with_hit_type( hit_type=hit_type_record_with_amt_id, question=question_record ) + # Create it in the DB hm.create(hit) return hit @@ -210,12 +227,16 @@ def assignment_stub_record( yield assignment_stub - with pg_config.make_connection() as conn: - with conn.cursor() as c: - c.execute( - "DELETE FROM mtwerk_assignment WHERE id=%s", (assignment_stub.id,) - ) - conn.commit() + try: + with pg_config.make_connection() as conn: + with conn.cursor() as c: + c.execute( + "DELETE FROM mtwerk_assignment WHERE id=%s", (assignment_stub.id,) + ) + conn.commit() + + except ForeignKeyViolation: + pass # DB gets dropped anyway, don't care @pytest.fixture @@ -233,10 +254,14 @@ def assignment_record( yield assignment - with pg_config.make_connection() as conn: - with conn.cursor() as c: - c.execute("DELETE FROM mtwerk_assignment WHERE id=%s", (assignment.id,)) - conn.commit() + try: + with pg_config.make_connection() as conn: + with conn.cursor() as c: + c.execute("DELETE FROM mtwerk_assignment WHERE id=%s", (assignment.id,)) + conn.commit() + + except ForeignKeyViolation: + pass # DB gets dropped anyway, don't care @pytest.fixture |
