Exemple #1
0
    def __init__(
        self,
        api_key=None,
        request_info=False
    ):
        if api_key is None:
            try:
                api_key = load_environment_value('FACTIVA_APIKEY')
            except Exception:
                raise ValueError('Factiva API-Key not provided and environment variable FACTIVA_APIKEY not set.')

        if len(api_key) != 32:
            raise ValueError('Factiva API-Key has the wrong length')

        self.api_key = api_key

        if request_info is True:
            self.get_info()
        else:
            self.account_name = ''
            self.account_type = ''
            self.active_products = ''
            self.max_allowed_concurrent_extractions = 0
            self.max_allowed_extracted_documents = 0
            self.max_allowed_extractions = 0
            self.total_downloaded_bytes = 0
            self.total_extracted_documents = 0
            self.total_extractions = 0
            self.total_stream_subscriptions = 0
            self.total_stream_topics = 0
    def __init__(self, stream_id=None, id=None, subscription_type=None):
        """Instantiate listener class constructor."""
        if not stream_id:
            try:
                stream_id = helper.load_environment_value('FACTIVA_STREAM_SUBSCRIPTION_ID')
            except Exception:
                raise const.UNDEFINED_STREAM_ID_ERROR

        self.url = f'{const.API_HOST}{const.API_STREAMS_BASEPATH}'
        self.stream_id = stream_id
        # pylint: disable=invalid-name
        self.id = id
        self.subscription_type = subscription_type
Exemple #3
0
    def __init__(self, subscription_id=None, stream_user=None):
        """Instantiate listener class constructor."""
        if not subscription_id:
            try:
                subscription_id = helper.load_environment_value(
                    'FACTIVA_STREAM_SUBSCRIPTION_ID')
            except Exception:
                raise const.UNDEFINED_SUBSCRIPTION_ERROR

        if not stream_user:
            raise ValueError('Undefined stream_user')

        self.stream_user = stream_user
        self.subscription_id = subscription_id
        self.is_consuming = True
        self.limit_msg = None
from factiva.core import const
from factiva.helper import load_environment_value
from factiva.news.snapshot.jobs import UpdateJob
from factiva.news.snapshot import Snapshot

VALID_SNAPSHOT_ID = load_environment_value('FACTIVA_SNAPSHOTID')
# Fill out this data
VALID_UPDATE_ID = load_environment_value('FACTIVA_SNAPSHOT_UPDATEID')

# Uncomment to test. Snapshot Updates can only be processed once every
# 24 hours
# def test_update_creation():
#     test_snapshot = Snapshot(snapshot_id=VALID_SNAPSHOT_ID) 
#     test_snapshot.process_update(update_type='replacements')
#     assert len(test_snapshot.last_update_job.files) > 0

def test_update_creation():
    test_update = UpdateJob(update_id=VALID_UPDATE_ID)
    test_update.get_job_results()
    assert len(test_update.files) > 0
    assert len(test_update.job_id) > 0
    assert test_update.job_state == const.API_JOB_DONE_STATE
import pytest
from factiva.core import APIKeyUser
from factiva.helper import load_environment_value

FACTIVA_APIKEY = load_environment_value("FACTIVA_APIKEY")
DUMMY_KEY = 'abcd1234abcd1234abcd1234abcd1234'

# API Response sample with the most complete set of attributes
# {
#     "data": {
#         "id": "abcd1234abcd1234abcd1234abcd1234",
#         "attributes": {
#             "cnt_curr_ext": 1,
#             "current_downloaded_amount": 427567508,
#             "max_allowed_concurrent_extracts": 10,
#             "max_allowed_document_extracts": 2500000,
#             "max_allowed_extracts": 5,
#             "name": "Company Corp",
#             "products": "DNA",
#             "tot_document_extracts": 1595383,
#             "tot_extracts": 4,
#             "tot_subscriptions": 0,
#             "tot_topics": 0,
#             "licensed_company_ids": [
#                 4,
#                 3,
#                 1,
#                 5
#             ],
#             "enabled_company_identifiers": [
#                 {
Exemple #6
0
import pytest

from factiva.core import APIKeyUser, const
from factiva.helper import load_environment_value
from factiva.news.snapshot import Snapshot, SnapshotQuery

# [MB] This file needs to test mainly constructor outputs. Specific
# operations are tested in separate files.

# TEST DATA. Fill out these values with valid data
# Environment values are loaded for automated testing.
ENVIRONMENT_USER_KEY = load_environment_value('FACTIVA_APIKEY')
VALID_USER_KEY = load_environment_value('FACTIVA_APIKEY')
VALID_SNAPSHOT_ID = load_environment_value('FACTIVA_SNAPSHOTID')
VALID_WHERE_STATEMENT = "publication_datetime >= '2021-01-01'"

# Dummy key to test data flow without making requests to API
aku = APIKeyUser(VALID_USER_KEY)


# USER-CENTRIC tests
def test_create_snapshot_evironment_variable():
    s = Snapshot(query=VALID_WHERE_STATEMENT)
    assert s.api_user.api_key == ENVIRONMENT_USER_KEY
    assert s.query.get_base_query() == {
        'query': {
            'where': VALID_WHERE_STATEMENT
        }
    }

    assert type(aku_obj.max_allowed_concurrent_extractions) == int
    assert type(aku_obj.max_allowed_extracted_documents) == int
    assert type(aku_obj.max_allowed_extractions) == int
    assert type(aku_obj.remaining_documents) == int
    assert type(aku_obj.remaining_extractions) == int
    assert type(aku_obj.total_downloaded_bytes) == int
    assert type(aku_obj.total_extracted_documents) == int
    assert type(aku_obj.total_extractions) == int
    assert type(aku_obj.total_stream_subscriptions) == int
    assert type(aku_obj.total_stream_topics) == int


# Creates the object using the ENV variable and request the usage details to the API service
aku = APIKeyUser(request_info=True)
check_apikeyuser_types(aku)
assert aku.api_key == load_environment_value("FACTIVA_APIKEY")
assert aku.account_name != ''
assert aku.active_products != ''

# Creates an empty object from the ENV variablt with a value only for the api_key property
aku = APIKeyUser()
check_apikeyuser_types(aku)
assert aku.api_key == load_environment_value("FACTIVA_APIKEY")
assert aku.account_name == ''
assert aku.active_products == ''

# Creates an empty object from the provided string with a value only for the api_key property
aku = APIKeyUser('abcd1234abcd1234abcd1234abcd1234')
check_apikeyuser_types(aku)
assert aku.api_key == 'abcd1234abcd1234abcd1234abcd1234'
assert aku.account_name == ''