-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into loris-integration-…
…phase-2
- Loading branch information
Showing
7 changed files
with
155 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from apps.activities.domain.activity_update import ActivityUpdate | ||
from apps.activity_assignments.domain.assignments import ActivityAssignmentCreate | ||
from apps.activity_assignments.service import ActivityAssignmentService | ||
from apps.answers.crud import AnswerItemsCRUD | ||
from apps.answers.crud.answers import AnswersCRUD | ||
from apps.answers.db.schemas import AnswerItemSchema, AnswerNoteSchema, AnswerSchema | ||
|
@@ -1124,29 +1126,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, | ||
|
@@ -1286,24 +1280,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, | ||
|
@@ -1360,9 +1351,81 @@ async def test_answer_activity_items_create_expired_temporary_relation_fail( | |
}, | ||
) | ||
|
||
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 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() | ||
|
||
async def test_answer_activity_items_create_expired_temporary_relation_with_assignment_success( | ||
self, | ||
tom: User, | ||
answer_create_applet_one: AppletAnswerCreate, | ||
client: TestClient, | ||
session: AsyncSession, | ||
sam: User, | ||
applet_one: AppletFull, | ||
applet_one_sam_respondent, | ||
applet_one_sam_subject, | ||
) -> None: | ||
client.login(tom) | ||
subject_service = SubjectsService(session, tom.id) | ||
|
||
data = answer_create_applet_one.copy(deep=True) | ||
|
||
client.login(sam) | ||
subject_service = SubjectsService(session, sam.id) | ||
source_subject = await subject_service.create( | ||
SubjectCreate( | ||
applet_id=applet_one.id, | ||
creator_id=tom.id, | ||
first_name="source", | ||
last_name="subject", | ||
email=EmailStr("[email protected]"), | ||
secret_user_id=f"{uuid.uuid4()}", | ||
) | ||
) | ||
target_subject = await subject_service.create( | ||
SubjectCreate( | ||
applet_id=applet_one.id, | ||
creator_id=tom.id, | ||
first_name="target", | ||
last_name="subject", | ||
secret_user_id=f"{uuid.uuid4()}", | ||
) | ||
) | ||
|
||
# Create an assignment by source subject about target subject | ||
await ActivityAssignmentService(session).create_many( | ||
applet_id=applet_one.id, | ||
assignments_create=[ | ||
ActivityAssignmentCreate( | ||
activity_id=answer_create_applet_one.activity_id, | ||
activity_flow_id=None, | ||
respondent_subject_id=source_subject.id, | ||
target_subject_id=target_subject.id, | ||
), | ||
], | ||
) | ||
|
||
# create a relation between respondent and source | ||
await subject_service.create_relation( | ||
relation="take-now", | ||
source_subject_id=applet_one_sam_subject.id, | ||
subject_id=source_subject.id, | ||
meta={ | ||
"expiresAt": (datetime.datetime.now() - datetime.timedelta(days=1)).isoformat(), | ||
}, | ||
) | ||
# create a relation between respondent and target | ||
await subject_service.create_relation( | ||
relation="take-now", | ||
source_subject_id=source_subject.id, | ||
source_subject_id=applet_one_sam_subject.id, | ||
subject_id=target_subject.id, | ||
meta={ | ||
"expiresAt": (datetime.datetime.now() - datetime.timedelta(days=1)).isoformat(), | ||
|
@@ -1373,12 +1436,12 @@ async def test_answer_activity_items_create_expired_temporary_relation_fail( | |
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() | ||
assert response.status_code == http.HTTPStatus.CREATED, response.json() | ||
|
||
async def test_answer_get_export_data__answer_from_respondent( | ||
self, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters