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
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)
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')
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()
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()
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')
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
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']
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')
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']
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
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
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
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
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)
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
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
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]}}') "
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' "
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
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
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)
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
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 == []
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)
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']
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)
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
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' "
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)