Exemplo n.º 1
0
 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')
Exemplo n.º 2
0
 def test_1280(self, cn_client_v2, caplog):
     """do_meta(): Successful system metadata download"""
     mock_get_system_metadata.add_callback('http://responses/cn')
     cli = d1_cli.impl.cli.CLI()
     cli.do_set('cn-url http://responses/cn')
     with d1_test.d1_test_case.temp_file_name() as tmp_file_path:
         cli.do_meta('test_pid_1234 {}'.format(tmp_file_path))
         with open(tmp_file_path, 'rb') as f:
             received_sysmeta_xml = f.read().decode('utf-8')
     self.sample.assert_equals(received_sysmeta_xml, 'do_meta')
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
    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')
Exemplo n.º 5
0
 def test_1280(self, cn_client_v2):
     """do_meta(): Successful system metadata download"""
     mock_get_system_metadata.add_callback('http://responses/cn')
     cli = d1_cli.impl.cli.CLI()
     cli.do_set('cn-url http://responses/cn')
     with tempfile.NamedTemporaryFile() as tmp_file:
         tmp_file_path = tmp_file.name
     pid_str = 'test_pid_1234'
     cli.do_meta('{} {}'.format(pid_str, tmp_file_path))
     with open(tmp_file_path, 'rb') as f:
         received_sysmeta_pyxb = v2.CreateFromDocument(f.read())
     client = d1_client.cnclient.CoordinatingNodeClient(
         'http://responses/cn')
     expected_sysmeta_pyxb = client.getSystemMetadata(pid_str)
     d1_common.system_metadata.is_equivalent_pyxb(received_sysmeta_pyxb,
                                                  expected_sysmeta_pyxb)
Exemplo n.º 6
0
    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.getSystemMetadata() returns expected SysMeta values"""
     mock_sysmeta.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
     sysmeta_pyxb = mn_client_v1_v2.getSystemMetadata('test_pid')
     self.sample.assert_equals(sysmeta_pyxb, 'mock_get_system_metadata',
                               mn_client_v1_v2)
 def test_1010(self, mn_client_v1_v2):
     """mock_api.getSystemMetadata(): Passing a trigger header triggers a DataONEException"""
     mock_sysmeta.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
     with pytest.raises(d1_common.types.exceptions.NotFound):
         mn_client_v1_v2.getSystemMetadata(
             'test_pid', vendorSpecific={'trigger': '404'})
 def test_1000(self, mn_client_v1_v2):
     """mock_api.getSystemMetadata() returns a System Metadata PyXB object"""
     mock_sysmeta.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
     assert isinstance(mn_client_v1_v2.getSystemMetadata('test_pid'),
                       mn_client_v1_v2.bindings.SystemMetadata)