Example #1
0
    def test_add_default_users_reapprove(self):
        """
        Ensure nothing happens or changes during rerun of approve.
        """
        project = fake_clients.FakeProject(name="test_project")

        setup_identity_cache(projects=[project])

        task = Task.objects.create(keystone_user={"roles": ["admin"]})

        task.cache = {"project_id": project.id}

        action = AddDefaultUsersToProjectAction({"domain_id": "default"},
                                                task=task,
                                                order=1)

        action.prepare()
        self.assertEqual(action.valid, True)

        action.approve()
        self.assertEqual(action.valid, True)

        fake_client = fake_clients.FakeManager()
        user = fake_client.find_user("admin", "default")
        roles = fake_client._get_roles_as_names(user, project)
        self.assertEqual(roles, ["admin"])

        action.approve()
        self.assertEqual(action.valid, True)

        roles = fake_client._get_roles_as_names(user, project)
        self.assertEqual(roles, ["admin"])
    def test_add_default_users_reapprove(self):
        """
        Ensure nothing happens or changes during rerun of approve.
        """
        project = mock.Mock()
        project.id = 'test_project_id'
        project.name = 'test_project'
        project.domain = 'default'
        project.roles = {}

        setup_temp_cache({'test_project': project}, {})

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={'roles': ['admin']})

        task.cache = {'project_id': "test_project_id"}

        action = AddDefaultUsersToProjectAction({'domain_id': 'default'},
                                                task=task,
                                                order=1)

        action.pre_approve()
        self.assertEquals(action.valid, True)

        action.post_approve()
        self.assertEquals(action.valid, True)

        project = tests.temp_cache['projects']['test_project']
        self.assertEquals(project.roles['user_id_0'], ['admin'])

        action.post_approve()
        self.assertEquals(action.valid, True)

        project = tests.temp_cache['projects']['test_project']
        self.assertEquals(project.roles['user_id_0'], ['admin'])
Example #3
0
    def test_add_default_users_reapprove(self):
        """
        Ensure nothing happens or changes during rerun of approve.
        """
        project = fake_clients.FakeProject(name="test_project")

        setup_identity_cache(projects=[project])

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={'roles': ['admin']})

        task.cache = {'project_id': project.id}

        action = AddDefaultUsersToProjectAction({'domain_id': 'default'},
                                                task=task,
                                                order=1)

        action.pre_approve()
        self.assertEqual(action.valid, True)

        action.post_approve()
        self.assertEqual(action.valid, True)

        fake_client = fake_clients.FakeManager()
        user = fake_client.find_user('admin', 'default')
        roles = fake_client._get_roles_as_names(user, project)
        self.assertEqual(roles, ['admin'])

        action.post_approve()
        self.assertEqual(action.valid, True)

        roles = fake_client._get_roles_as_names(user, project)
        self.assertEqual(roles, ['admin'])
Example #4
0
    def test_add_default_users(self):
        """
        Base case, adds admin user with admin role to project.

        NOTE(adriant): This test assumes the conf setting of:
        default_users = ['admin']
        default_roles = ['admin']
        """
        project = fake_clients.FakeProject(name="test_project")

        setup_identity_cache(projects=[project])

        task = Task.objects.create(keystone_user={"roles": ["admin"]})

        task.cache = {"project_id": project.id}

        action = AddDefaultUsersToProjectAction({"domain_id": "default"},
                                                task=task,
                                                order=1)

        action.prepare()
        self.assertEqual(action.valid, True)

        action.approve()
        self.assertEqual(action.valid, True)

        fake_client = fake_clients.FakeManager()
        user = fake_client.find_user("admin", "default")
        roles = fake_client._get_roles_as_names(user, project)
        self.assertEqual(roles, ["admin"])
    def test_add_default_users_invalid_project(self):
        """Add default users to a project that doesn't exist.

        Action should become invalid at the post_approve state, it's ok if
        the project isn't created yet during pre_approve.
        """
        project = mock.Mock()
        project.id = 'test_project_id'
        project.name = 'test_project'
        project.domain = 'default'
        project.roles = {}

        setup_temp_cache({'test_project': project}, {})

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={'roles': ['admin']})

        task.cache = {'project_id': "invalid_project_id"}

        action = AddDefaultUsersToProjectAction({'domain_id': 'default'},
                                                task=task,
                                                order=1)
        action.pre_approve()
        # No need to test project yet - it's ok if it doesn't exist
        self.assertEquals(action.valid, True)

        action.post_approve()
        # Now the missing project should make the action invalid
        self.assertEquals(action.valid, False)
    def test_add_default_users(self):
        """
        Base case, adds admin user with admin role to project.

        NOTE(adriant): both the lists of users, and the roles to add
        come from test_settings. This test assumes the conf setting of:
        default_users = ['admin']
        default_roles = ['admin']
        """
        project = mock.Mock()
        project.id = 'test_project_id'
        project.name = 'test_project'
        project.domain = 'default'
        project.roles = {}

        setup_temp_cache({'test_project': project}, {})

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={'roles': ['admin']})

        task.cache = {'project_id': "test_project_id"}

        action = AddDefaultUsersToProjectAction({'domain_id': 'default'},
                                                task=task,
                                                order=1)

        action.pre_approve()
        self.assertEquals(action.valid, True)

        action.post_approve()
        self.assertEquals(action.valid, True)

        project = tests.temp_cache['projects']['test_project']
        self.assertEquals(project.roles['user_id_0'], ['admin'])
Example #7
0
    def test_add_default_users(self):
        """
        Base case, adds admin user with admin role to project.

        NOTE(adriant): both the lists of users, and the roles to add
        come from test_settings. This test assumes the conf setting of:
        default_users = ['admin']
        default_roles = ['admin']
        """
        project = fake_clients.FakeProject(name="test_project")

        setup_identity_cache(projects=[project])

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={'roles': ['admin']})

        task.cache = {'project_id': project.id}

        action = AddDefaultUsersToProjectAction({'domain_id': 'default'},
                                                task=task,
                                                order=1)

        action.pre_approve()
        self.assertEqual(action.valid, True)

        action.post_approve()
        self.assertEqual(action.valid, True)

        fake_client = fake_clients.FakeManager()
        user = fake_client.find_user('admin', 'default')
        roles = fake_client._get_roles_as_names(user, project)
        self.assertEqual(roles, ['admin'])
Example #8
0
    def test_add_default_users_invalid_project(self):
        """Add default users to a project that doesn't exist.

        Action should become invalid at the approve state, it's ok if
        the project isn't created yet during prepare.
        """
        setup_identity_cache()

        task = Task.objects.create(keystone_user={"roles": ["admin"]})

        task.cache = {"project_id": "invalid_project_id"}

        action = AddDefaultUsersToProjectAction({"domain_id": "default"},
                                                task=task,
                                                order=1)
        action.prepare()
        # No need to test project yet - it's ok if it doesn't exist
        self.assertEqual(action.valid, True)

        action.approve()
        # Now the missing project should make the action invalid
        self.assertEqual(action.valid, False)