-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathtest_invitation.py
50 lines (40 loc) · 1.76 KB
/
test_invitation.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
from fastapi import status
from app.routers.invitation import get_all_invitations, get_invitation_by_id
class TestInvitations:
NO_INVITATIONS = b"You don't have any invitations."
URL = "/invitations/"
@staticmethod
def test_view_no_invitations(invitation_test_client):
response = invitation_test_client.get(TestInvitations.URL)
assert response.ok
assert TestInvitations.NO_INVITATIONS in response.content
@staticmethod
def test_accept_invitations(user, invitation, invitation_test_client):
invitation = {"invite_id ": invitation.id}
resp = invitation_test_client.post(
TestInvitations.URL, data=invitation)
assert resp.status_code == status.HTTP_302_FOUND
@staticmethod
def test_get_all_invitations_success(invitation, event, user, session):
invitations = get_all_invitations(event=event, db=session)
assert invitations == [invitation]
invitations = get_all_invitations(recipient=user, db=session)
assert invitations == [invitation]
@staticmethod
def test_get_all_invitations_failure(user, session):
invitations = get_all_invitations(unknown_parameter=user, db=session)
assert invitations == []
invitations = get_all_invitations(recipient=None, db=session)
assert invitations == []
@staticmethod
def test_get_invitation_by_id(invitation, session):
get_invitation = get_invitation_by_id(invitation.id, db=session)
assert get_invitation == invitation
@staticmethod
def test_repr(invitation):
invitation_repr = (
f'<Invitation '
f'({invitation.event.owner}'
f'to {invitation.recipient})>'
)
assert invitation.__repr__() == invitation_repr