コード例 #1
0
    def test_creating_directory_with_defined_password_policy(self):
        ds = MagicMock()
        ds.create_resource.return_value = {}

        dl = DirectoryList(
            client=MagicMock(data_store=ds, BASE_URL='http://example.com'),
            href='directories')

        dl.create({
            'name': 'Foo',
            'description': 'Desc',
            'password_policy': {
                'reset_email_status':
                    PasswordPolicy.RESET_EMAIL_STATUS_ENABLED,
                'reset_success_email_status':
                    PasswordPolicy.RESET_EMAIL_STATUS_ENABLED,
                'reset_token_ttl': 32
                }
        })

        ds.create_resource.assert_called_once_with(
            'http://example.com/directories', {
                'passwordPolicy': {
                    'resetSuccessEmailStatus': 'ENABLED',
                    'resetEmailStatus': 'ENABLED',
                    'resetTokenTtl': 32
                },
                'description': 'Desc',
                'name': 'Foo',
            }, params={})
コード例 #2
0
    def test_creating_provider_directory_passes_provider_info(self):
        ds = MagicMock()
        ds.create_resource.return_value = {}

        dl = DirectoryList(
            client=MagicMock(data_store=ds, BASE_URL='http://example.com'),
            href='directories')

        dl.create({
            'name': 'Foo',
            'description': 'Desc',
            'provider': {
                'client_id': 'ID',
                'client_secret': 'SECRET',
                'redirect_uri': 'SOME_URL',
                'provider_id': 'myprovider'
            }
        })

        ds.create_resource.assert_called_once_with(
            'http://example.com/directories', {
                'description': 'Desc',
                'name': 'Foo',
                'provider': {
                    'clientSecret': 'SECRET',
                    'providerId': 'myprovider',
                    'redirectUri': 'SOME_URL',
                    'clientId': 'ID'
                }
            }, params={})
コード例 #3
0
    def test_creating_provider_directory_passes_provider_info(self):
        ds = MagicMock()
        ds.create_resource.return_value = {}

        dl = DirectoryList(
            client=MagicMock(data_store=ds, BASE_URL='http://example.com'),
            href='directories')

        dl.create({
            'name': 'Foo',
            'description': 'Desc',
            'provider': {
                'client_id': 'ID',
                'client_secret': 'SECRET',
                'redirect_uri': 'SOME_URL',
                'provider_id': 'myprovider'
            }
        })

        ds.create_resource.assert_called_once_with(
            'http://example.com/directories', {
                'description': 'Desc',
                'name': 'Foo',
                'provider': {
                    'clientSecret': 'SECRET',
                    'providerId': 'myprovider',
                    'redirectUri': 'SOME_URL',
                    'clientId': 'ID'
                }
            }, params={})
コード例 #4
0
    def test_creating_directory_with_defined_password_policy(self):
        ds = MagicMock()
        ds.create_resource.return_value = {}

        dl = DirectoryList(client=MagicMock(data_store=ds,
                                            BASE_URL='http://example.com'),
                           href='directories')

        dl.create({
            'name': 'Foo',
            'description': 'Desc',
            'password_policy': {
                'reset_email_status':
                PasswordPolicy.RESET_EMAIL_STATUS_ENABLED,
                'reset_success_email_status':
                PasswordPolicy.RESET_EMAIL_STATUS_ENABLED,
                'reset_token_ttl': 32
            }
        })

        ds.create_resource.assert_called_once_with(
            'http://example.com/directories', {
                'passwordPolicy': {
                    'resetSuccessEmailStatus': 'ENABLED',
                    'resetEmailStatus': 'ENABLED',
                    'resetTokenTtl': 32
                },
                'description': 'Desc',
                'name': 'Foo',
            },
            params={})
コード例 #5
0
    def test_modify_directory_provider(self):
        ds = MagicMock()
        ds.create_resource.return_value = {
            'name': 'Foo',
            'description': 'Desc',
            'provider': {
                'href': 'provider',
                'client_id': 'ID',
                'client_secret': 'SECRET',
                'redirect_uri': 'SOME_URL',
                'provider_id': 'myprovider'
            }
        }
        ds.update_resource.return_value = {}

        dl = DirectoryList(
            client=MagicMock(data_store=ds, BASE_URL='http://example.com'),
            href='directories')

        d = dl.create({
            'name': 'Foo',
            'description': 'Desc',
            'provider': {
                'client_id': 'ID',
                'client_secret': 'SECRET',
                'redirect_uri': 'SOME_URL',
                'provider_id': 'myprovider'
            }
        })

        d.provider.redirect_uri = 'SOME_OTHER_URL'
        d.provider.save()

        ds.update_resource.assert_called_once_with(
            'provider',
            {
                'clientSecret': 'SECRET',
                'providerId': 'myprovider',
                'redirectUri': 'SOME_OTHER_URL',
                'clientId': 'ID'
            })
コード例 #6
0
 def test_setting_context_only_works_for_application_and_directory_resources(self):
     context.store_config_file = lambda x, y: True
     context.get_resource = lambda x, y, z: True
     app = ApplicationList(MagicMock(), href="test/resource")
     d = DirectoryList(MagicMock(), href="test/resource")
     args = {'--name': 'test'}
     try:
         context.set_context(app, args)
     except:
         self.fail('Exception should not have been raised.')
     try:
         context.set_context(d, args)
     except:
         self.fail('Exception should not have been raised.')
     acc = AccountList(MagicMock(), href='test/resource')
     self.assertRaises(ValueError, context.set_context, acc, args)