Skip to content

Commit

Permalink
fix: delete inappropriate temp relations in tests
Browse files Browse the repository at this point in the history
This temporary relation is not normally created for Take Now:

❌ source subject ⇔ target subject

Only these two temporary relations should be created:

✅ inputting subject ⇔ source subject
✅ inputting subject ⇔ target subject

So deleted superfluous calls to `create_relation` where found in tests.
  • Loading branch information
farmerpaul committed Nov 26, 2024
1 parent 678f55b commit ab62b2a
Showing 1 changed file with 20 additions and 49 deletions.
69 changes: 20 additions & 49 deletions src/apps/answers/tests/test_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,29 +1118,21 @@ async def test_answer_activity_items_create_temporary_relation_success(
},
)

await subject_service.create_relation(
relation="take-now",
source_subject_id=source_subject.id,
subject_id=target_subject.id,
meta={
"expiresAt": (datetime.datetime.now() + datetime.timedelta(days=1)).isoformat(),
},
)

data.source_subject_id = source_subject.id
data.target_subject_id = target_subject.id
data.input_subject_id = applet_one_sam_subject.id

# before posting the request, make sure that there is a temporary relation
existing_relation = await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)
assert existing_relation
# before posting the request, make sure that there are temporary relations
assert subject_service.get_relation(applet_one_sam_subject.id, source_subject.id)
assert subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)

response = await client.post(self.answer_url, data=data)

assert response.status_code == http.HTTPStatus.CREATED, response.json()
# after submitting make sure that the relation has been deleted
relation_exists = await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)
assert not relation_exists

# after submitting make sure that the relations have been deleted
assert not await subject_service.get_relation(applet_one_sam_subject.id, source_subject.id)
assert not await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)

async def test_answer_activity_items_relation_equal_other_when_relation_is_temp(
self,
Expand Down Expand Up @@ -1280,24 +1272,21 @@ async def test_answer_activity_items_create_permanent_relation_success(
relation="parent", source_subject_id=applet_one_sam_subject.id, subject_id=target_subject.id
)

await subject_service.create_relation(
relation="parent", source_subject_id=source_subject.id, subject_id=target_subject.id
)

data.source_subject_id = source_subject.id
data.target_subject_id = target_subject.id
data.input_subject_id = applet_one_sam_subject.id

# before posting the request, make sure that there is a temporary relation
existing_relation = await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)
assert existing_relation
# before posting the request, make sure that there are temporary relations
assert await subject_service.get_relation(applet_one_sam_subject.id, source_subject.id)
assert await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)

response = await client.post(self.answer_url, data=data)

assert response.status_code == http.HTTPStatus.CREATED, response.json()
# after submitting make sure that the relation has not been deleted
relation_exists = await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)
assert relation_exists

# after submitting make sure that the relations have not been deleted
assert await subject_service.get_relation(applet_one_sam_subject.id, source_subject.id)
assert await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)

async def test_answer_activity_items_create_expired_temporary_relation_fail(
self,
Expand Down Expand Up @@ -1354,22 +1343,13 @@ async def test_answer_activity_items_create_expired_temporary_relation_fail(
},
)

await subject_service.create_relation(
relation="take-now",
source_subject_id=source_subject.id,
subject_id=target_subject.id,
meta={
"expiresAt": (datetime.datetime.now() - datetime.timedelta(days=1)).isoformat(),
},
)

data.source_subject_id = source_subject.id
data.target_subject_id = target_subject.id
data.input_subject_id = applet_one_sam_subject.id

# before posting the request, make sure that there is a temporary relation
existing_relation = await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)
assert existing_relation
# before posting the request, make sure that there are temporary relations
assert await subject_service.get_relation(applet_one_sam_subject.id, source_subject.id)
assert await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)

response = await client.post(self.answer_url, data=data)
assert response.status_code == http.HTTPStatus.BAD_REQUEST, response.json()
Expand Down Expand Up @@ -1444,22 +1424,13 @@ async def test_answer_activity_items_create_expired_temporary_relation_with_assi
},
)

await subject_service.create_relation(
relation="take-now",
source_subject_id=source_subject.id,
subject_id=target_subject.id,
meta={
"expiresAt": (datetime.datetime.now() - datetime.timedelta(days=1)).isoformat(),
},
)

data.source_subject_id = source_subject.id
data.target_subject_id = target_subject.id
data.input_subject_id = applet_one_sam_subject.id

# before posting the request, make sure that there is a temporary relation
existing_relation = await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)
assert existing_relation
# before posting the request, make sure that there are temporary relations
assert await subject_service.get_relation(applet_one_sam_subject.id, source_subject.id)
assert await subject_service.get_relation(applet_one_sam_subject.id, target_subject.id)

response = await client.post(self.answer_url, data=data)
assert response.status_code == http.HTTPStatus.CREATED, response.json()
Expand Down

0 comments on commit ab62b2a

Please sign in to comment.