-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_search_events_for_schedule.py
More file actions
111 lines (93 loc) · 3.37 KB
/
test_search_events_for_schedule.py
File metadata and controls
111 lines (93 loc) · 3.37 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from conferences.tests.factories import KeynoteFactory
from i18n.strings import LazyI18nString
import pytest
from submissions.models import Submission
from submissions.tests.factories import SubmissionFactory
pytestmark = pytest.mark.django_db
def _search_events_for_schedule(client, **input):
return client.query(
"""query SearchEventsForSchedule($conferenceId: ID!, $query: String!) {
searchEventsForSchedule(conferenceId: $conferenceId, query: $query) {
results {
__typename
... on Submission {
id
}
... on Keynote {
id
}
}
}
}""",
variables={**input},
)
@pytest.mark.parametrize("user_to_test", ["admin_user", "user", "not_authenticated"])
def test_cannot_search_without_permission(
admin_graphql_api_client,
user_to_test,
admin_user,
user,
conference_with_schedule_setup,
):
if user_to_test == "admin_user":
admin_graphql_api_client.force_login(admin_user)
elif user_to_test == "user":
admin_graphql_api_client.force_login(user)
conference = conference_with_schedule_setup
response = _search_events_for_schedule(
admin_graphql_api_client, conferenceId=conference.id, query="TDD"
)
assert response["errors"][0]["message"] == "Cannot edit schedule"
assert not response.get("data")
def test_search(
admin_graphql_api_client, admin_superuser, conference_with_schedule_setup
):
admin_graphql_api_client.force_login(admin_superuser)
conference = conference_with_schedule_setup
submission_1 = SubmissionFactory(
conference=conference,
status=Submission.STATUS.accepted,
title=LazyI18nString({"en": "My TDD talk", "it": ""}),
speaker__name="John Doe",
)
submission_2 = SubmissionFactory(
conference=conference,
status=Submission.STATUS.proposed,
pending_status=Submission.STATUS.accepted,
title=LazyI18nString({"en": "TDD talk", "it": ""}),
speaker__name="John Doe",
)
SubmissionFactory(
conference=conference,
status=Submission.STATUS.accepted,
title=LazyI18nString({"en": "Unrelated submission", "it": ""}),
speaker__name="Jane Doe",
)
keynote_1 = KeynoteFactory(
conference=conference,
title=LazyI18nString({"en": "A keynote about TDD, yes, really.", "it": ""}),
)
KeynoteFactory(
conference=conference,
title=LazyI18nString({"en": "Unrelated keynote.", "it": ""}),
)
SubmissionFactory(
conference=conference,
status=Submission.STATUS.rejected,
title=LazyI18nString({"en": "TDD: How to do it", "it": ""}),
)
response = _search_events_for_schedule(
admin_graphql_api_client, conferenceId=conference.id, query="TDD"
)
assert not response.get("errors")
data = response["data"]
assert len(data["searchEventsForSchedule"]["results"]) == 3
assert {"__typename": "Submission", "id": str(submission_1.hashid)} in data[
"searchEventsForSchedule"
]["results"]
assert {"__typename": "Keynote", "id": str(keynote_1.id)} in data[
"searchEventsForSchedule"
]["results"]
assert {"__typename": "Submission", "id": str(submission_2.hashid)} in data[
"searchEventsForSchedule"
]["results"]