Example #1
0
    def test_iter_cai_assets(self):
        """Validate querying CAI asset data."""
        self._add_resources()

        results = CaiDataAccess.iter_cai_assets(
            ContentTypes.resource,
            'cloudresourcemanager.googleapis.com/Folder',
            '//cloudresourcemanager.googleapis.com/organizations/1234567890',
            self.session)

        expected_names = ['folders/11111']
        self.assertEqual(expected_names, [asset['name'] for asset in results])

        results = CaiDataAccess.iter_cai_assets(
            ContentTypes.resource, 'appengine.googleapis.com/Service',
            '//appengine.googleapis.com/apps/forseti-test-project',
            self.session)

        expected_names = ['apps/forseti-test-project/services/default']
        self.assertEqual(expected_names, [asset['name'] for asset in results])
Example #2
0
    def test_clear_cai_data(self):
        """Validate CAI data delete."""
        self._add_resources()

        rows = CaiDataAccess.clear_cai_data(self.session)
        expected_rows = len(CAI_RESOURCE_DATA.split('\n'))
        self.assertEqual(expected_rows, rows)

        results = CaiDataAccess.iter_cai_assets(
            ContentTypes.resource,
            'cloudresourcemanager.googleapis.com/Folder',
            '//cloudresourcemanager.googleapis.com/organizations/1234567890',
            self.session)
        self.assertEqual(0, len(list(results)))
Example #3
0
    def test_iter_cai_assets(self):
        """Validate querying CAI asset data."""
        self._add_resources()

        cai_type = 'cloudresourcemanager.googleapis.com/Folder'

        results = CaiDataAccess.iter_cai_assets(
            ContentTypes.resource, cai_type,
            '//cloudresourcemanager.googleapis.com/organizations/1234567890',
            self.session)

        expected_results = [
            ('folders/11111',
             AssetMetadata(
                 cai_type=cai_type,
                 cai_name='//cloudresourcemanager.googleapis.com/folders/11111'
             ))
        ]
        self.assertEqual(expected_results, [(asset['name'], metadata)
                                            for asset, metadata in results])

        cai_type = 'appengine.googleapis.com/Service'

        results = CaiDataAccess.iter_cai_assets(
            ContentTypes.resource, cai_type,
            '//appengine.googleapis.com/apps/forseti-test-project',
            self.session)

        expected_results = [(
            'apps/forseti-test-project/services/default',
            AssetMetadata(
                cai_name=
                '//appengine.googleapis.com/apps/forseti-test-project/services/default',
                cai_type=cai_type))]
        self.assertEqual(expected_results, [(asset['name'], metadata)
                                            for asset, metadata in results])