Beispiel #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')
Beispiel #2
0
 def test_1020(self, mn_client_v1_v2):
     """mock_api.get(): Redirects"""
     mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
     direct_sciobj_bytes = mn_client_v1_v2.get('test_pid_1').content
     redirect_sciobj_bytes = mn_client_v1_v2.get(
         '<REDIRECT:303:3>test_pid_1').content
     assert direct_sciobj_bytes == redirect_sciobj_bytes
Beispiel #3
0
 def test_1170(self):
     """copy_requests_stream_to_file(): Raises InvalidArguments if path is invalid"""
     responses_base_url = 'http://mock/node'
     mock_get.add_callback(responses_base_url)
     client = d1_client.mnclient_2_0.MemberNodeClient_2_0(
         responses_base_url)
     response = client.get('test_pid_1')
     with pytest.raises(d1_cli.impl.cli_exceptions.CLIError):
         cli_util.copy_requests_stream_to_file(response, '/an/invalid/path')
Beispiel #4
0
 def test_1170(self):
   """copy_requests_stream_to_file(): Raises InvalidArguments if path is invalid"""
   mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   client = d1_client.mnclient_2_0.MemberNodeClient_2_0(
     d1_test.d1_test_case.MOCK_MN_BASE_URL
   )
   response = client.get('test_pid_1')
   with pytest.raises(d1_cli.impl.cli_exceptions.CLIError):
     cli_util.copy_requests_stream_to_file(response, '/an/invalid/path')
Beispiel #5
0
 def test_1010(self, mn_client_v1_v2):
     """mock_api.get() returns the same content each time for a given PID"""
     mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
     obj_1a_str = mn_client_v1_v2.get('test_pid_1').content
     obj_2a_str = mn_client_v1_v2.get('test_pid_2').content
     obj_1b_str = mn_client_v1_v2.get('test_pid_1').content
     obj_2b_str = mn_client_v1_v2.get('test_pid_2').content
     assert obj_1a_str == obj_1b_str
     assert obj_2a_str == obj_2b_str
Beispiel #6
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')
Beispiel #7
0
 def test_1160(self):
     """copy_requests_stream_to_file(): Copies Requests Response body to file when path is valid"""
     responses_base_url = 'http://mock/node'
     mock_get.add_callback(responses_base_url)
     client = d1_client.mnclient_2_0.MemberNodeClient_2_0(
         responses_base_url)
     response = client.get('test_pid_1')
     with tempfile.NamedTemporaryFile() as tmp_file:
         cli_util.copy_requests_stream_to_file(response, tmp_file.name)
         tmp_file.seek(0)
         got_sciobj_str = tmp_file.read()
         expected_sciobj_str = client.get('test_pid_1').content
         self.sample.assert_equals(got_sciobj_str, 'copy_stream_to_file')
         assert got_sciobj_str == expected_sciobj_str
Beispiel #8
0
 def test_1160(self):
   """copy_requests_stream_to_file(): Copies Requests Response body to file when path is valid"""
   mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   client = d1_client.mnclient_2_0.MemberNodeClient_2_0(
     d1_test.d1_test_case.MOCK_MN_BASE_URL
   )
   response = client.get('test_pid_1')
   with tempfile.NamedTemporaryFile() as tmp_file:
     cli_util.copy_requests_stream_to_file(response, tmp_file.name)
     tmp_file.seek(0)
     got_sciobj_bytes = tmp_file.read()
     expected_sciobj_bytes = client.get('test_pid_1').content
     self.sample.assert_equals(got_sciobj_bytes, 'copy_stream_to_file')
     assert got_sciobj_bytes == expected_sciobj_bytes
Beispiel #9
0
 def test_1270(self, cn_client_v2):
     """do_get(): Successful file download"""
     mock_get.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
     pid_str = 'test_pid_1234'
     cli.do_get('{} {}'.format(pid_str, tmp_file_path))
     with open(tmp_file_path, 'rb') as f:
         received_sciobj_bytes = f.read()
     client = d1_client.mnclient.MemberNodeClient('http://responses/cn')
     expected_sciobj_bytes = client.get(pid_str).content
     assert received_sciobj_bytes == expected_sciobj_bytes
Beispiel #10
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')
 def _set_mock_session(self):
   # Must add Responses callbacks after activating @responses.activate
   mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   mock_list_nodes.add_callback(d1_test.d1_test_case.MOCK_CN_BASE_URL)
   mock_ping.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   mock_ping.add_callback(d1_test.d1_test_case.MOCK_CN_BASE_URL)
   mock_solr_search.add_callback(d1_test.d1_test_case.MOCK_CN_BASE_URL)
   mock_list_formats.add_callback(d1_test.d1_test_case.MOCK_CN_BASE_URL)
   mock_resolve.add_callback(d1_test.d1_test_case.MOCK_CN_BASE_URL)
   # Must set these session variables after activating Responses because
   # they implicitly call listNodes, etc.
   with d1_test.d1_test_case.mock_input('yes'):
     self.cp.get_session().set(
       session.CN_URL_NAME, d1_test.d1_test_case.MOCK_CN_BASE_URL
     )
     self.cp.get_session().set(
       session.MN_URL_NAME, d1_test.d1_test_case.MOCK_MN_BASE_URL
     )
Beispiel #12
0
 def _get_response(self, pid, header_dict=None):
   mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   s = session.Session(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   return s.GET(['object', pid], headers=header_dict or {})
Beispiel #13
0
 def _get_hash(self, pid):
   mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   s = session.Session(d1_test.d1_test_case.MOCK_MN_BASE_URL)
   response = s.GET(['object', pid])
   return hashlib.sha1(response.content).hexdigest()
Beispiel #14
0
 def test_1000(self, mn_client_v1_v2):
     """mock_api.get() returns a Requests Response object"""
     mock_get.add_callback(d1_test.d1_test_case.MOCK_MN_BASE_URL)
     assert isinstance(mn_client_v1_v2.get('test_pid_1'), requests.Response)