def test_register_remove_user_command_project_id(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_remove_user_command(self.set_parsed_args)
     self.assertEqual(['remove-user'], list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(['remove-user', '-i', '456', '--user', 'joe123'])
     self.assertEqual(None, self.parsed_args.project_name)
     self.assertEqual('456', self.parsed_args.project_id)
Beispiel #2
0
    def test_list_command(self):
        func = Mock()
        command_parser = CommandParser(version_str='1.0')
        command_parser.register_list_command(func)
        self.assertEqual(['list'],
                         list(command_parser.subparsers.choices.keys()))

        # Test simple listing
        command_parser.run_command(['list'])
        func.assert_called()
        args, kwargs = func.call_args
        self.assertEqual(args[0].auth_role, None)
        self.assertEqual(args[0].project_name, None)
        self.assertEqual(args[0].long_format, False)
        func.reset_mock()

        # Test simple listing single project
        command_parser.run_command(['list', '-p', 'mouse'])
        func.assert_called()
        args, kwargs = func.call_args
        self.assertEqual(args[0].auth_role, None)
        self.assertEqual(args[0].project_name, 'mouse')

        # Test simple listing auth_role
        command_parser.run_command(['list', '--auth-role', 'project_admin'])
        func.assert_called()
        args, kwargs = func.call_args
        self.assertEqual(args[0].auth_role, 'project_admin')
        self.assertEqual(args[0].project_name, None)
 def test_share_with_msg(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_share_command(self.set_parsed_args)
     self.assertEqual(['share'], list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(['share', '-i', '456', '--user', 'joe123', '--msg-file', 'setup.py'])
     self.assertIn('setup(', self.parsed_args.msg_file.read())
     self.assertEqual(None, self.parsed_args.project_name)
     self.assertEqual('456', self.parsed_args.project_id)
 def test_share_no_msg(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_share_command(self.set_parsed_args)
     self.assertEqual(['share'], list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(['share', '-p', 'someproject2', '--user', 'joe123'])
     self.assertEqual(None, self.parsed_args.msg_file)
     self.assertEqual('someproject2', self.parsed_args.project_name)
     self.assertEqual(None, self.parsed_args.project_id)
    def test_list_command(self):
        func = Mock()
        command_parser = CommandParser(version_str='1.0')
        command_parser.register_list_command(func)
        self.assertEqual(['list'], list(command_parser.subparsers.choices.keys()))

        # Test simple listing
        command_parser.run_command(['list'])
        func.assert_called()
        args, kwargs = func.call_args
        self.assertEqual(args[0].auth_role, None)
        self.assertEqual(args[0].project_name, None)
        self.assertEqual(args[0].long_format, False)
        func.reset_mock()

        # Test simple listing single project
        command_parser.run_command(['list', '-p', 'mouse'])
        func.assert_called()
        args, kwargs = func.call_args
        self.assertEqual(args[0].auth_role, None)
        self.assertEqual(args[0].project_name, 'mouse')

        # Test simple listing auth_role
        command_parser.run_command(['list', '--auth-role', 'project_admin'])
        func.assert_called()
        args, kwargs = func.call_args
        self.assertEqual(args[0].auth_role, 'project_admin')
        self.assertEqual(args[0].project_name, None)
 def test_deliver_with_copy(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_deliver_command(self.set_parsed_args)
     self.assertEqual(['deliver'], list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(['deliver', '-p', 'someproject', '--user', 'joe123', '--copy'])
     self.assertEqual(None, self.parsed_args.msg_file)
     self.assertEqual('someproject', self.parsed_args.project_name)
     self.assertEqual(None, self.parsed_args.project_id)
     self.assertEqual(None, self.parsed_args.share_usernames)
     self.assertEqual(None, self.parsed_args.share_emails)
     self.assertEqual(True, self.parsed_args.copy_project)
 def test_deliver_with_share_users(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_deliver_command(self.set_parsed_args)
     self.assertEqual(['deliver'], list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(['deliver', '-i', '123',
                                 '--user', 'joe123',
                                 '--share-users', 'bob555', 'tom666',
                                 '--share-emails', '*****@*****.**'])
     self.assertEqual(None, self.parsed_args.project_name)
     self.assertEqual('123', self.parsed_args.project_id)
     self.assertEqual(['bob555', 'tom666'], self.parsed_args.share_usernames)
     self.assertEqual(['*****@*****.**'], self.parsed_args.share_emails)
     self.assertEqual(False, self.parsed_args.copy_project)
Beispiel #8
0
 def test_register_download_command(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_download_command(self.set_parsed_args)
     self.assertEqual(['download'],
                      list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(['download', '-p', 'mouse'])
     self.assertEqual('mouse', self.parsed_args.project_name)
Beispiel #9
0
 def test_share_no_msg(self):
     command_parser = CommandParser()
     command_parser.register_share_command(self.set_parsed_args)
     self.assertEqual(['share'],
                      list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(
         ['share', '-p', 'someproject', '--user', 'joe123'])
     self.assertEqual(None, self.parsed_args.msg_file)
Beispiel #10
0
 def test_register_remove_user_command_project_id(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_remove_user_command(self.set_parsed_args)
     self.assertEqual(['remove-user'],
                      list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(
         ['remove-user', '-i', '456', '--user', 'joe123'])
     self.assertEqual(None, self.parsed_args.project_name)
     self.assertEqual('456', self.parsed_args.project_id)
Beispiel #11
0
 def test_share_with_msg(self):
     command_parser = CommandParser()
     command_parser.register_share_command(self.set_parsed_args)
     self.assertEqual(['share'],
                      list(command_parser.subparsers.choices.keys()))
     command_parser.run_command([
         'share', '-p', 'someproject', '--user', 'joe123', '--msg-file',
         'setup.py'
     ])
     self.assertIn('setup(', self.parsed_args.msg_file.read())
Beispiel #12
0
 def test_share_with_msg(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_share_command(self.set_parsed_args)
     self.assertEqual(['share'],
                      list(command_parser.subparsers.choices.keys()))
     command_parser.run_command([
         'share', '-i', '456', '--user', 'joe123', '--msg-file', 'setup.py'
     ])
     self.assertIn('setup(', self.parsed_args.msg_file.read())
     self.assertEqual(None, self.parsed_args.project_name)
     self.assertEqual('456', self.parsed_args.project_id)
Beispiel #13
0
 def test_deliver_no_msg(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_deliver_command(self.set_parsed_args)
     self.assertEqual(['deliver'],
                      list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(
         ['deliver', '-p', 'someproject', '--user', 'joe123'])
     self.assertEqual(None, self.parsed_args.msg_file)
     self.assertEqual('someproject', self.parsed_args.project_name)
     self.assertEqual(None, self.parsed_args.project_id)
     self.assertEqual(None, self.parsed_args.share_usernames)
     self.assertEqual(None, self.parsed_args.share_emails)
Beispiel #14
0
 def test_deliver_with_share_users(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_deliver_command(self.set_parsed_args)
     self.assertEqual(['deliver'],
                      list(command_parser.subparsers.choices.keys()))
     command_parser.run_command([
         'deliver', '-i', '123', '--user', 'joe123', '--share-users',
         'bob555', 'tom666', '--share-emails', '*****@*****.**'
     ])
     self.assertEqual(None, self.parsed_args.project_name)
     self.assertEqual('123', self.parsed_args.project_id)
     self.assertEqual(['bob555', 'tom666'],
                      self.parsed_args.share_usernames)
     self.assertEqual(['*****@*****.**'], self.parsed_args.share_emails)
Beispiel #15
0
    def test_list_command_long(self):
        command_parser = CommandParser(version_str='1.0')
        command_parser.register_list_command(self.set_parsed_args)
        command_parser.run_command(['list'])
        self.assertEqual(False, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)

        command_parser.run_command(['list', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)

        command_parser.run_command(['list', '-i', '123', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual('123', self.parsed_args.project_id)

        command_parser.run_command(['list', '--project-id', '123', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual('123', self.parsed_args.project_id)

        command_parser.run_command(['list', '-p', 'mouse', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual('mouse', self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)

        command_parser.run_command(['list', '--project-name', 'mouse', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual('mouse', self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)
Beispiel #16
0
 def test_register_remove_user_command(self):
     command_parser = CommandParser()
     command_parser.register_remove_user_command(no_op)
     self.assertEqual(['remove-user'],
                      list(command_parser.subparsers.choices.keys()))
Beispiel #17
0
 def test_register_add_user_command_no_msg(self):
     command_parser = CommandParser()
     command_parser.register_add_user_command(no_op)
     self.assertEqual(['add-user'],
                      list(command_parser.subparsers.choices.keys()))
Beispiel #18
0
 def _create_parser(self):
     """
     Create a parser hooking up the command methods below to be run when chosen.
     :return: CommandParser parser with commands attached.
     """
     parser = CommandParser(get_internal_version_str())
     parser.register_list_command(self._setup_run_command(ListCommand))
     parser.register_upload_command(self._setup_run_command(UploadCommand))
     parser.register_add_user_command(self._setup_run_command(AddUserCommand))
     parser.register_remove_user_command(self._setup_run_command(RemoveUserCommand))
     parser.register_download_command(self._setup_run_command(DownloadCommand))
     parser.register_share_command(self._setup_run_command(ShareCommand))
     parser.register_deliver_command(self._setup_run_command(DeliverCommand))
     parser.register_delete_command(self._setup_run_command(DeleteCommand))
     parser.register_list_auth_roles_command(self._setup_run_command(ListAuthRolesCommand))
     return parser
Beispiel #19
0
    def test_list_command_long(self):
        command_parser = CommandParser(version_str='1.0')
        command_parser.register_list_command(self.set_parsed_args)
        command_parser.run_command(['list'])
        self.assertEqual(False, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)

        command_parser.run_command(['list', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)

        command_parser.run_command(['list', '-i', '123', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual('123', self.parsed_args.project_id)

        command_parser.run_command(['list', '--project-id', '123', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual(None, self.parsed_args.project_name)
        self.assertEqual('123', self.parsed_args.project_id)

        command_parser.run_command(['list', '-p', 'mouse', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual('mouse', self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)

        command_parser.run_command(['list', '--project-name', 'mouse', '-l'])
        self.assertEqual(True, self.parsed_args.long_format)
        self.assertEqual('mouse', self.parsed_args.project_name)
        self.assertEqual(None, self.parsed_args.project_id)
Beispiel #20
0
 def test_description(self):
     expected_description = 'DukeDSClient (1.0) Manage projects/folders/files in the duke-data-service'
     command_parser = CommandParser(version_str='1.0')
     self.assertEqual(expected_description,
                      command_parser.parser.description)
Beispiel #21
0
 def _create_parser(self):
     """
     Create a parser hooking up the command methods below to be run when chosen.
     :return: CommandParser parser with commands attached.
     """
     parser = CommandParser()
     parser.register_list_command(self._setup_run_command(ListCommand))
     parser.register_upload_command(self._setup_run_command(UploadCommand))
     parser.register_add_user_command(
         self._setup_run_command(AddUserCommand))
     parser.register_remove_user_command(
         self._setup_run_command(RemoveUserCommand))
     parser.register_download_command(
         self._setup_run_command(DownloadCommand))
     parser.register_share_command(self._setup_run_command(ShareCommand))
     parser.register_deliver_command(
         self._setup_run_command(DeliverCommand))
     parser.register_delete_command(self._setup_run_command(DeleteCommand))
     parser.register_list_auth_roles_command(
         self._setup_run_command(ListAuthRolesCommand))
     return parser
Beispiel #22
0
 def test_register_download_command(self):
     command_parser = CommandParser(version_str='1.0')
     command_parser.register_download_command(self.set_parsed_args)
     self.assertEqual(['download'], list(command_parser.subparsers.choices.keys()))
     command_parser.run_command(['download', '-p', 'mouse'])
     self.assertEqual('mouse', self.parsed_args.project_name)