Skip to content

Commit

Permalink
test: coverage patch mailbox raises to 83%
Browse files Browse the repository at this point in the history
  • Loading branch information
octohuguesdumont committed Jul 10, 2024
1 parent e14a485 commit 7408864
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion src/routes/test_mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_with_webmail(
):
token = normal_user["token"]
virgin_token = virgin_user["token"]
admin = { "user": admin_token["user"], "password": admin_token["password"]}
admin_token = admin_token["token"]
domain_name = domain_web["name"]

Expand Down Expand Up @@ -124,13 +125,16 @@ def test_with_webmail(
"displayName": "Joli nom affichable",
}

# Lorsque je modifie une webmail -> 200 OK
# Et seul, les clefs demandées sont modifiées
response = client.patch(
f"/domains/{domain_name}/mailboxes/address",
json={
"displayName": "Joli nom afficha",
},
headers={"Authorization": f"Bearer {token}"},
)

assert response.status_code == fastapi.status.HTTP_200_OK
assert response.json() == {
"type": "mailbox",
Expand All @@ -141,6 +145,8 @@ def test_with_webmail(
"displayName": "Joli nom afficha",
}

# Lorque je veux modifier le givenName d'une webmail -> 200 OK
# Et le seul le givenName se modifie
response = client.patch(
f"/domains/{domain_name}/mailboxes/address",
json={
Expand All @@ -158,8 +164,60 @@ def test_with_webmail(
"displayName": "Joli nom afficha",
}

# Si on veut modifier le given name d'une mailbox ->
# Status OK
# Mais aucune modification ne sera faite

# Creer un domain mailbox pour le test
response = client.post(
"/domains/",
json={
"name": "new.com",
"features": ["mailbox"],
"context_name": None,
},
auth=(admin["user"], admin["password"])
)
assert response.status_code == fastapi.status.HTTP_201_CREATED

# Créer une mailbox pour le test
# FIXME parler avec Benjamin est ce que c'est logique de rendre les
# trois clefs obligatoires ? en sachant que les mailbox n'en ont pas
# besoin.
response = client.post(
"/domains/new.com/mailboxes/addr",
json={
"givenName": "",
"surName": "",
"displayName": "",
},
headers={"Authorization": f"Bearer {admin_token}"},
)
assert response.status_code == fastapi.status.HTTP_201_CREATED

# On modifie la mailbox
response = client.patch(
"/domains/new.com/mailboxes/addr",
json={
"givenName": "newGivenName",
},
headers={"Authorization": f"Bearer {admin_token}"},
)

# on acquitte le status 200 et le fait que rien n'a été modifié
assert response.status_code == fastapi.status.HTTP_200_OK
# FIXME: should be "ok" ? or "broken" ?
assert response.json() == {
"type": "mailbox",
"status": "broken",
"email": "[email protected]",
"surName": None,
"givenName": None,
"displayName": None,
}

# Si on patch sur un domaine qui n'existe pas -> not found
# Il faut etre admin pour pouvoir essayer de toucher un domaine qui
# Il faut être admin pour pouvoir essayer de toucher un domaine qui
# n'existe pas, les gens normaux auront un permisison denied.
response = client.patch(
"/domains/pas-un-domaine/mailboxes/hop",
Expand Down

0 comments on commit 7408864

Please sign in to comment.