def test_cli_create_user_random_password(self):
     args = self.parser.parse_args([
         'users', 'create', '--username', 'test1', '--lastname', 'doe',
         '--firstname', 'jon', '--email', '*****@*****.**', '--role',
         'Viewer', '--use-random-password'
     ])
     user_command.users_create(args)
 def test_cli_create_user_supplied_password(self):
     args = self.parser.parse_args([
         'users', 'create', '--username', 'test2', '--lastname', 'doe',
         '--firstname', 'jon', '--email', '*****@*****.**', '--role',
         'Viewer', '--password', 'test'
     ])
     user_command.users_create(args)
    def test_cli_add_user_role(self):
        args = self.parser.parse_args([
            'users',
            'create',
            '--username',
            'test4',
            '--lastname',
            'doe',
            '--firstname',
            'jon',
            '--email',
            TEST_USER1_EMAIL,
            '--role',
            'Viewer',
            '--use-random-password',
        ])
        user_command.users_create(args)

        self.assertFalse(
            _does_user_belong_to_role(appbuilder=self.appbuilder,
                                      email=TEST_USER1_EMAIL,
                                      rolename='Op'),
            "User should not yet be a member of role 'Op'",
        )

        args = self.parser.parse_args(
            ['users', 'add-role', '--username', 'test4', '--role', 'Op'])
        user_command.users_manage_role(args, remove=False)

        self.assertTrue(
            _does_user_belong_to_role(appbuilder=self.appbuilder,
                                      email=TEST_USER1_EMAIL,
                                      rolename='Op'),
            "User should have been added to role 'Op'",
        )
Exemple #4
0
    def test_cli_remove_user_role(self):
        args = self.parser.parse_args(
            [
                'users',
                'create',
                '--username',
                'test4',
                '--lastname',
                'doe',
                '--firstname',
                'jon',
                '--email',
                TEST_USER1_EMAIL,
                '--role',
                'Viewer',
                '--use-random-password',
            ]
        )
        user_command.users_create(args)

        assert _does_user_belong_to_role(
            appbuilder=self.appbuilder, email=TEST_USER1_EMAIL, rolename='Viewer'
        ), "User should have been created with role 'Viewer'"

        args = self.parser.parse_args(['users', 'remove-role', '--username', 'test4', '--role', 'Viewer'])
        user_command.users_manage_role(args, remove=True)

        assert not _does_user_belong_to_role(
            appbuilder=self.appbuilder, email=TEST_USER1_EMAIL, rolename='Viewer'
        ), "User should have been removed from role 'Viewer'"
Exemple #5
0
 def test_cli_list_users(self):
     for i in range(0, 3):
         args = self.parser.parse_args(
             [
                 'users',
                 'create',
                 '--username',
                 f'user{i}',
                 '--lastname',
                 'doe',
                 '--firstname',
                 'jon',
                 '--email',
                 f'jdoe+{i}@gmail.com',
                 '--role',
                 'Viewer',
                 '--use-random-password',
             ]
         )
         user_command.users_create(args)
     with redirect_stdout(io.StringIO()) as stdout:
         user_command.users_list(self.parser.parse_args(['users', 'list']))
         stdout = stdout.getvalue()
     for i in range(0, 3):
         assert f'user{i}' in stdout
Exemple #6
0
 def test_cli_delete_user_by_email(self):
     args = self.parser.parse_args(
         [
             'users',
             'create',
             '--username',
             'test4',
             '--lastname',
             'doe',
             '--firstname',
             'jon',
             '--email',
             '*****@*****.**',
             '--role',
             'Viewer',
             '--use-random-password',
         ]
     )
     user_command.users_create(args)
     args = self.parser.parse_args(
         [
             'users',
             'delete',
             '--email',
             '*****@*****.**',
         ]
     )
     user_command.users_delete(args)
 def test_cli_list_users(self):
     for i in range(0, 3):
         args = self.parser.parse_args([
             'users', 'create', '--username', 'user{}'.format(i),
             '--lastname', 'doe', '--firstname', 'jon', '--email',
             'jdoe+{}@gmail.com'.format(i), '--role', 'Viewer',
             '--use_random_password'
         ])
         user_command.users_create(args)
     with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout:
         user_command.users_list(self.parser.parse_args(['users', 'list']))
         stdout = mock_stdout.getvalue()
     for i in range(0, 3):
         self.assertIn('user{}'.format(i), stdout)