From ab62b2a6c9a10f859305635b1892d1f696eb98ad Mon Sep 17 00:00:00 2001 From: farmerpaul Date: Tue, 26 Nov 2024 13:31:32 -0400 Subject: [PATCH] fix: delete inappropriate temp relations in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/apps/answers/tests/test_answers.py | 69 ++++++++------------------ 1 file changed, 20 insertions(+), 49 deletions(-) diff --git a/src/apps/answers/tests/test_answers.py b/src/apps/answers/tests/test_answers.py index 697a2131d21..2958929f790 100644 --- a/src/apps/answers/tests/test_answers.py +++ b/src/apps/answers/tests/test_answers.py @@ -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, @@ -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, @@ -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() @@ -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()