Exemplo n.º 1
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()
Exemplo n.º 2
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.º 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_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()
Exemplo n.º 5
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)
Exemplo n.º 6
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.º 7
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.º 8
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)
Exemplo n.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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)
Exemplo n.º 21
0
def test_run_sync_error(mock_get, mock_post):
    """ fcn to run a sync end-to-end until finished - error """
    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_ERROR
    status = bulk.sync(sleeptime=0.01)
    assert status == 'error'
Exemplo n.º 22
0
def test_run_sync_error(mock_get, mock_post):
    """ fcn to run a sync end-to-end until finished - error """
    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_ERROR
    status = bulk.sync(sleeptime=0.01)
    assert status == 'error'
Exemplo n.º 23
0
def test_post_data_call(mock_post):
    """ post data to an import definition """
    bulk = Bulk(test=True)
    bulk.imports('contacts')
    bulk.job_def = IMPORT_JOB_DEF
    mock_post.return_value = Mock(ok=True, status_code=201)
    bulk.post_data(IMPORT_TEST_DATA)
    mock_post.assert_called_with(url=bulk.bulk_base + '/contacts/imports/1/data',
                                 auth=bulk.auth,
                                 data=dumps(IMPORT_TEST_DATA, ensure_ascii=False).encode('utf8'),
                                 headers=POST_HEADERS)
Exemplo n.º 24
0
def test_post_data_call(mock_post):
    """ post data to an import definition """
    bulk = Bulk(test=True)
    bulk.imports('contacts')
    bulk.job_def = IMPORT_JOB_DEF
    mock_post.return_value = Mock(ok=True, status_code=201)
    bulk.post_data(IMPORT_TEST_DATA)
    mock_post.assert_called_with(url=bulk.bulk_base +
                                 '/contacts/imports/1/data',
                                 auth=bulk.auth,
                                 data=dumps(IMPORT_TEST_DATA,
                                            ensure_ascii=False).encode('utf8'),
                                 headers=POST_HEADERS)
Exemplo n.º 25
0
def test_start_sync_export(mock_post):
    """ start syncing an export - api call """
    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()
    mock_post.assert_called_with(url=bulk.bulk_base + '/syncs',
                                 auth=bulk.auth,
                                 data=dumps(
                                     {
                                         "syncedInstanceUri": "/contacts/exports/1"
                                     },
                                 ensure_ascii=False).encode('utf8'),
                                 headers=POST_HEADERS)
Exemplo n.º 26
0
def test_start_sync_export(mock_post):
    """ start syncing an export - api call """
    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()
    mock_post.assert_called_with(
        url=bulk.bulk_base + '/syncs',
        auth=bulk.auth,
        data=dumps({
            "syncedInstanceUri": "/contacts/exports/1"
        },
                   ensure_ascii=False).encode('utf8'),
        headers=POST_HEADERS)