Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
elasticsearch
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
cubes
elasticsearch
Commits
21b992410538
Commit
21b992410538
authored
8 years ago
by
Arthur Lutz
Browse files
Options
Downloads
Patches
Plain Diff
[tests] test hooks and ccplugin
parent
ac89237201a8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/data/bootstrap_cubes
+1
-1
1 addition, 1 deletion
test/data/bootstrap_cubes
test/test_elastic_search.py
+128
-0
128 additions, 0 deletions
test/test_elastic_search.py
tox.ini
+1
-0
1 addition, 0 deletions
tox.ini
with
130 additions
and
1 deletion
test/data/bootstrap_cubes
+
1
−
1
View file @
21b99241
elasticsearch
elasticsearch
,blog
This diff is collapsed.
Click to expand it.
test/test_elastic_search.py
0 → 100644
+
128
−
0
View file @
21b99241
# flake8: noqa
from
__future__
import
print_function
import
sys
import
unittest
from
io
import
StringIO
from
mock
import
patch
from
elasticsearch_dsl.result
import
Response
from
cubicweb.devtools
import
testlib
from
cubicweb.cwconfig
import
CubicWebConfiguration
from
cubes.elasticsearch
import
ccplugin
from
cubes.elasticsearch.es
import
indexable_types
,
index_settings
class
ExportElasticSearchTC
(
testlib
.
AutoPopulateTest
):
# ignore ComputedRelations
ignored_relations
=
set
(
(
'
narrower_concept
'
,
'
hidden_label
'
,
'
preferred_label
'
,
'
alternative_label
'
,
))
def
setup_database
(
self
):
super
(
ExportElasticSearchTC
,
self
).
setup_database
()
self
.
orig_config_for
=
CubicWebConfiguration
.
config_for
config_for
=
lambda
appid
:
self
.
config
# noqa
CubicWebConfiguration
.
config_for
=
staticmethod
(
config_for
)
def
to_test_etypes
(
self
):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
types
=
indexable_types
(
cnx
.
repo
)
return
types
def
tearDown
(
self
):
CubicWebConfiguration
.
config_for
=
self
.
orig_config_for
super
(
ExportElasticSearchTC
,
self
).
tearDown
()
def
test_indexable_types
(
self
):
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
self
.
assertNotEquals
(
len
(
indexable_types
(
cnx
.
repo
)),
0
)
@patch
(
'
elasticsearch.client.Elasticsearch.index
'
,
unsafe
=
True
)
@patch
(
'
elasticsearch.client.indices.IndicesClient.create
'
,
unsafe
=
True
)
def
test_ccplugin
(
self
,
create
,
index
):
self
.
auto_populate
(
10
)
index
.
reset_mock
()
cmd
=
[
self
.
appid
,
'
--dry-run
'
,
'
yes
'
]
sys
.
stdout
=
out
=
StringIO
()
try
:
ccplugin
.
IndexInES
(
None
).
main_run
(
cmd
)
finally
:
sys
.
stdout
=
sys
.
__stdout__
self
.
assertEquals
(
''
,
out
.
getvalue
())
create
.
assert_not_called
()
index
.
assert_not_called
()
cmd
=
[
self
.
appid
,
'
--dry-run
'
,
'
yes
'
,
'
--debug
'
,
'
yes
'
]
sys
.
stdout
=
out
=
StringIO
()
try
:
ccplugin
.
IndexInES
(
None
).
main_run
(
cmd
)
finally
:
sys
.
stdout
=
sys
.
__stdout__
self
.
assert_
(
'
found
'
in
out
.
getvalue
())
create
.
assert_not_called
()
index
.
assert_not_called
()
# TODO try wrong option
# cmd = [self.appid, '--wrong-option', 'yes']
cmd
=
[
self
.
appid
]
sys
.
stdout
=
StringIO
()
try
:
ccplugin
.
IndexInES
(
None
).
main_run
(
cmd
)
finally
:
sys
.
stdout
=
sys
.
__stdout__
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
self
.
assert_
(
cnx
.
execute
(
'
Any X WHERE X is %(etype)s
'
%
{
'
etype
'
:
indexable_types
(
cnx
.
repo
)[
0
]}))
create
.
assert_called_with
(
ignore
=
400
,
index
=
'
cubicweb
'
,
body
=
index_settings
())
index
.
assert_called
()
# TODO ? check called data
@patch
(
'
elasticsearch.client.Elasticsearch.index
'
,
unsafe
=
True
)
def
test_es_hooks_create
(
self
,
index
):
with
self
.
admin_access
.
cnx
()
as
cnx
:
cnx
.
create_entity
(
'
BlogEntry
'
,
title
=
u
'
Article about stuff
'
,
content
=
u
'
content herer
'
)
cnx
.
commit
()
index
.
assert_called
()
@patch
(
'
elasticsearch.client.Elasticsearch.index
'
,
unsafe
=
True
)
def
test_es_hooks_modify
(
self
,
index
):
with
self
.
admin_access
.
cnx
()
as
cnx
:
entity
=
cnx
.
create_entity
(
'
BlogEntry
'
,
title
=
u
'
Article about stuff
'
,
content
=
u
'
content herer
'
)
cnx
.
commit
()
index
.
reset_mock
()
entity
.
cw_set
(
title
=
u
'
Different title
'
)
index
.
assert_called
()
def
mock_execute
(
*
args
,
**
kwargs
):
result
=
{
'
_source
'
:
{
'
description
'
:
'
test
'
,
'
cwuri
'
:
'
http://example.org/123
'
,
'
eid
'
:
123
,
'
title
'
:
'
test
'
},
'
_type
'
:
'
BaseContent
'
,
'
_score
'
:
1
}
return
Response
({
'
hits
'
:
{
'
hits
'
:
[
result
],
'
total
'
:
1
}})
class
ElasticSearchViewsTC
(
testlib
.
CubicWebTC
):
@patch
(
'
elasticsearch_dsl.search.Search.execute
'
,
new
=
mock_execute
)
def
test_search_view
(
self
):
with
self
.
new_access
(
'
anon
'
).
web_request
()
as
req
:
# self._cw.form.get('search'))
self
.
view
(
'
esearch
'
,
req
=
req
,
template
=
None
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
tox.ini
+
1
−
0
View file @
21b99241
...
...
@@ -8,6 +8,7 @@
sitepackages
=
true
deps
=
pytest
cubicweb-blog
commands
=
{envpython}
-m
pytest
{posargs:test}
...
...
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