Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 def _add_write_operation_to_queue(self, cli, write_fun, cmd_format_str,
                                   **kwargs_dict):
     cli.do_reset('')
     cli.do_allowaccess('test_subject_1 write')
     cli.do_allowaccess('test_subject_3 changePermission')
     cli.do_preferrep('preferred-mn-2')
     cli.do_blockrep('blocked-mn-1')
     cli.do_blockrep('blocked-mn-2')
     cli.do_numberrep('42')
     cli.do_set('authoritative-mn urn:node:myTestMN')
     cli.do_set('rights-holder test-rights-holder-subject')
     cli.do_set('format-id test-format-id')
     cli.do_set('cn-url {}'.format(d1_test.d1_test_case.MOCK_CN_BASE_URL))
     cli.do_set('mn-url {}'.format(d1_test.d1_test_case.MOCK_MN_BASE_URL))
     pid_str = 'test_pid_{}'.format(
         d1_test.instance_generator.random_data.random_3_words())
     with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
         tmp_file.write('sciobj_for_{}'.format(pid_str).encode('utf-8'))
     # Add a create task to the queue.
     kwargs_dict.update({
         'pid': pid_str,
         'tmp_file_path': tmp_file.name,
     })
     with d1_test.d1_test_case.capture_std():
         write_fun(cmd_format_str.format(**kwargs_dict))
     yield pid_str
     os.unlink(tmp_file.name)
Exemplo n.º 3
0
 def test_1260(self, capsys):
     """list nodes: Gives expected output"""
     mock_list_nodes.add_callback('http://responses/cn')
     cli = d1_cli.impl.cli.CLI()
     cli.do_set('cn-url http://responses/cn')
     cli.do_listnodes('')
     stdout, stderr = capsys.readouterr()
     self.sample.assert_equals(stdout, 'list_nodes')
Exemplo n.º 4
0
 def test_1410(self, cn_client_v2):
     """search: Expected Solr query is generated"""
     expect = 'id:knb-lter* abstract:water dateModified:[* TO *]'
     args = ' '.join([_f for _f in ('id:knb-lter*', ) if _f])
     cli = d1_cli.impl.cli.CLI()
     cli.do_set('query abstract:water')
     actual = cli._command_processor._create_solr_query(args)
     assert expect == actual
Exemplo n.º 5
0
 def test_1150(self, cn_client_v2):
     """ping: Returns server status"""
     d1_test.mock_api.catch_all.add_callback('http://mock/node')
     cli = d1_cli.impl.cli.CLI()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('cn-url http://mock/node')
         cli.do_set('mn-url http://mock/node')
         cli.do_ping('')
Exemplo n.º 6
0
 def test_1130(self, cn_client_v2):
     """set: Command gives expected output when setting count"""
     cli = d1_cli.impl.cli.CLI()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('count 2')
     assert 'count to "2"' in out_stream.getvalue()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('count 3')
     assert 'count to "3"' in out_stream.getvalue()
Exemplo n.º 7
0
 def test_1120(self, cn_client_v2):
     """set: Command gives expected output on flag toggle"""
     cli = d1_cli.impl.cli.CLI()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('verbose true')
     assert 'verbose to "true"' in out_stream.getvalue()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('verbose false')
     assert 'verbose to "false"' in out_stream.getvalue()
Exemplo n.º 8
0
 def test_1420(self, cn_client_v2):
     """search: Expected Solr query is generated"""
     expect = 'id:knb-lter* formatId:text/csv dateModified:[* TO *]'
     args = ' '.join([_f for _f in ('id:knb-lter*', ) if _f])
     cli = d1_cli.impl.cli.CLI()
     cli.do_set('query None')
     cli.do_set('search-format-id text/csv')
     actual = cli._command_processor._create_solr_query(args)
     assert expect == actual
Exemplo n.º 9
0
 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')
Exemplo n.º 10
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.º 11
0
 def test_1260(self, cn_client_v2):
     """list nodes: Gives expected output"""
     mock_list_nodes.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.capture_std() as (out_stream, err_stream):
         cli.do_listnodes('')
     node_line = ('         cn \tcn-ucsb-1                               '
                  '\thttps://cn-ucsb-1.dataone.org/cn\n         cn '
                  '\tcn-unm-1                                '
                  '\thttps://cn-unm-1.dataone.org/cn\n')
     assert node_line in out_stream.getvalue()
Exemplo n.º 12
0
 def test_1190(self, cn_client_v2):
     """do_clearaccess(): Removes all subjects"""
     cli = d1_cli.impl.cli.CLI()
     cli.do_allowaccess('test_subject_1 write')
     cli.do_allowaccess('test_subject_2 write')
     cli.do_allowaccess('test_subject_3 changePermission')
     cli.do_clearaccess('')
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('')
     env_str = out_stream.getvalue()
     assert 'test_subject_1: write' not in env_str
     assert 'test_subject_2: write' not in env_str
     assert 'test_subject_3: changePermission' not in env_str
Exemplo n.º 13
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
Exemplo n.º 14
0
 def test_1150(self, cn_client_v2):
     """ping (no arguments): Ping the CN and MN that is specified in the session
 """
     d1_test.mock_api.catch_all.add_callback(
         d1_test.d1_test_case.MOCK_CN_BASE_URL)
     d1_test.mock_api.catch_all.add_callback(
         d1_test.d1_test_case.MOCK_MN_BASE_URL)
     cli = d1_cli.impl.cli.CLI()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('cn-url {}'.format(
             d1_test.d1_test_case.MOCK_CN_BASE_URL))
         cli.do_set('mn-url {}'.format(
             d1_test.d1_test_case.MOCK_MN_BASE_URL))
         cli.do_ping('')
Exemplo n.º 15
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.º 16
0
 def test_1300(self, cn_client_v2):
     """do_log(): Successful object listing"""
     mock_get_log_records.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_log(tmp_file_path)
     with open(tmp_file_path, 'rb') as f:
         received_event_log_pyxb = v2.CreateFromDocument(f.read())
     client = d1_client.mnclient.MemberNodeClient('http://responses/cn')
     expected_event_log_pyxb = client.getLogRecords()
     now = datetime.datetime.utcnow()
     for log_entry in received_event_log_pyxb.logEntry:
         log_entry.dateLogged = now
     for log_entry in expected_event_log_pyxb.logEntry:
         log_entry.dateLogged = now
     assert d1_common.xml. \
       are_equal_pyxb(received_event_log_pyxb, expected_event_log_pyxb)
Exemplo n.º 17
0
 def test_1180(self, cn_client_v2):
     """do_denyaccess(): Subject with permissions is removed"""
     cli = d1_cli.impl.cli.CLI()
     cli.do_allowaccess('test_subject_1 write')
     cli.do_allowaccess('test_subject_2 write')
     cli.do_allowaccess('test_subject_3 changePermission')
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('')
     env_str = out_stream.getvalue()
     assert 'test_subject_3: changePermission' in env_str
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_denyaccess('test_subject_3')
     assert 'Removed subject "test_subject_3"' in out_stream.getvalue()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('')
     env_str = out_stream.getvalue()
     assert 'test_subject_1: write' in env_str
     assert 'test_subject_2: write' in env_str
     assert 'test_subject_3: changePermission' not in env_str
Exemplo n.º 18
0
 def _do_exit(self, answer_str, exit_call_count):
     """do_exit(): Gives option to cancel if the operation queue is not empty"""
     cli = d1_cli.impl.cli.CLI()
     cli.preloop()
     fi, tmp_path = tempfile.mkstemp(prefix='test_dataone_cli.',
                                     suffix='.tmp',
                                     text=True)
     os.close(fi)
     cli.do_set('authoritative-mn urn:node:myTestMN')
     cli.do_set('rights-holder test-rights-holder-subject')
     create_operation = cli._command_processor._operation_maker.create(
         'test_pid', tmp_path, 'test_format_id')
     cli._command_processor._operation_queue.append(create_operation)
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         with d1_test.d1_test_case.mock_input(answer_str):
             with mock.patch('sys.exit', return_value='') as mock_method:
                 cli.do_exit('')
                 assert mock_method.call_count == exit_call_count
     assert 'There are 1 unperformed operations in the write operation queue' in out_stream.getvalue(
     )
Exemplo n.º 19
0
 def setup_method(self):
     cli = d1_cli.impl.cli.CLI()
     cli.do_set('verbose true')
Exemplo n.º 20
0
 def test_1110(self, cn_client_v2):
     """do_reset(), do_set(), do_save(), do_load(): Session to disk round trip"""
     cli = d1_cli.impl.cli.CLI()
     cli.preloop()
     fi, path = tempfile.mkstemp(prefix='test_dataone_cli.',
                                 suffix='.tmp',
                                 text=True)
     os.close(fi)
     # Reset, set some values and save to file
     cli.do_reset('')
     cli.do_set('editor test_editor')
     cli.do_set('cn-url test_cn-url')
     cli.do_set('key-file test-key-file')
     cli.do_save(path)
     # Reset and check that values are at their defaults
     cli.do_reset('')
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('editor')
     assert 'editor: nano' in out_stream.getvalue()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('cn-url')
     assert 'cn-url: https://cn.dataone.org/cn' in out_stream.getvalue()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('key-file')
     assert 'key-file: None' in out_stream.getvalue()
     # Load from file and verify
     cli.do_load(path)
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('editor')
     assert 'editor: test_editor' in out_stream.getvalue()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('cn-url')
     assert 'cn-url: test_cn-url' in out_stream.getvalue()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('key-file')
     assert 'key-file: test-key-file' in out_stream.getvalue()
Exemplo n.º 21
0
 def test_1140(self, cn_client_v2):
     """set: Command gives expected output when setting query string"""
     cli = d1_cli.impl.cli.CLI()
     with d1_test.d1_test_case.capture_std() as (out_stream, err_stream):
         cli.do_set('query a=b')
     assert 'variable query to "a=b"' in out_stream.getvalue()