def test_base_query():
    query = SnapshotQuery(VALID_WHERE_STATEMENT)
    assert query.get_base_query() == {
        'query': {
            'where': VALID_WHERE_STATEMENT
        }
    }
def test_extraction_query():
    query = SnapshotQuery(VALID_WHERE_STATEMENT)
    print(query.get_extraction_query())
    assert query.get_extraction_query() == {
        'query': {
            'where': "publication_datetime >= '2021-01-01'",
            'format': 'avro'
        }
    }
def test_analytics_query():
    query = SnapshotQuery(VALID_WHERE_STATEMENT)
    assert query.get_analytics_query() == {
        'query': {
            'where': "publication_datetime >= '2021-01-01'",
            'frequency': 'MONTH',
            'date_field': 'publication_datetime',
            'group_by_source_code': False,
            'top': 10
        }
    }
Beispiel #4
0
def test_create_snapshot_query_parameter():
    q = SnapshotQuery(VALID_WHERE_STATEMENT)
    s = Snapshot(query=q)
    assert s.api_user.api_key == ENVIRONMENT_USER_KEY
    assert s.query.get_base_query() == {
        'query': {
            'where': VALID_WHERE_STATEMENT
        }
    }
Beispiel #5
0
from factiva.news.snapshot import Snapshot, SnapshotQuery

querystr = "publication_datetime >= '2018-01-01 00:00:00' AND publication_datetime <= '2018-01-10 00:00:00' AND LOWER(language_code) = 'en'"
st1 = Snapshot(query=querystr)

print(st1.query.get_explain_query())
print(st1.query.get_analytics_query())
print(st1.query.get_extract_query())

query1 = SnapshotQuery(where=querystr,
                       limit=1000,
                       file_format='avro',
                       frequency='YEAR',
                       date_field='publication_datetime',
                       group_by_source_code=True,
                       top=25)
st2 = Snapshot(query=query1)

print(st2.query.get_explain_query())
print(st2.query.get_analytics_query())
print(st2.query.get_extract_query())
def test_invalid_field():
    with pytest.raises(
            ValueError,
            match=r'Value of file_format is not within the allowed options'):
        query = SnapshotQuery(VALID_WHERE_STATEMENT, file_format='TXT')