-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_managers.py
65 lines (51 loc) · 1.83 KB
/
test_managers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from unittest import mock
from uuid import UUID
from asyncpg.connection import Connection
from cdb.api.db.crud.account import get_accounts_from_email
from cdb.api.db.crud.manager import get_managers_from_deployment
ENDPOINT_PATH = "/v1/managers/create"
sender_email = "[email protected]"
@mock.patch("cdb.api.v1.routers.managers.send_invitation_email")
async def test_jwt_token_verification(
mock_send_invitation_mail: mock.Mock,
test_client,
get_admin_structure_jwt,
):
response = test_client.post(
ENDPOINT_PATH,
json={"email": sender_email, "firstname": "lionel", "lastname": "Bé"},
headers={"jwt-token": get_admin_structure_jwt},
)
json = response.json()
assert response.status_code == 403
assert json["detail"] == "Operation forbidden to the given role"
@mock.patch("cdb.api.v1.routers.managers.send_invitation_email")
async def test_insert_admin_in_db(
mock_send_invitation_mail: mock.Mock,
test_client,
db_connection: Connection,
get_admin_cdb_jwt,
deployment_id_cd93: UUID,
):
test_client.post(
ENDPOINT_PATH,
json={
"email": sender_email,
"firstname": "lionel",
"lastname": "Bé",
"deployment_id": deployment_id_cd93,
},
headers={"jwt-token": get_admin_cdb_jwt},
)
admins = await get_managers_from_deployment(db_connection, deployment_id_cd93)
assert sender_email in [admin.email for admin in admins]
[account] = await get_accounts_from_email(db_connection, sender_email)
assert account
assert mock_send_invitation_mail.call_count == 1
mock_send_invitation_mail.assert_called_once()
mock_send_invitation_mail.assert_called_once_with(
email=sender_email,
firstname="lionel",
lastname="Bé",
access_key=account.access_key,
)