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
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')
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)
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)
# we could get the same set of fields like this: field_set = ['Email Address', 'contactID', 'createdAt', 'First Name', 'isSubscribed', 'isBounced'] # Now add them to our job bulk.add_fields(field_set) # Add a filter which will only give us contacts in our segment (using the ID from the segment URL) bulk.asset_exists('segments', asset_id=12345) # we could also get it like this, assuming the segment name is 'My Segment': bulk.asset_exists('segments', name='My Segment') # Now we're ready to export the data bulk.create_def('my export') bulk.sync() # creates a sync which tells Eloqua to prepare the data contact_records = bulk.get_export_data() # retrieve the prepared data # Let's take a look at our data: for contact in contact_records: print(contact)