Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Openlobby Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
openlobby
Openlobby Server
Commits
c6307403
Commit
c6307403
authored
7 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
Search of reports tests.
parent
6b2bbcdc
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
openlobby/core/search.py
+4
-4
4 additions, 4 deletions
openlobby/core/search.py
openlobby/settings.py
+0
-1
0 additions, 1 deletion
openlobby/settings.py
tests/test_models.py
+19
-2
19 additions, 2 deletions
tests/test_models.py
tests/test_search.py
+88
-0
88 additions, 0 deletions
tests/test_search.py
with
111 additions
and
7 deletions
openlobby/core/search.py
+
4
−
4
View file @
c6307403
...
@@ -8,10 +8,10 @@ HIGHLIGHT_PARAMS = {
...
@@ -8,10 +8,10 @@ HIGHLIGHT_PARAMS = {
}
}
def
query_reports
(
query
,
paginator
,
*
,
es
,
index
,
highlight
=
False
):
def
query_reports
(
query
,
paginator
,
*
,
highlight
=
False
):
fields
=
[
'
title
'
,
'
body
'
,
'
received_benefit
'
,
'
provided_benefit
'
,
fields
=
[
'
title
'
,
'
body
'
,
'
received_benefit
'
,
'
provided_benefit
'
,
'
our_participants
'
,
'
other_participants
'
]
'
our_participants
'
,
'
other_participants
'
]
s
=
ReportDoc
.
search
(
using
=
es
,
index
=
index
)
s
=
ReportDoc
.
search
()
if
query
!=
''
:
if
query
!=
''
:
s
=
s
.
query
(
'
multi_match
'
,
query
=
query
,
fields
=
fields
)
s
=
s
.
query
(
'
multi_match
'
,
query
=
query
,
fields
=
fields
)
if
highlight
:
if
highlight
:
...
@@ -21,8 +21,8 @@ def query_reports(query, paginator, *, es, index, highlight=False):
...
@@ -21,8 +21,8 @@ def query_reports(query, paginator, *, es, index, highlight=False):
return
s
.
execute
()
return
s
.
execute
()
def
reports_by_author
(
author_id
,
paginator
,
*
,
es
,
index
):
def
reports_by_author
(
author_id
,
paginator
):
s
=
ReportDoc
.
search
(
using
=
es
,
index
=
index
)
s
=
ReportDoc
.
search
()
s
=
s
.
filter
(
'
term
'
,
author_id
=
author_id
)
s
=
s
.
filter
(
'
term
'
,
author_id
=
author_id
)
s
=
s
.
sort
(
'
-published
'
)
s
=
s
.
sort
(
'
-published
'
)
s
=
s
[
paginator
.
slice_from
:
paginator
.
slice_to
]
s
=
s
[
paginator
.
slice_from
:
paginator
.
slice_to
]
...
...
This diff is collapsed.
Click to expand it.
openlobby/settings.py
+
0
−
1
View file @
c6307403
...
@@ -119,7 +119,6 @@ STATIC_URL = '/static/'
...
@@ -119,7 +119,6 @@ STATIC_URL = '/static/'
LOGGING
=
{
LOGGING
=
{
'
version
'
:
1
,
'
version
'
:
1
,
'
disable_existing_loggers
'
:
False
,
'
handlers
'
:
{
'
handlers
'
:
{
'
console
'
:
{
'
console
'
:
{
'
class
'
:
'
logging.StreamHandler
'
,
'
class
'
:
'
logging.StreamHandler
'
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_models.py
+
19
−
2
View file @
c6307403
...
@@ -8,7 +8,7 @@ from openlobby.core.documents import ReportDoc
...
@@ -8,7 +8,7 @@ from openlobby.core.documents import ReportDoc
pytestmark
=
[
pytest
.
mark
.
django_db
,
pytest
.
mark
.
usefixtures
(
'
django_es
'
)]
pytestmark
=
[
pytest
.
mark
.
django_db
,
pytest
.
mark
.
usefixtures
(
'
django_es
'
)]
def
test_report_marks_user_as_author_on_save
():
def
test_report_
_
marks_user_as_author_on_save
():
author
=
User
.
objects
.
create
(
id
=
1
,
is_author
=
False
)
author
=
User
.
objects
.
create
(
id
=
1
,
is_author
=
False
)
date
=
arrow
.
get
(
2018
,
1
,
1
).
datetime
date
=
arrow
.
get
(
2018
,
1
,
1
).
datetime
Report
.
objects
.
create
(
author
=
author
,
date
=
date
,
body
=
'
Lorem ipsum.
'
)
Report
.
objects
.
create
(
author
=
author
,
date
=
date
,
body
=
'
Lorem ipsum.
'
)
...
@@ -16,7 +16,7 @@ def test_report_marks_user_as_author_on_save():
...
@@ -16,7 +16,7 @@ def test_report_marks_user_as_author_on_save():
assert
user
.
is_author
assert
user
.
is_author
def
test_report_is_saved_in_elasticsearch
():
def
test_report_
_
is_saved_in_elasticsearch
():
author
=
User
.
objects
.
create
(
id
=
6
)
author
=
User
.
objects
.
create
(
id
=
6
)
date
=
arrow
.
get
(
2018
,
1
,
1
).
datetime
date
=
arrow
.
get
(
2018
,
1
,
1
).
datetime
published
=
arrow
.
get
(
2018
,
1
,
2
).
datetime
published
=
arrow
.
get
(
2018
,
1
,
2
).
datetime
...
@@ -47,3 +47,20 @@ def test_report_is_saved_in_elasticsearch():
...
@@ -47,3 +47,20 @@ def test_report_is_saved_in_elasticsearch():
assert
doc
.
our_participants
==
'
me
'
assert
doc
.
our_participants
==
'
me
'
assert
doc
.
other_participants
==
'
them
'
assert
doc
.
other_participants
==
'
them
'
assert
doc
.
extra
==
{
'
a
'
:
3
}
assert
doc
.
extra
==
{
'
a
'
:
3
}
def
test_report__save_works_with_no_extra
():
author
=
User
.
objects
.
create
(
id
=
6
)
date
=
arrow
.
get
(
2018
,
1
,
1
).
datetime
Report
.
objects
.
create
(
id
=
7
,
author
=
author
,
date
=
date
,
published
=
date
,
body
=
'
Lorem ipsum.
'
,
)
docs
=
list
(
ReportDoc
.
search
())
assert
len
(
docs
)
==
1
doc
=
docs
[
0
]
assert
doc
.
meta
.
id
==
'
7
'
assert
doc
.
extra
is
None
This diff is collapsed.
Click to expand it.
tests/test_search.py
0 → 100644
+
88
−
0
View file @
c6307403
import
pytest
import
arrow
from
openlobby.core.api.paginator
import
Paginator
,
encode_cursor
from
openlobby.core.models
import
Report
,
User
from
openlobby.core.search
import
query_reports
pytestmark
=
[
pytest
.
mark
.
django_db
,
pytest
.
mark
.
usefixtures
(
'
django_es
'
)]
reports
=
[
{
'
id
'
:
1
,
'
date
'
:
arrow
.
get
(
2018
,
1
,
1
).
datetime
,
'
published
'
:
arrow
.
get
(
2018
,
1
,
2
).
datetime
,
'
title
'
:
'
The Fellowship of the Ring
'
,
'
body
'
:
'
Long story short: we got the Ring!
'
,
'
received_benefit
'
:
'
The Ring
'
,
'
provided_benefit
'
:
''
,
'
our_participants
'
:
'
Frodo, Gandalf
'
,
'
other_participants
'
:
'
Saruman
'
,
},
{
'
id
'
:
2
,
'
date
'
:
arrow
.
get
(
2018
,
1
,
5
).
datetime
,
'
published
'
:
arrow
.
get
(
2018
,
1
,
10
).
datetime
,
'
title
'
:
'
The Two Towers
'
,
'
body
'
:
'
Another long story.
'
,
'
received_benefit
'
:
'
Mithrill Jacket
'
,
'
provided_benefit
'
:
''
,
'
our_participants
'
:
'
Frodo, Gimli, Legolas
'
,
'
other_participants
'
:
'
Saruman, Sauron
'
,
},
{
'
id
'
:
3
,
'
date
'
:
arrow
.
get
(
2018
,
1
,
7
).
datetime
,
'
published
'
:
arrow
.
get
(
2018
,
1
,
8
).
datetime
,
'
title
'
:
'
The Return of the King
'
,
'
body
'
:
'
Aragorn is the King. And we have lost the Ring.
'
,
'
received_benefit
'
:
''
,
'
provided_benefit
'
:
'
The Ring
'
,
'
our_participants
'
:
'
Aragorn
'
,
'
other_participants
'
:
'
Sauron
'
,
},
]
def
prepare_data
():
author
=
User
.
objects
.
create
(
id
=
1
,
username
=
'
Wolf
'
,
openid_uid
=
'
Wolf
'
,
first_name
=
'
Winston
'
,
last_name
=
'
Wolfe
'
)
for
report
in
reports
:
Report
.
objects
.
create
(
author
=
author
,
**
report
)
@pytest.mark.parametrize
(
'
query, expected_ids
'
,
[
(
''
,
[
2
,
3
,
1
]),
(
'
sauron
'
,
[
2
,
3
]),
(
'
towers
'
,
[
2
]),
(
'
Aragorn Gandalf
'
,
[
3
,
1
]),
])
def
test_query_reports
(
query
,
expected_ids
):
prepare_data
()
paginator
=
Paginator
()
response
=
query_reports
(
query
,
paginator
)
assert
expected_ids
==
[
int
(
r
.
meta
.
id
)
for
r
in
response
]
def
test_query_reports__highlight
():
prepare_data
()
paginator
=
Paginator
()
query
=
'
King
'
response
=
query_reports
(
query
,
paginator
,
highlight
=
True
)
doc
=
response
.
hits
[
0
]
assert
'
<mark>King</mark>
'
in
doc
.
meta
.
highlight
.
title
[
0
]
assert
'
<mark>King</mark>
'
in
doc
.
meta
.
highlight
.
body
[
0
]
@pytest.mark.parametrize
(
'
first, after, expected_ids
'
,
[
(
2
,
None
,
[
2
,
3
]),
(
2
,
encode_cursor
(
1
),
[
3
,
1
]),
])
def
test_query_reports__pagination
(
first
,
after
,
expected_ids
):
prepare_data
()
query
=
''
paginator
=
Paginator
(
first
=
first
,
after
=
after
)
response
=
query_reports
(
query
,
paginator
)
assert
expected_ids
==
[
int
(
r
.
meta
.
id
)
for
r
in
response
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment