Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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')
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
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')
Exemplo n.º 8
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
Exemplo n.º 9
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)
Exemplo n.º 10
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()
Exemplo n.º 11
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']
Exemplo n.º 12
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')
Exemplo n.º 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']
Exemplo n.º 14
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
Exemplo n.º 15
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
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
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)
Exemplo n.º 19
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
Exemplo n.º 20
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
Exemplo n.º 21
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']
Exemplo n.º 22
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')
Exemplo n.º 23
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]}}') "
Exemplo n.º 24
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' "
Exemplo n.º 25
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']
Exemplo n.º 26
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
Exemplo n.º 27
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
Exemplo n.º 28
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)
Exemplo n.º 29
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
Exemplo n.º 30
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 == []
Exemplo n.º 31
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 == []
Exemplo n.º 32
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)
Exemplo n.º 33
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
Exemplo n.º 34
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']
Exemplo n.º 35
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)
Exemplo n.º 36
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
Exemplo n.º 37
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']
Exemplo n.º 38
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
Exemplo n.º 39
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
Exemplo n.º 40
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
Exemplo n.º 41
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' "
Exemplo n.º 42
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)