-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add backend endpoints for managing edit sessions.
- Loading branch information
Showing
31 changed files
with
1,457 additions
and
13 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
Empty file.
Empty file.
Empty file.
86 changes: 86 additions & 0 deletions
86
tests/edit_session/api/integration/delete_participant_test.py
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 @@ | ||
# pylint: disable=missing-module-docstring,missing-function-docstring,redefined-outer-name,invalid-name,unused-argument,too-many-locals,too-many-arguments,too-many-statements,duplicate-code | ||
|
||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
import tests.edit_session.common as c | ||
import tests.user.common as cu | ||
from tests.edit_session.api.integration import requests as req | ||
from vran.edit_session.models_django import EditSessionParticipant | ||
from vran.exception import NotAuthenticatedException | ||
|
||
new_name = "patched name for user session" | ||
|
||
|
||
def test_unknown_user(auth_server, session_participant_commissioner): | ||
"Test response when user can not be authenticated" | ||
server, cookies = auth_server | ||
mock = MagicMock() | ||
mock.side_effect = NotAuthenticatedException() | ||
with patch("vran.edit_session.api.check_user", mock): | ||
rsp = req.delete_participant( | ||
server.url, c.id_session_user, cu.test_uuid_commissioner, cookies=cookies | ||
) | ||
assert rsp.status_code == 401 | ||
|
||
|
||
def test_no_cookies(auth_server, session_participant_commissioner): | ||
"Check error code for missing cookies" | ||
server, _cookies = auth_server | ||
rsp = req.delete_participant( | ||
server.url, c.id_session_user, cu.test_uuid_commissioner, cookies=None | ||
) | ||
assert rsp.status_code == 401 | ||
|
||
|
||
def test_applicant(auth_server_applicant, session_participant_commissioner): | ||
"Make sure applicant can not search for participants." | ||
server, cookies = auth_server_applicant | ||
rsp = req.delete_participant( | ||
server.url, c.id_session_user, cu.test_uuid_commissioner, cookies=cookies | ||
) | ||
assert rsp.status_code == 403 | ||
|
||
|
||
def test_wrong_user(auth_server1, session_participant_commissioner): | ||
server, _cookies, cookies = auth_server1 | ||
rsp = req.delete_participant( | ||
server.url, c.id_session_user, cu.test_uuid_commissioner, cookies=cookies | ||
) | ||
assert rsp.status_code == 403 | ||
|
||
|
||
def test_remove_as_owner(auth_server, session_participant_commissioner): | ||
"Make sure it can retrieve sessions owned by a user" | ||
server, cookies = auth_server | ||
assert ( | ||
len(EditSessionParticipant.objects.filter(edit_session_id=c.id_session_user)) | ||
== 2 | ||
) | ||
rsp = req.delete_participant( | ||
server.url, c.id_session_user, cu.test_uuid_commissioner, cookies=cookies | ||
) | ||
assert rsp.status_code == 200 | ||
assert ( | ||
len(EditSessionParticipant.objects.filter(edit_session_id=c.id_session_user)) | ||
== 1 | ||
) | ||
|
||
|
||
def test_remove_as_participant( | ||
user, auth_server_commissioner, session_participant_commissioner | ||
): | ||
"Make sure it can retrieve sessions owned by a user" | ||
assert ( | ||
len(EditSessionParticipant.objects.filter(edit_session_id=c.id_session_user)) | ||
== 2 | ||
) | ||
server, cookies = auth_server_commissioner | ||
rsp = req.delete_participant( | ||
server.url, c.id_session_user, cu.test_uuid_commissioner, cookies=cookies | ||
) | ||
assert rsp.status_code == 200 | ||
assert ( | ||
len(EditSessionParticipant.objects.filter(edit_session_id=c.id_session_user)) | ||
== 1 | ||
) |
63 changes: 63 additions & 0 deletions
63
tests/edit_session/api/integration/get_sessions_owner_test.py
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,63 @@ | ||
# pylint: disable=missing-module-docstring,missing-function-docstring,redefined-outer-name,invalid-name,unused-argument,too-many-locals,too-many-arguments,too-many-statements | ||
|
||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
import tests.edit_session.common as c | ||
import tests.user.common as cu | ||
from tests.edit_session.api.integration import requests as req | ||
from vran.exception import NotAuthenticatedException | ||
|
||
|
||
def test_unknown_user(auth_server): | ||
"Test response when user can not be authenticated" | ||
server, cookies = auth_server | ||
mock = MagicMock() | ||
mock.side_effect = NotAuthenticatedException() | ||
with patch("vran.edit_session.api.check_user", mock): | ||
rsp = req.get_sessions_owner(server.url, cookies=cookies) | ||
assert rsp.status_code == 401 | ||
|
||
|
||
def test_no_cookies(auth_server): | ||
"Check error code for missing cookies" | ||
server, _cookies = auth_server | ||
rsp = req.get_sessions_owner(server.url, cookies=None) | ||
assert rsp.status_code == 401 | ||
|
||
|
||
def test_applicant(auth_server_applicant): | ||
"Make sure applicant can not search for participants." | ||
server, cookies = auth_server_applicant | ||
rsp = req.get_sessions_owner(server.url, cookies=cookies) | ||
assert rsp.status_code == 403 | ||
|
||
|
||
def test_get_sessions_owner(auth_server, other_session): | ||
"Make sure it can retrieve sessions owned by a user" | ||
server, cookies = auth_server | ||
rsp = req.get_sessions_owner(server.url, cookies=cookies) | ||
assert rsp.status_code == 200 | ||
participant_json = { | ||
"id_participant": cu.test_uuid, | ||
"type_participant": "INTERNAL", | ||
"name_participant": cu.test_username, | ||
} | ||
owner_json = participant_json.copy() | ||
owner_json.pop("name_participant") | ||
json = rsp.json() | ||
session_list = json["edit_session_list"] | ||
assert session_list == [ | ||
{ | ||
"id_persistent": c.id_session_user, | ||
"owner": owner_json, | ||
"name": c.name_session_user, | ||
"participant_list": [participant_json], | ||
}, | ||
{ | ||
"id_persistent": c.id_session_user_changed, | ||
"owner": owner_json, | ||
"name": c.name_session_user_changed, | ||
"participant_list": [participant_json], | ||
}, | ||
] |
76 changes: 76 additions & 0 deletions
76
tests/edit_session/api/integration/get_sessions_participant_test.py
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,76 @@ | ||
# pylint: disable=missing-module-docstring,missing-function-docstring,redefined-outer-name,invalid-name,unused-argument,too-many-locals,too-many-arguments,too-many-statements | ||
|
||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
import tests.edit_session.common as c | ||
import tests.user.common as cu | ||
from tests.edit_session.api.integration import requests as req | ||
from vran.exception import NotAuthenticatedException | ||
|
||
|
||
def test_unknown_user(auth_server): | ||
"Test response when user can not be authenticated" | ||
server, cookies = auth_server | ||
mock = MagicMock() | ||
mock.side_effect = NotAuthenticatedException() | ||
with patch("vran.edit_session.api.check_user", mock): | ||
rsp = req.get_sessions_participant(server.url, cookies=cookies) | ||
assert rsp.status_code == 401 | ||
|
||
|
||
def test_no_cookies(auth_server): | ||
"Check error code for missing cookies" | ||
server, _cookies = auth_server | ||
rsp = req.get_sessions_participant(server.url, cookies=None) | ||
assert rsp.status_code == 401 | ||
|
||
|
||
def test_applicant(auth_server_applicant): | ||
"Make sure applicant can not search for participants." | ||
server, cookies = auth_server_applicant | ||
rsp = req.get_sessions_participant(server.url, cookies=cookies) | ||
assert rsp.status_code == 403 | ||
|
||
|
||
def test_get_sessions_participant( | ||
auth_server_commissioner, | ||
other_session, | ||
session_participant_commissioner, | ||
other_session_participant_commissioner, | ||
): | ||
"Make sure it can retrieve sessions owned by a user" | ||
server, cookies = auth_server_commissioner | ||
rsp = req.get_sessions_participant(server.url, cookies=cookies) | ||
assert rsp.status_code == 200 | ||
participant_json = { | ||
"id_participant": cu.test_uuid, | ||
"type_participant": "INTERNAL", | ||
"name_participant": cu.test_username, | ||
} | ||
owner_json = participant_json.copy() | ||
owner_json.pop("name_participant") | ||
participant_list = [ | ||
participant_json, | ||
{ | ||
"id_participant": cu.test_uuid_commissioner, | ||
"type_participant": "INTERNAL", | ||
"name_participant": cu.test_username_commissioner, | ||
}, | ||
] | ||
json = rsp.json() | ||
session_list = json["edit_session_list"] | ||
assert session_list == [ | ||
{ | ||
"id_persistent": c.id_session_user, | ||
"owner": owner_json, | ||
"name": c.name_session_user, | ||
"participant_list": participant_list, | ||
}, | ||
{ | ||
"id_persistent": c.id_session_user_changed, | ||
"owner": owner_json, | ||
"name": c.name_session_user_changed, | ||
"participant_list": participant_list, | ||
}, | ||
] |
Oops, something went wrong.