-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a752671
commit 29f6d17
Showing
2 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pytest | ||
from graphql_relay.node.node import to_global_id | ||
from coordinator.api.models import ReleaseNote | ||
from coordinator.api.factories.release_note import ReleaseNoteFactory | ||
|
||
|
||
UPDATE_RELEASE_NOTE = """ | ||
mutation ($releaseNote: ID!, $input: UpdateReleaseNoteInput!) { | ||
updateReleaseNote(releaseNote: $releaseNote, input: $input) { | ||
releaseNote { | ||
id | ||
kfId | ||
uuid | ||
author | ||
description | ||
createdAt | ||
study { | ||
id | ||
kfId | ||
} | ||
release { | ||
id | ||
kfId | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"user_type,expected", | ||
[("admin", True), ("dev", True), ("user", False), ("anon", False)], | ||
) | ||
def test_update_release_note_permissions(db, test_client, user_type, expected): | ||
""" | ||
ADMIN - Can update new release notes | ||
DEV - Can update new release notes | ||
USER - May not update relase notes | ||
anonomous - May not update release notes | ||
""" | ||
release_note = ReleaseNoteFactory() | ||
release_note_id = to_global_id("ReleaseNoteNode", release_note.kf_id) | ||
|
||
variables = { | ||
"releaseNote": release_note_id, | ||
"input": {"description": "Test "}, | ||
} | ||
|
||
client = test_client(user_type) | ||
resp = client.post( | ||
"/graphql", | ||
format="json", | ||
data={"query": UPDATE_RELEASE_NOTE, "variables": variables}, | ||
) | ||
print(resp.json()) | ||
|
||
if expected: | ||
assert ( | ||
"kfId" in resp.json()["data"]["updateReleaseNote"]["releaseNote"] | ||
) | ||
else: | ||
assert "errors" in resp.json() | ||
|
||
|
||
def test_update_release_note(db, admin_client): | ||
""" | ||
Test that release notes are updated correctly. | ||
""" | ||
release_note = ReleaseNoteFactory() | ||
release_note_id = to_global_id("ReleaseNoteNode", release_note.kf_id) | ||
|
||
variables = { | ||
"releaseNote": release_note_id, | ||
"input": {"description": "Updated description"}, | ||
} | ||
resp = admin_client.post( | ||
"/graphql", | ||
format="json", | ||
data={"query": UPDATE_RELEASE_NOTE, "variables": variables}, | ||
) | ||
|
||
release = resp.json()["data"]["updateReleaseNote"]["releaseNote"] | ||
assert ReleaseNote.objects.count() == 1 | ||
assert release["kfId"] == ReleaseNote.objects.first().kf_id | ||
assert release["description"] == variables["input"]["description"] |