1+ # -*- coding: utf-8 -*-
2+ import pytest
3+ from django .core .urlresolvers import reverse
4+
5+ from web .tests import EventFactory , ApprovedEventFactory , PastEventFactory
6+
7+ @pytest .mark .django_db
8+ def test_search_show_only_approved (db , client ):
9+ approved_event = ApprovedEventFactory .create ()
10+ unapproved_event = EventFactory .create ()
11+
12+ response = client .get ('/search/' )
13+
14+ assert approved_event .get_absolute_url () in response .content
15+ assert unapproved_event .get_absolute_url () not in response .content
16+
17+ map (lambda x : x .delete (), [approved_event , unapproved_event ])
18+
19+ def test_search_do_not_show_past_events (db , client ):
20+ future_event = ApprovedEventFactory .create ()
21+ past_event = PastEventFactory .create (status = 'APPROVED' )
22+
23+ response = client .get ('/search/' )
24+
25+ assert future_event .get_absolute_url () in response .content
26+ assert past_event .get_absolute_url () not in response .content
27+
28+ map (lambda x : x .delete (), [future_event , past_event ])
29+
30+
31+ def test_search_show_past_events (db , client ):
32+ future_event = ApprovedEventFactory .create ()
33+ past_event = PastEventFactory .create (status = 'APPROVED' )
34+
35+ response = client .get ('/search/?past=yes' )
36+
37+ assert future_event .get_absolute_url () in response .content
38+ assert past_event .get_absolute_url () in response .content
39+
40+ map (lambda x : x .delete (), [future_event , past_event ])
41+
42+
43+ def test_search_events_with_search_query_all_countries_multiple_results (db , client ):
44+ approved1 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" )
45+ approved2 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "AT" )
46+
47+ response = client .get (reverse ('web.search_events' ), {'q' :'arglebargle' , 'country' :'00' }, REMOTE_ADDR = '93.103.53.11' )
48+
49+ assert approved1 .get_absolute_url () in response .content
50+ assert approved2 .get_absolute_url () in response .content
51+
52+ map (lambda x : x .delete (), [approved1 , approved2 ])
53+
54+
55+ def test_search_events_with_search_query (db , client ):
56+ approved1 = ApprovedEventFactory .create (title = 'Event Arglebargle - Approved' )
57+ response = client .get (reverse ('web.search_events' ), {'q' :'arglebargle' }, REMOTE_ADDR = '93.103.53.11' )
58+
59+ assert approved1 .get_absolute_url () in response .content
60+
61+ approved1 .delete ()
62+
63+
64+
65+ def test_search_events_with_unicode_tag_in_search_query (db , client ):
66+ approved1 = ApprovedEventFactory .create (tags = [u"jabolčna čežana" ,u"José" , "Django" ])
67+ response = client .get (reverse ('web.search_events' ), {'q' :'čežana' }, REMOTE_ADDR = '93.103.53.11' )
68+
69+ assert approved1 .get_absolute_url () in response .content
70+
71+ approved1 .delete ()
72+
73+
74+ def test_search_events_with_search_query_multiple_events_current_country_only (db , client ):
75+ approved1 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" )
76+ approved2 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "AT" )
77+
78+ response = client .get (reverse ('web.search_events' ), {'q' :'arglebargle' }, REMOTE_ADDR = '93.103.53.11' )
79+
80+ assert approved1 .get_absolute_url () in response .content
81+ assert approved2 .get_absolute_url () not in response .content
82+
83+ map (lambda x : x .delete (), [approved1 , approved2 ])
84+
85+
86+ def test_search_with_audience (db , client ):
87+ approved1 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" )
88+ response = client .get (reverse ('web.search_events' ), {'audience' :1 }, REMOTE_ADDR = '93.103.53.11' )
89+
90+ assert approved1 .get_absolute_url () in response .content
91+
92+ approved1 .delete ()
93+
94+
95+ def test_search_with_audience_multiple_events (db , client ):
96+ approved1 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" ) #default audience 1
97+ approved2 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" , audience = [1 ,2 ])
98+ approved3 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "AT" , audience = [1 ,2 ])
99+ approved4 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" , audience = [3 ])
100+ response = client .get (reverse ('web.search_events' ), {'audience' :1 }, REMOTE_ADDR = '93.103.53.11' )
101+
102+ assert approved1 .get_absolute_url () in response .content
103+ assert approved2 .get_absolute_url () in response .content
104+ assert approved3 .get_absolute_url () not in response .content
105+ assert approved4 .get_absolute_url () not in response .content
106+
107+ map (lambda x : x .delete (), [approved1 , approved2 , approved3 , approved4 ])
108+
109+
110+
111+ def test_search_with_theme (db , client ):
112+ approved1 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" , theme = [2 ])
113+ response = client .get (reverse ('web.search_events' ), {'theme' :2 }, REMOTE_ADDR = '93.103.53.11' )
114+
115+ assert approved1 .get_absolute_url () in response .content
116+
117+ approved1 .delete ()
118+
119+
120+ def test_search_with_theme_multiple_events (db , client ):
121+ approved1 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" )
122+ approved2 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" , theme = [2 ])
123+ response = client .get (reverse ('web.search_events' ), {'theme' :1 }, REMOTE_ADDR = '93.103.53.11' )
124+
125+ assert approved1 .get_absolute_url () in response .content
126+ assert approved2 .get_absolute_url () not in response .content
127+
128+ map (lambda x : x .delete (), [approved1 , approved2 ])
129+
130+
131+
132+ def test_search_with_theme_multiple_events_all_countries (db , client ):
133+ approved1 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "SI" )
134+ approved2 = ApprovedEventFactory .create (title = "Event Arglebargle - Approved" , country = "AT" )
135+ response = client .get (reverse ('web.search_events' ), {'country' :'00' , 'theme' :1 }, REMOTE_ADDR = '93.103.53.11' )
136+
137+ assert approved1 .get_absolute_url () in response .content
138+ assert approved2 .get_absolute_url () in response .content
139+
140+ map (lambda x : x .delete (), [approved1 , approved2 ])
0 commit comments