-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_index_searchbox.py
63 lines (50 loc) · 3.28 KB
/
test_index_searchbox.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
from doajtest.helpers import DoajTestCase
from flask import url_for
class TestSearchBox(DoajTestCase):
def setUp(self):
super(TestSearchBox, self).setUp()
def tearDown(self):
super(TestSearchBox, self).tearDown()
def test_01_with_referrer(self):
""" Utilise the search endpoint using the ref field. We expect a redirect with the referrer to be appended """
with self.app_test.test_client() as c:
resp1 = c.post('/search?source={"query": {"query_string": {"query": "cheese", "default_operator": "AND"}}}',
data={'ref': 'homepage-box', 'origin': 'ui'})
assert resp1.status_code == 302, resp1.status_code
assert resp1.location.endswith('&ref=homepage-box')
resp2 = c.post('/search?source={"query": {"query_string": {"query": "cheese", "default_operator": "AND"}}}',
data={'ref': 'homepage-box', 'origin': 'ui'}, follow_redirects=True)
assert resp2.status_code == 200, resp2.status_code
def test_02_without_origin(self):
""" Omit the origin field when emulating the text box - this is disallowed."""
with self.app_test.test_client() as c:
resp = c.post('/search?source={"query": {"query_string": {"query": "cheese", "default_operator": "AND"}}}',
data={'ref': 'homepage-box'})
assert resp.status_code == 400, resp.status_code
pass
def test_03_without_referrer(self):
""" Omit the referrer field when emulating the text box """
with self.app_test.test_client() as c:
resp = c.post('/search?source={"query": {"query_string": {"query": "cheese", "default_operator": "AND"}}}',
data={'origin': 'ui'})
assert resp.status_code == 400, resp.status_code
pass
def test_04_legacy_search_routes(self):
with self.app_test.test_request_context():
with self.app_test.test_client() as t:
# A plain /search goes to the journal search
resp = t.get('/search')
assert resp.status_code == 301, resp.status_code
assert resp.location == url_for('doaj.journals_search'), resp.location
# A legacy /search?source=...journal... also goes to the journal search page
resp = t.get('/search?source={"query": {"bool": {"filter": {"bool": {"must": [{"term": {"_type": "journal"}}]}}}}}')
assert resp.status_code == 301, resp.status_code
assert resp.location == url_for('doaj.journals_search'), resp.location
# A legacy /search?source=...article... goes to the article search page
resp = t.get('/search?source={"query":{"bool":{"filter":{"bool":{"must":[{"term":{"_type":"article"}}]}}}}}')
assert resp.status_code == 301, resp.status_code
assert resp.location == url_for('doaj.articles_search'), resp.location
# Even if there's whitespace in the query
resp = t.get('/search?source={"query": {"bool": {"filter": {"bool": {"must": [{"term": {"_type": "article"}}]}}}}}')
assert resp.status_code == 301, resp.status_code
assert resp.location == url_for('doaj.articles_search'), resp.location