aboutsummaryrefslogtreecommitdiff
path: root/tests/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fixtures')
-rw-r--r--tests/fixtures/models.py73
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