def test_1000(self, caplog): mock_object_list.add_callback(d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_log_records.add_callback(d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_get_system_metadata.add_callback( d1_test.d1_test_case.MOCK_REMOTE_BASE_URL ) mock_get.add_callback(d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): self.call_management_command( 'import', '--force', '--clear', '--debug', '--workers=1', '--page-size=9', '--major=2', d1_test.d1_test_case.MOCK_REMOTE_BASE_URL ) # The importer is multiprocessed but only log output written by the main # process is captured. It's enough to give an indication of successful run # so we leave it at that. Capturing the output from the other processes is # apparently not trivial. # # Due to the multiprocessing, the messages don't look exactly the same each # run, so we strip out the volatile parts before comparing. log_str = d1_test.d1_test_case.get_caplog_text(caplog) log_str = re.sub('Waiting to queue task\n', '', log_str) log_str = re.sub('start', '[START/COUNT]', log_str) log_str = re.sub('count', '[START/COUNT]', log_str) log_str = re.sub('(?:total_run_sec=)[\d.]*', '[SEC]', log_str) log_str = re.sub('(?:total_run_dhm=)[\ddhm"]*', '[DHM]', log_str) self.sample.assert_equals(log_str, 'bulk_import_log')
def test_1290(self, cn_client_v2): """do_list(): Successful object listing""" mock_list_objects.add_callback('http://responses/cn') cli = d1_cli.impl.cli.CLI() cli.do_set('mn-url http://responses/cn') with tempfile.NamedTemporaryFile() as tmp_file: tmp_file_path = tmp_file.name cli.do_list(tmp_file_path) with open(tmp_file_path, 'rb') as f: received_object_list_xml = f.read() client = d1_client.mnclient.MemberNodeClient('http://responses/cn') received_object_list_xml = d1_common.xml.pretty_xml( re.sub( r'<dateSysMetadataModified>.*?</dateSysMetadataModified>', '', received_object_list_xml, )) expected_object_list_xml = d1_common.xml.pretty_xml( re.sub( r'<dateSysMetadataModified>.*?</dateSysMetadataModified>', '', client.listObjects().toxml('utf-8'), )) assert d1_common.xml. \ is_equal_xml(received_object_list_xml, expected_object_list_xml)
def test_1290(self, cn_client_v2): """do_list(): Successful object listing""" mock_list_objects.add_callback('http://responses/cn') cli = d1_cli.impl.cli.CLI() cli.do_set('mn-url http://responses/cn') with d1_test.d1_test_case.temp_file_name() as tmp_file_path: cli.do_list(tmp_file_path) with open(tmp_file_path, 'rb') as f: received_object_list_xml = f.read().decode('utf-8') self.sample.assert_equals(received_object_list_xml, 'do_list')
def test_1000(self, capsys): mock_object_list.add_callback( d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_log_records.add_callback( d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_get_system_metadata.add_callback( d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_get.add_callback(d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) self.call_management_command('import', '--force', '--major=2', d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) stdout, stderr = capsys.readouterr() self.sample.assert_equals(stdout, 'import')
def test_1000(self, caplog): with caplog.at_level(logging.INFO): mock_object_list.add_callback( d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_log_records.add_callback( d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_get_system_metadata.add_callback( d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) mock_get.add_callback(d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) self.call_management_command( 'import', '--force', '--major=2', d1_test.d1_test_case.MOCK_REMOTE_BASE_URL) self.sample.assert_equals(d1_test.d1_test_case.get_caplog_text(caplog), 'import')
def test_1000(self, mn_client_v1_v2): """Object List iteration""" mock_list_objects.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) api_major = d1_client.d1client.get_version_tag_by_d1_client(mn_client_v1_v2) object_list_iter = d1_client.iter.objectlist_multi.ObjectListIteratorMulti( d1_test.d1_test_case.MOCK_MN_BASE_URL, page_size=13, max_workers=2, max_queue_size=10, api_major=api_major ) i = 0 for i, object_info_pyxb in enumerate(object_list_iter): assert isinstance(object_info_pyxb, mn_client_v1_v2.bindings.ObjectInfo) assert i == mock_list_objects.N_TOTAL - 1
def test_1000( self, page_size, n_workers, from_date, to_date, ): mock_list_objects.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL, n_total=N_TOTAL) mock_get_system_metadata.add_callback( d1_test.d1_test_case.MOCK_MN_BASE_URL) sysmeta_pyxb_list = [] # with freezegun.freeze_time('1977-07-27') as freeze_time: sysmeta_iter = d1_client.iter.sysmeta_multi.SystemMetadataIteratorMulti( d1_test.d1_test_case.MOCK_MN_BASE_URL, page_size=page_size, max_workers=n_workers, client_dict={ # 'cert_pem_path': cert_pem_path, # 'cert_key_path': cert_key_path, }, list_objects_dict=dict(fromDate=from_date, toDate=to_date), ) for sysmeta_pyxb in sysmeta_iter: # freeze_time.tick(delta=datetime.timedelta(days=1)) sysmeta_pyxb_list.append(sysmeta_pyxb) combined_sysmeta_xml = self._get_combined_xml(sysmeta_pyxb_list, N_TOTAL) self.sample.assert_equals( combined_sysmeta_xml, 'from_{}_to_{}'.format( from_date.strftime('%Y%m%d') if from_date else 'unset', to_date.strftime('%Y%m%d') if to_date else 'unset', ), )
def test_1020(self, mn_client_v1_v2): """mock_api.listObjects(): Passing a trigger header triggers a DataONEException""" mock_object_list.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) with pytest.raises(d1_common.types.exceptions.ServiceFailure): mn_client_v1_v2.listObjects(vendorSpecific={'trigger': '500'})
def test_1010(self, mn_client_v1_v2): """mock_api.listObjects() returns a populated ObjectList""" mock_object_list.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) object_list = mn_client_v1_v2.listObjects() self.sample.assert_equals(object_list, 'populated')
def test_1000(self, mn_client_v1_v2): """mock_api.listObjects() returns a DataONE ObjectList PyXB object""" mock_object_list.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL) assert isinstance(mn_client_v1_v2.listObjects(), mn_client_v1_v2.bindings.ObjectList)