def setUp(self, mock_org_dao, mock_folder_dao, mock_project_dao):
        mock_org_dao.return_value = None
        mock_folder_dao.return_value = None
        mock_project_dao.return_value = None
        self.org_res_rel_dao = org_resource_rel_dao.OrgResourceRelDao({})

        # TODO: move this to separate module
        self.fake_org = organization.Organization(
            organization_id=1,
            display_name='Org 1')
        self.fake_folder1 = folder.Folder(
            folder_id=11,
            display_name='Folder 1',
            parent=self.fake_org)
        self.fake_folder2 = folder.Folder(
            folder_id=22,
            display_name='Folder 2',
            parent=self.fake_folder1)
        self.fake_project1 = project.Project(
            project_number=111,
            project_id='project-1',
            display_name='Project 1',
            parent=self.fake_folder2)

        self.fake_timestamp = '1234567890'
 def test_get_project_policies(self, mock_get_proj_iam, mock_conn):
     """Test that get_org_policies() works."""
     proj_policies = [{
         project.Project(project_number='11111', project_id='abc111'): {
             'role': 'roles/a',
             'members': ['user:[email protected]', 'group:[email protected]']
         }
     }]
     mock_get_proj_iam.return_value = proj_policies
     actual = self.irs.IamPolicyScanner(
         self.fake_timestamp)._get_project_policies()
     mock_get_proj_iam.assert_called_once_with('projects',
                                               self.fake_timestamp)
     self.assertEqual(proj_policies, actual)
Beispiel #3
0
    def test_get_project_policies(self, mock_dao):
        """Test that get_org_policies() works."""

        fake_policies = [{
            project.Project(project_number='11111', project_id='abc111'): {
                'role': 'roles/a',
                'members': ['user:[email protected]', 'group:[email protected]']
            }
        }]

        mock_dao.ProjectDao({}).get_project_policies.return_value = (
            fake_policies)
        policies = self.scanner._get_project_iam_policies()
        self.assertEqual(fake_policies, policies)
Beispiel #4
0
    def map_row_to_object(row):
        """Instantiate a Project from database row.

        TODO: Make this go away when we start using an ORM.
        ProjectDao has a special case because the database schema doesn't
        match the GCP API fields.

        Args:
            row: The database row to map.

        Returns:
            A Project, created from the row.
        """
        return project.Project(project_id=row['project_id'],
                               project_number=row['project_number'],
                               display_name=row['project_name'],
                               lifecycle_state=row['lifecycle_state'],
                               parent=resource_util.create_resource(
                                   resource_id=row['parent_id'],
                                   resource_type=row['parent_type']))
 def get_project(self, project_id, snapshot_timestamp=0):
     return project_type.Project(project_id=project_id)