Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
infra
spot
Commits
46e8be53
Commit
46e8be53
authored
Jan 07, 2019
by
Nicolas Gelot
Browse files
Fix unit test test_index_html
parent
4b0c4062
Changes
3
Hide whitespace changes
Inline
Side-by-side
requirements-dev.txt
View file @
46e8be53
...
...
@@ -9,3 +9,4 @@ transifex-client==0.12.2
unittest2==1.1.0
zope.testrunner==4.5.1
selenium==3.5.0
mockredispy==2.9.3
searx/search_database.py
View file @
46e8be53
...
...
@@ -32,7 +32,8 @@ class SearchData(object):
def
_get_connection
(
host
):
return
redis
.
StrictRedis
(
host
if
host
else
settings
[
'redis'
][
'host'
],
decode_responses
=
True
)
host
=
host
if
host
else
settings
[
'redis'
][
'host'
]
return
redis
.
StrictRedis
(
host
=
host
,
decode_responses
=
True
)
def
read
(
q
,
host
):
...
...
tests/unit/test_webapp.py
View file @
46e8be53
# -*- coding: utf-8 -*-
import
json
from
mock
import
Mock
from
mock
import
Mock
,
patch
from
mockredis
import
mock_strict_redis_client
from
searx
import
webapp
from
searx.testing
import
SearxTestCase
from
searx.search
import
Search
...
...
@@ -19,12 +20,14 @@ class ViewsTestCase(SearxTestCase):
{
'content'
:
'first test content'
,
'title'
:
'First Test'
,
'category'
:
'general'
,
'url'
:
'http://first.test.xyz'
,
'engines'
:
[
'youtube'
,
'startpage'
],
'engine'
:
'startpage'
,
'parsed_url'
:
ParseResult
(
scheme
=
'http'
,
netloc
=
'first.test.xyz'
,
path
=
'/'
,
params
=
''
,
query
=
''
,
fragment
=
''
),
# noqa
},
{
'content'
:
'second test content'
,
'category'
:
'general'
,
'title'
:
'Second Test'
,
'url'
:
'http://second.test.xyz'
,
'engines'
:
[
'youtube'
,
'startpage'
],
...
...
@@ -33,16 +36,16 @@ class ViewsTestCase(SearxTestCase):
},
]
def
search_mock
(
search_self
,
*
args
):
search_self
.
result_container
=
Mock
(
get_ordered_results
=
lambda
:
self
.
test_results
,
answers
=
set
(),
corrections
=
set
(),
suggestions
=
set
(),
infoboxes
=
[],
unresponsive_engines
=
set
(),
results
=
self
.
test_results
,
results_number
=
lambda
:
3
,
results_length
=
lambda
:
len
(
self
.
test_results
))
def
search_mock
(
*
args
):
return
Mock
(
get_ordered_results
=
lambda
:
self
.
test_results
,
answers
=
set
(),
corrections
=
set
(),
suggestions
=
set
(),
infoboxes
=
[],
unresponsive_engines
=
set
(),
results
=
self
.
test_results
,
results_number
=
lambda
:
3
,
results_length
=
lambda
:
len
(
self
.
test_results
))
Search
.
search
=
search_mock
...
...
@@ -60,6 +63,7 @@ class ViewsTestCase(SearxTestCase):
self
.
assertEqual
(
result
.
status_code
,
200
)
self
.
assertIn
(
b
'<div class="title"><h1>searx</h1></div>'
,
result
.
data
)
@
patch
(
'redis.StrictRedis'
,
mock_strict_redis_client
)
def
test_index_html
(
self
):
result
=
self
.
app
.
post
(
'/'
,
data
=
{
'q'
:
'test'
})
self
.
assertIn
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment