def test_index_document_without_request(solr): doc = Document(title='No request', body=u'There is no request',) doc.id = 33 add_document_handler(event=Mock(object=doc, request=None)) results = list(solr.query(title='No request')) assert len(results) == 1 assert results[0]['id'] == 'document-33' assert results[0]['path'] == '/'
def test_index_document_without_request(solr): doc = Document( title='No request', body=u'There is no request', ) doc.id = 33 add_document_handler(event=Mock(object=doc, request=None)) results = list(solr.query(title='No request')) assert len(results) == 1 assert results[0]['id'] == 'document-33' assert results[0]['path'] == '/'
def test_index_document(solr, db_session): now = datetime.now() doc = Document(title='foo', body=u'bar!', modification_date=now) doc.id = 23 # we don't really add the object yet... request = Mock(resource_path=lambda _: '/path/') add_document_handler(event=Mock(object=doc, request=request)) results = list(solr.query(title='foo')) assert len(results) == 1 assert results[0]['id'] == 'document-23' assert results[0]['path'] == '/path/' # Solr's date values don't take microseconds into account... assert abs(results[0]['modification_date'] - now) < timedelta(milliseconds=1)
def test_delete_document(solr, db_session): doc = Document(title=u'delete-me', description=u'foo!') doc.id = 3 request = Mock(resource_path=lambda _: '/path/') add_document_handler(event=Mock(object=doc, request=request)) results = list(solr.query(title='delete-me')) assert len(results) == 1 assert results[0]['id'] == 'document-3' assert results[0]['description'] == u'foo!' delete_document_handler(event=Mock(object=doc, request=request)) results = list(solr.query(title='delete-me')) assert len(results) == 0