[tests] flake8 on test_elastic_search

authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
changeset3cbf5bd3db0f
branchdefault
phasepublic
hiddenno
parent revision#a571130d47bf udpate elasticsearch indexes after modifying parent relation
child revision#32493f2373c1 postcommit_event instead of precommit_event
files modified by this revision
test/test_elastic_search.py
# HG changeset patch
# User Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
# Date 1485982680 -3600
# Wed Feb 01 21:58:00 2017 +0100
# Node ID 3cbf5bd3db0f739d1029d6a0e8f82bc1280db785
# Parent a571130d47bff96357979acb496ff18852e34e12
[tests] flake8 on test_elastic_search

diff --git a/test/test_elastic_search.py b/test/test_elastic_search.py
@@ -1,6 +1,5 @@
1 -# flake8: noqa
2  from __future__ import print_function
3 
4  import sys
5  import unittest
6  from io import StringIO
@@ -14,13 +13,13 @@
7  from cubicweb.cwconfig import CubicWebConfiguration
8  from cubes.elasticsearch import ccplugin
9  from cubes.elasticsearch.es import (indexable_types,
10                                      fulltext_indexable_rql)
11 
12 +
13  # TODO - find a way to configure ElasticSearch as non threaded while running tests
14  # so that the traces show the full stack, not just starting from connection.http_*
15 -
16  class ExportElasticSearchTC(testlib.AutoPopulateTest):
17      # ignore ComputedRelations
18      ignored_relations = set(
19          ('narrower_concept', 'hidden_label', 'preferred_label', 'alternative_label', ))
20 
@@ -88,11 +87,11 @@
21              sys.stdout = sys.__stdout__
22          with self.admin_access.repo_cnx() as cnx:
23              self.assert_(cnx.execute('Any X WHERE X is %(etype)s' %
24                                       {'etype': indexable_types(cnx.vreg.schema)[0]}))
25          # TODO - put this somewhere where it tests on the first get_connection
26 -        #create.assert_called_with(ignore=400,
27 +        # create.assert_called_with(ignore=400,
28          #                          index='unittest_index_name',
29          #                          body=INDEX_SETTINGS)
30          bulk.assert_called()
31          # TODO ? check called data
32 
@@ -118,32 +117,39 @@
33              entity.cw_set(title=u'Different title')
34              cnx.commit()
35              index.assert_called()
36 
37 
38 -
39  def mock_execute_150(*args, **kwargs):
40      return mock_execute(100)
41 +
42 +
43  def mock_execute_15(*args, **kwargs):
44      return mock_execute(15)
45 +
46 +
47  def mock_execute_1(*args, **kwargs):
48      return mock_execute(1)
49 +
50 +
51  def mock_execute(nb_results):
52      result = {'_source': {'description': 'test',
53                            'cwuri': 'http://example.org/123',
54                            'eid': 123,
55                            'title': 'test'},
56                '_type': 'BaseContent',
57                '_score': 1}
58 -    search = {'hits': {'hits': repeat(result,nb_results),
59 +    search = {'hits': {'hits': repeat(result, nb_results),
60                         'total': nb_results
61                         }}
62      return FacetedResponse(search, search)
63 
64 +
65  def mock_cnx(*args, **kwargs):
66      return True
67 
68 +
69  class ElasticSearchViewsTC(testlib.CubicWebTC):
70 
71      # TODO generate X tests ranging the number of results from 1 to 150
72      @patch('elasticsearch_dsl.search.Search.execute', new=mock_execute_1)
73      @patch('elasticsearch_dsl.connections.connections.get_connection', new=mock_cnx)
@@ -169,11 +175,10 @@
74 
75  class ElasticsearchTC(testlib.CubicWebTC):
76 
77      def test_1(self):
78          with self.admin_access.cnx() as cnx:
79 -            print (cnx.vreg.schema)
80              schema = cnx.vreg.schema
81              etype = 'Person'
82              rql = fulltext_indexable_rql(etype, schema)
83              self.assertIn('age', rql)
84              self.assertNotIn('eid', rql)