def test_mocked_merge_error(m): datadir = tempfile.mkdtemp() setdatadir(datadir) mock_oauth(m) mock_login(m) # test bigger part of merge flow but don't check output m.post(url='https://fake-host.salesforce.com/services/Soap/c/37.0', text=MERGE_HTTP_FAULT_RESP, status_code=201) with open(os.path.join(datadir, 'mergedata.csv'), 'w') as mergedata_f: csv_writer = CsvWriter(mergedata_f, False) csv_writer.write_csv([BULK_DATA_IN.fields]) csv_writer.write_csv(BULK_DATA_IN.rows) config_filename = 'test-config.ini' endpoint_names = {'dst': 'test', 'src': 'test'} with open(config_filename) as config_f: with open('tests/sql/merge.sql') as job_f: try: run_job_from_file(config_f, job_f, endpoint_names, {}, False, False) # expected to fail assert (0) except SoapException: pass
def test_empty_query_res(mock_docall, m): # mock setup mock_oauth(m) mock_login(m) sf_bulk_connector.JOB_CHECK_TIMER = 0 mockers.mock_empty_query_res(mock_docall, m) setdatadir(tempfile.mkdtemp()) with open(config_file) as conf_file: with open('tests/sql/empty_query_res.sql') as job_file: run_job_from_file(conf_file, job_file, {'src':'test', 'dst':'test'}, {}, None, None)
def test_merge_bad_ascii_error(m): mock_oauth(m) mock_login(m) setdatadir(tempfile.mkdtemp()) with open(config_file) as conf_file: with open('tests/sql/merge_bad_ascii.sql') as job_file: try: run_job_from_file(conf_file, job_file, {'src':'test', 'dst':'test'}, {}, None, None) # it should fail assert(0) except UnicodeEncodeError: pass
def test_merge_required_columns_error(m): mock_oauth(m) mock_login(m) setdatadir(tempfile.mkdtemp()) with open(config_file) as conf_file: with open('tests/sql/merge_required_columns_error.sql') as job_file: try: run_job_from_file(conf_file, job_file, {'src':'test', 'dst':'test'}, {}, None, None) # it should fail assert(0) except SystemExit: pass
def test_upsert_unsupported(m): mock_oauth(m) mock_login(m) setdatadir(tempfile.mkdtemp()) with open(config_file) as conf_file: with open('tests/sql/upsert_unsupported.sql') as job_file: try: run_job_from_file(conf_file, job_file, {'src':'test', 'dst':'test'}, {}, None, None) # it should fail assert(0) except SystemExit: pass
def test_delete_syntax(m): # this delete operation should fail anyway but improves coverage mock_oauth(m) mock_login(m) setdatadir(tempfile.mkdtemp()) with open(config_file) as conf_file: with open('tests/sql/delete_fake.sql') as job_file: try: run_job_from_file(conf_file, job_file, {'src':'test', 'dst':'test'}, {}, None, None) # it should fail assert(0) except: pass
def fast_merge_mock(m, response_list): datadir = tempfile.mkdtemp() setdatadir(datadir) mock_oauth(m) mock_login(m) # test smaller part of merge flow but checking output # Also test how merge splits payload to sequence of chunks loginit(STDERR) fake_bulk_connector = mock.Mock() m.register_uri(method='POST', url='https://fake-localhost/services/Soap/c/37.0', response_list=response_list) sm = SfSoapMergeWrapper(fake_bulk_connector, 'Account', BULK_DATA_IN, 2) sm.sf_bulk_connector.bulk.sessionid = 'fake-sessionid' sm.sf_bulk_connector.instance_url = 'https://fake-localhost' res = sm.validate() assert res != None print res bulk_data = sm.run_merge() print bulk_data assert BULK_DATA_OUT == bulk_data