Beispiel #1
0
    def test_add_role_assignment_basic(self):
        role = 'Owner'
        sp = '1234567'

        with mock.patch('azure.cli.command_modules.role.custom.create_role_assignment') as create_role_assignment:
            ok = _add_role_assignment(role, sp, delay=0, output=False)
            create_role_assignment.assert_called_with(role, sp)
            self.assertTrue(ok, 'Expected _add_role_assignment to succeed')
Beispiel #2
0
    def test_add_role_assignment_basic(self):
        role = 'Owner'
        sp = '1234567'

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            ok = _add_role_assignment(role, sp, delay=0, output=False)
            create_role_assignment.assert_called_with(role, sp)
            self.assertTrue(ok, 'Expected _add_role_assignment to succeed')
Beispiel #3
0
    def test_add_role_assignment_msi_basic(self):
        role = 'Owner'
        sp = '1234567'
        cli_ctx = mock.MagicMock()

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            ok = _add_role_assignment(cli_ctx, role, sp, False, delay=0)
            create_role_assignment.assert_called_with(cli_ctx, role, sp, False, scope=None)
            self.assertTrue(ok, 'Expected _add_role_assignment with msi to succeed')
Beispiel #4
0
    def test_add_role_assignment_basic(self):
        role = 'Owner'
        sp = '1234567'
        cli_ctx = mock.MagicMock()

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            ok = _add_role_assignment(cli_ctx, role, sp, delay=0)
            create_role_assignment.assert_called_with(cli_ctx, role, sp)
            self.assertTrue(ok, 'Expected _add_role_assignment to succeed')
Beispiel #5
0
    def test_add_role_assignment_fails(self):
        role = 'Owner'
        sp = '1234567'

        with mock.patch('azure.cli.command_modules.role.custom.create_role_assignment') as create_role_assignment:
            resp = mock.Mock()
            resp.status_code = 500
            resp.content = 'Internal Error'
            err = CloudError(resp)
            err.message = 'Internal Error'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(role, sp, delay=0, output=False)
            
            create_role_assignment.assert_called_with(role, sp)
            self.assertFalse(ok, 'Expected _add_role_assignment to fail')
Beispiel #6
0
    def test_add_role_assignment_exists(self):
        role = 'Owner'
        sp = '1234567'

        with mock.patch('azure.cli.command_modules.role.custom.create_role_assignment') as create_role_assignment:
            resp = mock.Mock()
            resp.status_code = 409
            resp.content = 'Conflict'
            err = CloudError(resp)
            err.message = 'The role assignment already exists.'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(role, sp, delay=0, output=False)

            create_role_assignment.assert_called_with(role, sp)
            self.assertTrue(ok, 'Expected _add_role_assignment to succeed')
Beispiel #7
0
    def test_add_role_assignment_fails(self):
        role = 'Owner'
        sp = '1234567'

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            resp = mock.Mock()
            resp.status_code = 500
            resp.content = 'Internal Error'
            err = CloudError(resp)
            err.message = 'Internal Error'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(role, sp, delay=0, output=False)

            create_role_assignment.assert_called_with(role, sp)
            self.assertFalse(ok, 'Expected _add_role_assignment to fail')
Beispiel #8
0
    def test_add_role_assignment_exists(self):
        role = 'Owner'
        sp = '1234567'

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            resp = mock.Mock()
            resp.status_code = 409
            resp.content = 'Conflict'
            err = CloudError(resp)
            err.message = 'The role assignment already exists.'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(role, sp, delay=0, output=False)

            create_role_assignment.assert_called_with(role, sp)
            self.assertTrue(ok, 'Expected _add_role_assignment to succeed')
Beispiel #9
0
    def test_add_role_assignment_fails(self):
        role = 'Owner'
        sp = '1234567'
        cli_ctx = mock.MagicMock()

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            resp = requests.Response()
            resp.status_code = 500
            resp._content = b'Internal Error'
            err = CloudError(resp)
            err.message = 'Internal Error'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(cli_ctx, role, sp, delay=0)

            create_role_assignment.assert_called_with(cli_ctx, role, sp, True, scope=None)
            self.assertFalse(ok, 'Expected _add_role_assignment to fail')
Beispiel #10
0
    def test_add_role_assignment_exists(self):
        role = 'Owner'
        sp = '1234567'
        cli_ctx = mock.MagicMock()

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            resp = requests.Response()
            resp.status_code = 409
            resp._content = b'Conflict'
            err = CloudError(resp)
            err.message = 'The role assignment already exists.'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(cli_ctx, role, sp, delay=0)

            create_role_assignment.assert_called_with(cli_ctx, role, sp, True, scope=None)
            self.assertTrue(ok, 'Expected _add_role_assignment to succeed')
Beispiel #11
0
    def test_add_role_assignment_fails(self):
        role = 'Owner'
        sp = '1234567'
        cli_ctx = mock.MagicMock()

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            resp = requests.Response()
            resp.status_code = 500
            resp._content = b'Internal Error'
            err = CloudError(resp)
            err.message = 'Internal Error'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(cli_ctx, role, sp, delay=0)

            create_role_assignment.assert_called_with(cli_ctx, role, sp)
            self.assertFalse(ok, 'Expected _add_role_assignment to fail')
Beispiel #12
0
    def test_add_role_assignment_exists(self):
        role = 'Owner'
        sp = '1234567'
        cli_ctx = mock.MagicMock()

        with mock.patch(
                'azure.cli.command_modules.acs.custom.create_role_assignment') as create_role_assignment:
            resp = requests.Response()
            resp.status_code = 409
            resp._content = b'Conflict'
            err = CloudError(resp)
            err.message = 'The role assignment already exists.'
            create_role_assignment.side_effect = err
            ok = _add_role_assignment(cli_ctx, role, sp, delay=0)

            create_role_assignment.assert_called_with(cli_ctx, role, sp)
            self.assertTrue(ok, 'Expected _add_role_assignment to succeed')