def test_listing(self): query = {'match_all': {}} results = [{ '_id': 22, '_somethingelse': 5, 'fields': { 'effective_on': '2005-05-05' } }, { '_id': 9, '_somethingelse': 'blue', 'fields': {} }] with self.expect_search('notice', query, results): entries = ESNotices().listing() self.assertEqual([{ 'document_number': 22, 'effective_on': '2005-05-05' }, { 'document_number': 9 }], entries) query = {'match': {'cfr_parts': '876'}} with self.expect_search('notice', query, results): ESNotices().listing('876')
class SplitterNotices(object): """Implementation of Django+Elastic Search as notices backend""" def __init__(self): self.dm = DMNotices() self.es = ESNotices() self.get = self.dm.get self.listing = self.dm.listing def put(self, doc_number, part, notice): """Write to both""" self.dm.put(doc_number, part, notice) self.es.put(doc_number, notice)
def test_insert(self): with self.expect_insert('notice', 'docdoc') as insert: ESNotices().insert('docdoc', {"some": "structure"}) self.assertEqual(insert.call_args[0][2], {"some": "structure"})
def test_get_success(self): with self.expect_get('notice', 'docdoc', {'some': 'body'}): self.assertEqual(ESNotices().get('docdoc'), {"some": 'body'})
def test_get_404(self): with self.expect_get('notice', 'docdoc'): self.assertIsNone(ESNotices().get('docdoc'))
def __init__(self): self.dm = DMNotices() self.es = ESNotices() self.get = self.dm.get self.listing = self.dm.listing