Exemplo n.º 1
0
def assert_story_query(db: DatabaseHandler,
                       q: str,
                       expected_story: Dict[str, Any],
                       label: str = 'test story query') -> None:
    """
    Run the given query against Solr, adding an 'and stories_id:{expected_story['stories_id']}' to make it return at
    most one story.

    Verify that the query succeeds and returns only the "expected_story".
    """
    q = decode_object_from_bytes_if_needed(q)
    expected_story = decode_object_from_bytes_if_needed(expected_story)
    label = decode_object_from_bytes_if_needed(label)

    expected_stories_id = expected_story['stories_id']

    r = query_solr(db=db,
                   params={
                       'q': f"{q} and stories_id:{expected_stories_id}",
                       'rows': 1_000_000
                   })

    docs = r.get('response', {}).get('docs', None)

    assert docs, f"No response.docs found in Solr results: {docs}"

    got_stories_ids = [_['stories_id'] for _ in docs]

    assert [expected_stories_id] == got_stories_ids, f"{label}: {q}"
Exemplo n.º 2
0
 def test_range_queries(self):
     with pytest.raises(McQuerySolrRangeQueryException,
                        message="Range queries should not be allowed"):
         query_solr(db=self.DB, params={'q': "publish_date:[foo TO bar]"})