def test_apikeyuser_without_info():
    # Creates an empty object from the ENV variable with a value only for the api_key property
    aku = APIKeyUser()
    check_apikeyuser_types(aku)
    assert aku.api_key == FACTIVA_APIKEY
    assert len(aku.account_name) == 0
    assert len(aku.active_products) == 0
def test_user_with_parameter_and_info():
    # API Key is passed as a string and request_info=True
    aku = APIKeyUser(api_key=FACTIVA_APIKEY, request_info=True)
    check_apikeyuser_types(aku)
    assert aku.api_key == FACTIVA_APIKEY
    assert len(aku.account_name) > 0
    assert len(aku.active_products) > 0
Пример #3
0
 def __init__(self, api_user=None, request_userinfo=False):
     """Initialize Bulk news job class."""
     self.job_id = ''
     self.job_state = ''
     self.submitted_datetime = datetime.now()
     self.link = ''
     self.api_user = APIKeyUser.create_api_user(api_user, request_userinfo)
def test_apikeyuser_with_request_info():
    # 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 == FACTIVA_APIKEY
    assert len(aku.account_name) > 0
    assert len(aku.active_products) > 0
Пример #5
0
 def __init__(self, api_user=None, request_userinfo=False):
     if api_user is None:
         try:
             self.api_user = APIKeyUser(request_info=request_userinfo)
         except Exception:
             raise RuntimeError(
                 "User cannot be obtained from ENV variables")
     elif type(api_user) == str:
         try:
             self.api_user = APIKeyUser(api_user,
                                        request_info=request_userinfo)
         except Exception:
             raise RuntimeError(
                 "User cannot be obtained from the provided key.")
     elif type(api_user) == APIKeyUser:
         self.api_user = api_user
     else:
         raise RuntimeError("Unexpected api_user value")
def check_apikeyuser_types(aku):
    aku = APIKeyUser(request_info=True)
    assert type(aku.api_key) == str
    assert type(aku.account_name) == str
    assert type(aku.active_products) == str
    assert type(aku.max_allowed_concurrent_extractions) == int
    assert type(aku.max_allowed_extracted_documents) == int
    assert type(aku.max_allowed_extractions) == int
    assert type(aku.remaining_documents) == int
    assert type(aku.remaining_extractions) == int
    assert type(aku.total_downloaded_bytes) == int
    assert type(aku.total_extracted_documents) == int
    assert type(aku.total_extractions) == int
    assert type(aku.total_stream_subscriptions) == int
    assert type(aku.total_stream_topics) == int
    assert type(aku.enabled_company_identifiers) == list
def test_user_with_parameter_without_info():
    aku = APIKeyUser(DUMMY_KEY)
    check_apikeyuser_types(aku)
    assert aku.api_key == DUMMY_KEY
    assert aku.account_name == ''
    assert aku.active_products == ''
def test_invald_lenght_key():
    # Attempts to create an object with malformed keys. This requires assert the raised exception.
    with pytest.raises(ValueError, match=r'Factiva API-Key has the wrong length'):
        aku = APIKeyUser('abc')
def test_invalid_key():
    # Creates an object from the provided string and request the usage details to the API service
    # The key is invalid and this should validate how the error is processed
    with pytest.raises(ValueError, match=r'Factiva API-Key does not exist or inactive.'):
        aku = APIKeyUser(DUMMY_KEY, request_info=True)
Пример #10
0
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
        }
    }


def test_create_snapshot_str_key():
    s = Snapshot(query=VALID_WHERE_STATEMENT, api_user=VALID_USER_KEY)
    assert type(aku_obj.account_name) == str
    assert type(aku_obj.active_products) == str
    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)
Пример #12
0
 def test_create_user_with_env_key(self):
     aku = APIKeyUser(request_info=True)
     self.assertEqual(aku.api_key, FACTIVA_APIKEY)
Пример #13
0
 def test_create_user_with_invalid_key(self):
     with self.assertRaises(ValueError):
         APIKeyUser(api_key='aabbcc')
Пример #14
0
 def test_create_user_with_key_dummy(self):
     aku = APIKeyUser(api_key=DUMMY_KEY)
     self.assertNotEqual(aku.api_key, FACTIVA_APIKEY)
Пример #15
0
 def __init__(self, api_user=None, request_userinfo=False):
     """Class initializer."""
     self.api_user = APIKeyUser.create_api_user(api_user, request_userinfo)
     self.categories = self.get_categories()
Пример #16
0
 def __init__(self, api_user=None, request_userinfo=False):
     """Initialize class constructor."""
     self.api_user = APIKeyUser.create_api_user(api_user, request_userinfo)