932986a876
this handles the piece of work we've been talking about for a while in moving the queries.yaml file into a directory with a bunch of files. These remain yaml so that they can be tagged with additional metadata. This would support the concept of soft deleting as well as other useful meta data to gauge our evolution of the bugs we track over time. This should see some real review as it's extensive enough of a change that the existing tests might not be sufficient. However it should be enough to move this forward quite a bit. This also makes future looking statements about doing soft deletes with a resolved_at keyword in the future. That implementation will come later. Change-Id: I86317fcf6f1886ab5b6c0ee154b29e71865c52b7
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import fixtures
|
|
import json
|
|
|
|
from elastic_recheck import loader
|
|
import elastic_recheck.tests
|
|
|
|
|
|
def load_empty():
|
|
with open("elastic_recheck/tests/unit/samples/no-results.json") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def load_by_bug(bug):
|
|
with open("elastic_recheck/tests/unit/samples/bug-%s.json" % bug) as f:
|
|
return json.load(f)
|
|
|
|
|
|
class FakeES(object):
|
|
"""A fake elastic search interface.
|
|
|
|
This provides a stub of the elastic search interface, so we can return
|
|
fake results based on the samples we've already collected to use for
|
|
other unit tests. It does this by buiding a reverse mapping from our
|
|
queries.yaml file, and grabbing the results we'd find for known bugs.
|
|
"""
|
|
def __init__(self, url):
|
|
self._yaml = loader.load('elastic_recheck/tests/unit/queries')
|
|
self._queries = {}
|
|
for item in self._yaml:
|
|
self._queries[item['query'].rstrip()] = item['bug']
|
|
|
|
def search(self, query, **kwargs):
|
|
qstring = query['query']['query_string']['query']
|
|
if qstring in self._queries:
|
|
return load_by_bug(self._queries[qstring])
|
|
return load_empty()
|
|
|
|
|
|
class UnitTestCase(elastic_recheck.tests.TestCase):
|
|
def setUp(self):
|
|
super(UnitTestCase, self).setUp()
|
|
|
|
self.useFixture(fixtures.MonkeyPatch('pyelasticsearch.ElasticSearch',
|
|
FakeES))
|