Skip to content

Commit

Permalink
feat(mi): Add userId to get subjects query (M2-6582) (#1298)
Browse files Browse the repository at this point in the history
This PR updates GET `/subjects/{subject_id}` to return more data in the form of the following fields:
- User ID
  • Loading branch information
sultanofcardio committed May 15, 2024
1 parent b5d4c75 commit 555ca93
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/apps/subjects/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,6 @@ async def get_subject(
last_seen=answer_dates.get(subject.id),
tag=subject.tag,
applet_id=subject.applet_id,
user_id=subject.user_id,
)
)
1 change: 1 addition & 0 deletions src/apps/subjects/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ class SubjectReadResponse(SubjectUpdateRequest):
id: uuid.UUID
last_seen: datetime.datetime | None
applet_id: uuid.UUID
user_id: uuid.UUID | None
41 changes: 39 additions & 2 deletions src/apps/subjects/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ async def lucy_invitation_payload(lucy: User) -> dict:
)


@pytest.fixture
async def applet_one_shell_account(session: AsyncSession, applet_one: AppletFull, tom: User) -> Subject:
return await SubjectsService(session, tom.id).create(
Subject(
applet_id=applet_one.id,
creator_id=tom.id,
first_name="Shell",
last_name="Account",
nickname="shell-account-0",
secret_user_id=f"{uuid.uuid4()}",
email="shell@mail.com",
)
)


class TestSubjects(BaseTest):
fixtures = [
"workspaces/fixtures/workspaces.json",
Expand Down Expand Up @@ -436,20 +451,21 @@ async def test_error_try_delete_subject_by_not_owner(
res = await client.delete(delete_url, data=dict(deleteAnswers=True))
assert res.status_code == expected

async def test_get_subject(self, client, tom: User, tom_applet_one_subject: Subject, lucy, lucy_create):
async def test_get_subject_full(self, client, tom: User, tom_applet_one_subject: Subject, lucy, lucy_create):
subject_id = tom_applet_one_subject.id
client.login(tom)
response = await client.get(self.subject_detail_url.format(subject_id=subject_id))
assert response.status_code == http.HTTPStatus.OK
data = response.json()
assert data
res = data["result"]
assert set(res.keys()) == {"id", "secretUserId", "nickname", "lastSeen", "tag", "appletId"}
assert set(res.keys()) == {"id", "secretUserId", "nickname", "lastSeen", "tag", "appletId", "userId"}
assert uuid.UUID(res["id"]) == tom_applet_one_subject.id
assert res["secretUserId"] == tom_applet_one_subject.secret_user_id
assert res["nickname"] == tom_applet_one_subject.nickname
assert res["tag"] == tom_applet_one_subject.tag
assert uuid.UUID(res["appletId"]) == tom_applet_one_subject.applet_id
assert uuid.UUID(res["userId"]) == tom.id

# not found
response = await client.get(self.subject_detail_url.format(subject_id=uuid.uuid4()))
Expand All @@ -460,6 +476,27 @@ async def test_get_subject(self, client, tom: User, tom_applet_one_subject: Subj
response = await client.get(self.subject_detail_url.format(subject_id=subject_id))
assert response.status_code == http.HTTPStatus.FORBIDDEN

async def test_get_subject_limited(
self,
client,
applet_one_shell_account: Subject,
tom: User,
):
subject_id = applet_one_shell_account.id
client.login(tom)
response = await client.get(self.subject_detail_url.format(subject_id=subject_id))
assert response.status_code == http.HTTPStatus.OK
data = response.json()
assert data
res = data["result"]
assert set(res.keys()) == {"id", "secretUserId", "nickname", "lastSeen", "tag", "appletId", "userId"}
assert uuid.UUID(res["id"]) == applet_one_shell_account.id
assert res["secretUserId"] == applet_one_shell_account.secret_user_id
assert res["nickname"] == applet_one_shell_account.nickname
assert res["tag"] == applet_one_shell_account.tag
assert uuid.UUID(res["appletId"]) == applet_one_shell_account.applet_id
assert res["userId"] is None

async def test_get_reviewer_subject(
self,
client,
Expand Down

0 comments on commit 555ca93

Please sign in to comment.