def test_writebulkjob(mock_dump):
    """ ensure job def calls json.dump """
    bulk = Bulk(test=True)
    bulk.job = JOB_EXPORTS_CONTACTS
    mock_dump.return_value = None
    bulk.write_job('/tmp/pyeloqua_test_bulk_write.json')
    assert mock_dump.called
Пример #2
0
def test_start_sync_export_nodef(mock_post):
    """ except when no job_def """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_post.return_value = Mock(ok=True, status_code=200)
    mock_post.return_value.json.return_value = deepcopy(SYNC_RESPONSE)
    bulk.start_sync()
Пример #3
0
def test_option_add_all():
    """ add several random options """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.add_options(identifierFieldName='C_EmailAddress',
                     areSystemTimestampsInUTC=True)
    assert len(bulk.job['options']) == 2
Пример #4
0
def test_writebulkjob(mock_dump):
    """ ensure job def calls json.dump """
    bulk = Bulk(test=True)
    bulk.job = JOB_EXPORTS_CONTACTS
    mock_dump.return_value = None
    bulk.write_job('/tmp/pyeloqua_test_bulk_write.json')
    assert mock_dump.called
Пример #5
0
def test_event_lnk_cntct_fields(mock_get):
    """ add some linked contact fields to event """
    bulk = Bulk(test=True)
    bulk.exports('events', 1)
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_FIELDS)
    bulk.add_linked_fields('contacts', ['C_EmailAddress', 'C_FirstName'])
    assert bulk.job['fields'] == LINKED_EVENT_CONTACT_FIELDS
Пример #6
0
def test_cntct_lnk_acct_fields(mock_get):
    """ add some linked account fields """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_FIELDS_ACCOUNT)
    bulk.add_linked_fields('accounts', ['M_CompanyName', 'M_Country'])
    assert bulk.job['fields'] == LINKED_ACCOUNT_FIELDS
Пример #7
0
def test_accnt_system_fields_set(mock_get):
    """ add some account system fields """
    bulk = Bulk(test=True)
    bulk.exports('accounts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_FIELDS)
    bulk.add_fields(['accountID', 'createdAt'])
    assert len(bulk.job['fields']) == 2
Пример #8
0
def test_add_fields_notfound(mock_get):
    """ raise exception when field not found """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_FIELDS)
    fields = ['C_EmailAddress', 'C_FirstName', 'C_LastName']
    bulk.add_fields(fields)
Пример #9
0
def test_get_fields_specify(mock_get):
    """ specify elq_object to return fields for """
    bulk = Bulk(test=True)
    bulk.exports('accounts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_FIELDS)
    fields = bulk.get_fields(elq_object='contacts')
    assert fields == ALL_CONTACT_FIELDS
Пример #10
0
def test_get_fields_cntcts_return(mock_get):
    """ find all contact fields - return correct items """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_FIELDS)
    fields = bulk.get_fields()
    assert fields == ALL_CONTACT_FIELDS
Пример #11
0
def test_create_imports_error(mock_post):
    """ raise exception on bad import def """
    bulk = Bulk(test=True)
    bulk.job = JOB_IMPORTS_CONTACTS_BAD
    mock_post.return_value = Mock(ok=True, status_code=400)
    mock_post.return_value.json.return_value = deepcopy(
        IMPORT_JOB_RESPONSE_BAD)
    bulk.create_def('test name')
Пример #12
0
def test_setup_actvty():
    """ setup sets obj_id """
    bulk = Bulk(test=True)
    bulk._setup_(
        'imports',
        'activities',  # pylint: disable=W0212
        act_type='EmailOpen')
    assert bulk.job['act_type'] == 'EmailOpen'
Пример #13
0
def test_get_export_data_rt(mock_data):
    """ get data from a synced export - return data """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_data.return_value = RETURN_DATA['items']
    data = bulk.get_export_data()
    assert data == RETURN_DATA['items']
Пример #14
0
def test_get_sync_rejects_rt(mock_data):
    """ get logs from a sync - return data """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_sync = SYNC_RESPONSE_SUCCESS
    mock_data.return_value = RETURN_SYNC_REJECTS['items']
    data = bulk.get_sync_rejects()
    assert data == RETURN_SYNC_REJECTS['items']
Пример #15
0
def test_create_imports_error(mock_post):
    """ raise exception on bad import def """
    bulk = Bulk(test=True)
    bulk.job = JOB_IMPORTS_CONTACTS_BAD
    mock_post.return_value = Mock(ok=True, status_code=400)
    mock_post.return_value.json.return_value = deepcopy(
        IMPORT_JOB_RESPONSE_BAD)
    bulk.create_def('test name')
Пример #16
0
def test_create_imports_setdef(mock_post):
    """ set job_def for create import """
    bulk = Bulk(test=True)
    bulk.job = JOB_IMPORTS_CONTACTS
    mock_post.return_value = Mock(ok=True, status_code=201)
    mock_post.return_value.json.return_value = deepcopy(IMPORT_JOB_RESPONSE)
    bulk.create_def('test name')
    assert bulk.job_def == IMPORT_JOB_RESPONSE
Пример #17
0
def test_create_imports_setdef(mock_post):
    """ set job_def for create import """
    bulk = Bulk(test=True)
    bulk.job = JOB_IMPORTS_CONTACTS
    mock_post.return_value = Mock(ok=True, status_code=201)
    mock_post.return_value.json.return_value = deepcopy(IMPORT_JOB_RESPONSE)
    bulk.create_def('test name')
    assert bulk.job_def == IMPORT_JOB_RESPONSE
Пример #18
0
def test_get_data_nodata(mock_get):
    """ get data from an endpoint - no results data """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(RETURN_NORESULTS)
    return_data = bulk.get_data(endpoint='/dummyurl')
    assert return_data == []
Пример #19
0
def test_get_data_return(mock_get):
    """ get data from an endpoint - return data """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(RETURN_DATA)
    return_data = bulk.get_data(endpoint='/dummyurl')
    assert return_data == RETURN_DATA['items']
Пример #20
0
def test_check_sync_notfinished(mock_get):
    """ check on status of 'active' sync - return False """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_sync = SYNC_RESPONSE
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = SYNC_RESPONSE_ACTIVE
    status = bulk.check_sync()
    assert status is False
Пример #21
0
def test_asset_exists_list_id_call(mock_get):
    """ add exists filter - Shared List by ID, api call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_LIST_ID)
    bulk.asset_exists(asset='lists', asset_id=1)
    mock_get.assert_called_with(url=bulk.bulk_base + '/contacts/lists/1',
                                auth=bulk.auth)
Пример #22
0
def test_filter_date_end(mock_get):
    """ add field filter by ending date """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_CONTACT_FIELDS)
    bulk.filter_date(field='createdAt', end='2017-01-01 00:00:00')
    assert bulk.job['filters'][
        0] == " '{{Contact.CreatedAt}}' <= '2017-01-01 00:00:00' "
Пример #23
0
def test_leadscore_fields_name_call(mock_get):
    """ lead score model by model name api call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(LEADSCORE_MODEL_NAME)
    bulk.add_leadscore_fields(name='Model 1')
    mock_get.assert_called_with(url=bulk.bulk_base + '/contacts/scoring/models?q="name=Model*1"',
                                auth=bulk.auth)
Пример #24
0
def test_check_sync_error(mock_get):
    """ check on status of 'error' sync - return True """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_sync = SYNC_RESPONSE
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = SYNC_RESPONSE_ERROR
    status = bulk.check_sync()
    assert status is True
Пример #25
0
def test_leadscore_fields_id_call(mock_get):
    """ lead score model by model id api call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(LEADSCORE_MODEL_ID)
    bulk.add_leadscore_fields(model_id=1)
    mock_get.assert_called_with(url=bulk.bulk_base + '/contacts/scoring/models/1',
                                auth=bulk.auth)
Пример #26
0
def test_add_fields_display(mock_get):
    """ add contact fields to object by Display Name """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_FIELDS)
    fields = ['Email Address', 'First Name']
    bulk.add_fields(fields)
    assert bulk.job['fields'] == GOOD_FIELDS['items']
Пример #27
0
def test_asset_exists_list_nm_call(mock_get):
    """ add exists filter - Shared List by Name, api call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_LIST_NAME)
    bulk.asset_exists(asset='lists', name='Test List 1')
    mock_get.assert_called_with(url=bulk.bulk_base + '/contacts/lists?q="name=Test*List*1"',
                                auth=bulk.auth)
Пример #28
0
def test_readbulkjob():
    """ import correctly sets Bulk.job """
    bulk1 = Bulk(test=True)
    bulk1.job = JOB_EXPORTS_CONTACTS
    bulk1.write_job('/tmp/pyeloqua_test_bulk_write.json')
    bulk2 = Bulk(test=True)
    bulk2.read_job('/tmp/pyeloqua_test_bulk_write.json')
    assert bulk2.job == bulk1.job
Пример #29
0
def test_create_exports_call_sgfilt(mock_post):
    """ api call for create export - single filter """
    bulk = Bulk(test=True)
    bulk.job = JOB_EXPORTS_CONTACTS_F1
    mock_post.return_value = Mock(ok=True, status_code=201)
    mock_post.return_value.json.return_value = deepcopy(EXPORT_JOB_RESPONSE)
    bulk.create_def('test name')
    url = bulk.bulk_base + '/contacts/exports'
    mock_post.assert_called_with(url=url,
                                 auth=bulk.auth,
                                 data=DATA_EXPORTS_CONTACTS_F1,
                                 headers=POST_HEADERS)
Пример #30
0
def test_create_imports_call(mock_post):
    """ api call for create import """
    bulk = Bulk(test=True)
    bulk.job = JOB_IMPORTS_CONTACTS
    mock_post.return_value = Mock(ok=True, status_code=201)
    mock_post.return_value.json.return_value = deepcopy(IMPORT_JOB_RESPONSE)
    bulk.create_def('test name')
    url = bulk.bulk_base + '/contacts/imports'
    mock_post.assert_called_with(url=url,
                                 auth=bulk.auth,
                                 data=DATA_IMPORTS_CONTACTS,
                                 headers=POST_HEADERS)
Пример #31
0
def test_post_data_except_import(mock_post):
    """ post data to an export definition """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_post.return_value = Mock(ok=True, status_code=201)
    bulk.post_data(IMPORT_TEST_DATA)
Пример #32
0
def test_get_export_data_notexp(mock_data):
    """ get data from a synced export - exception """
    bulk = Bulk(test=True)
    bulk.imports('contacts')
    bulk.job_def = IMPORT_JOB_DEF
    mock_data.return_value = RETURN_DATA['items']
    bulk.get_export_data()
Пример #33
0
def test_get_sync_rejects_call(mock_data):
    """ get logs from a sync - method call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_sync = SYNC_RESPONSE_SUCCESS
    mock_data.return_value = RETURN_SYNC_REJECTS['items']
    bulk.get_sync_rejects()
    mock_data.assert_called_with(endpoint='/syncs/1/rejects')
Пример #34
0
def test_post_data_except(mock_post):
    """ post data server error """
    bulk = Bulk(test=True)
    bulk.imports('contacts')
    bulk.job_def = IMPORT_JOB_DEF
    mock_post.return_value = Mock(ok=False, status_code=400)
    mock_post.return_value.json.return_value = {}
    bulk.post_data(IMPORT_TEST_DATA)
Пример #35
0
def test_check_sync_update(mock_get):
    """ check on status of 'active' sync - update job_sync """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_sync = SYNC_RESPONSE
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = SYNC_RESPONSE_ACTIVE
    bulk.check_sync()
    assert bulk.job_sync == SYNC_RESPONSE_ACTIVE
Пример #36
0
def test_start_sync_export_add(mock_post):
    """ start syncing an export - add to Bulk """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_post.return_value = Mock(ok=True, status_code=200)
    mock_post.return_value.json.return_value = deepcopy(SYNC_RESPONSE)
    bulk.start_sync()
    assert bulk.job_sync == SYNC_RESPONSE
Пример #37
0
def test_get_export_data_call(mock_data):
    """ get data from a synced export - method call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_data.return_value = RETURN_DATA['items']
    bulk.get_export_data()
    mock_data.assert_called_with(endpoint='/contacts/exports/1/data',
                                 max_recs=None,
                                 offset=0)
Пример #38
0
def test_run_sync_timeout(mock_get, mock_post):
    """ fcn to run a sync end-to-end until finished - timeout """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_post.return_value = Mock(ok=True, status_code=200)
    mock_post.return_value.json.return_value = deepcopy(SYNC_RESPONSE)
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = SYNC_RESPONSE_ACTIVE
    bulk.sync(sleeptime=0.03, timeout=0.01)
Пример #39
0
def test_check_sync_call(mock_get):
    """ check on status of 'active' sync - api call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_sync = SYNC_RESPONSE
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = SYNC_RESPONSE_ACTIVE
    bulk.check_sync()
    mock_get.assert_called_with(url=bulk.bulk_base + '/syncs/1',
                                auth=bulk.auth)
Пример #40
0
def test_leadscore_fields_noparams(mock_get):
    """ add fields from a lead score model by model name """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(LEADSCORE_MODEL_NAME)
    bulk.add_leadscore_fields()
Пример #41
0
def test_asset_exists_list_none(mock_get):
    """ add exists filter - exception on no params """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_LIST_NAME)
    bulk.asset_exists(asset='lists')
Пример #42
0
def test_filter_date_badstr_end(mock_get):
    """ exception when bad datetime string passed - end """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_CONTACT_FIELDS)
    bulk.filter_date(field='created', end='2017-01- 00:00:00')
Пример #43
0
def test_add_fields_actvty():
    """ add some activity fields """
    bulk = Bulk(test=True)
    bulk.exports('activities', act_type='EmailOpen')
    fields = ['ActivityId', 'AssetId']
    bulk.add_fields(fields)
    assert len(bulk.job['fields']) == 2
Пример #44
0
def test_start_sync_export_nodef(mock_post):
    """ except when no job_def """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_post.return_value = Mock(ok=True, status_code=200)
    mock_post.return_value.json.return_value = deepcopy(SYNC_RESPONSE)
    bulk.start_sync()
Пример #45
0
def test_option_add_all():
    """ add several random options """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.add_options(identifierFieldName='C_EmailAddress',
                     areSystemTimestampsInUTC=True)
    assert len(bulk.job['options']) == 2
Пример #46
0
def test_get_data_call(mock_get):
    """ get data from an endpoint - api call """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(RETURN_DATA)
    bulk.get_data(endpoint='/dummyurl')
    mock_get.assert_called_with(url=bulk.bulk_base +
                                '/dummyurl?limit=1000&offset=0',
                                auth=bulk.auth)
Пример #47
0
def test_get_sync_rejects_rt(mock_data):
    """ get logs from a sync - return data """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_sync = SYNC_RESPONSE_SUCCESS
    mock_data.return_value = RETURN_SYNC_REJECTS['items']
    data = bulk.get_sync_rejects()
    assert data == RETURN_SYNC_REJECTS['items']
Пример #48
0
def test_leadscore_fields_name(mock_get):
    """ add fields from a lead score model by model name """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(LEADSCORE_MODEL_NAME)
    bulk.add_leadscore_fields(name='Model 1')
    assert bulk.job['fields'] == LEADSCORE_MODEL_FIELDS
Пример #49
0
def test_filter_value_equal(mock_get):
    """ add field filter by value equal """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_CONTACT_FIELDS)
    bulk.filter_equal(field='contactID', value='12345')
    assert bulk.job['filters'][0] == " '{{Contact.Id}}' = '12345' "
Пример #50
0
def test_get_export_data_rt(mock_data):
    """ get data from a synced export - return data """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    bulk.job_def = EXPORT_JOB_DEF
    mock_data.return_value = RETURN_DATA['items']
    data = bulk.get_export_data()
    assert data == RETURN_DATA['items']
Пример #51
0
def test_asset_exists_list_id(mock_get):
    """ add exists filter - Shared List by ID """
    bulk = Bulk(test=True)
    bulk.exports('contacts')
    mock_get.return_value = Mock(ok=True, status_code=200)
    mock_get.return_value.json.return_value = deepcopy(GOOD_LIST_ID)
    bulk.asset_exists(asset='lists', asset_id=1)
    assert bulk.job['filters'][0] == " EXISTS('{{ContactList[1]}}') "