コード例 #1
0
    def test_get_billing_info_raises(self):
        """Test get project billing info raises on exception."""
        http_mocks.mock_http_response(fake_cloudbilling.PERMISSION_DENIED,
                                      '403')

        with self.assertRaises(api_errors.ApiExecutionError):
             self.billing_api_client.get_billing_info(self.project_id)
コード例 #2
0
    def test_get_images(self):
        """Test get images."""
        http_mocks.mock_http_response(fake_compute.LIST_IMAGES)

        results = self.gce_api_client.get_images(self.project_id)
        self.assertEquals(fake_compute.EXPECTED_IMAGE_NAMES,
                          [r.get('name') for r in results])
コード例 #3
0
    def test_get_instances(self):
        """Test get instances."""
        http_mocks.mock_http_response(fake_compute.INSTANCES_AGGREGATED_LIST)

        results = self.gce_api_client.get_instances(self.project_id)
        self.assertEquals(fake_compute.EXPECTED_INSTANCE_NAMES,
                          [r.get('name') for r in results])
コード例 #4
0
    def test_get_instance_raises(self):
        http_mocks.mock_http_response(fae.PERMISSION_DENIED, '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.ae_api_client.get_instance(
            fae.FAKE_PROJECT_ID, fae.FAKE_SERVICE_ID, fae.FAKE_VERSION_ID,
            fae.FAKE_INSTANCE_ID)
コード例 #5
0
    def test_get_dataset_access_raises(self):
        """Test get_dataset_access raises when there is an HTTP exception."""
        http_mocks.mock_http_response(fbq.PERMISSION_DENIED, '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.bq_api_client.get_dataset_access(fbq.PROJECT_IDS[0],
                                                  fbq.DATASET_ID)
コード例 #6
0
    def test_get_projects_all(self):
        """Test get_projects() for all lifecycle_states."""
        response = json.dumps(fake_projects.FAKE_PROJECTS_API_RESPONSE1)
        http_mocks.mock_http_response(response)

        result = list(self.crm_api_client.get_projects('projects'))
        self.assertEquals(fake_projects.EXPECTED_FAKE_PROJECTS1, result)
コード例 #7
0
    def test_get_instance(self):
        http_mocks.mock_http_response(fae.GET_INSTANCE_RESPONSE)
        response = self.ae_api_client.get_instance(
            fae.FAKE_PROJECT_ID, fae.FAKE_SERVICE_ID, fae.FAKE_VERSION_ID,
            fae.FAKE_INSTANCE_ID)

        self.assertEqual(fae.EXPECTED_INSTANCE_NAMES[0], response.get('name'))
コード例 #8
0
    def test_get_service_account_keys_raises(self):
        """Test get iam project service accounts not found."""
        http_mocks.mock_http_response(fake_iam.SERVICE_ACCOUNT_NOT_FOUND, '404')

        with self.assertRaises(api_errors.ApiExecutionError):
             self.iam_api_client.get_service_account_keys(
                 fake_iam.FAKE_SERVICEACCOUNT_NAME)
コード例 #9
0
    def test_get_objects_iam_policy_raises(self):
        """Test get object acls access forbidden."""
        http_mocks.mock_http_response(fake_storage.ACCESS_FORBIDDEN, '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.gcs_api_client.get_object_acls(
                fake_storage.FAKE_BUCKET_NAME, fake_storage.FAKE_OBJECT_NAME)
    def test_get_organization_raises_error(self):
        """Test get_organization() raises ApiExecutionError on HTTP error."""
        http_mocks.mock_http_response(fake_crm_responses.GET_PROJECT_NOT_FOUND,
                                      '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.crm_api_client.get_organization(fake_crm_responses.FAKE_ORG_ID)
 def test_get_org_policy_errors(self):
     """Test get_org_policy for error handling."""
     test_cases = [
         (
             'folders/{}'.format(fake_crm_responses.FAKE_FOLDER_ID),
             fake_crm_responses.GET_PROJECT_NOT_FOUND,
             api_errors.ApiExecutionError
         ),
         (
             'projects/{}'.format(fake_crm_responses.FAKE_PROJECT_ID),
             fake_crm_responses.GET_PROJECT_NOT_FOUND,
             api_errors.ApiExecutionError
         ),
         (
             'organizations/{}'.format(fake_crm_responses.FAKE_ORG_ID),
             fake_crm_responses.GET_PROJECT_NOT_FOUND,
             api_errors.ApiExecutionError
         ),
         (
             'bad_resource_id',
             None,
             ValueError
         ),
     ]
     for (resource_id, response, expected_exception) in test_cases:
         if response:
             http_mocks.mock_http_response(response, '403')
         with self.assertRaises(expected_exception):
             self.crm_api_client.get_org_policy(
                 resource_id,
                 fake_crm_responses.TEST_ORG_POLICY_CONSTRAINT)
    def test_get_project_org_policies(self):
        """Test get project org policies."""
        http_mocks.mock_http_response(fake_crm_responses.LIST_ORG_POLICIES)

        response = self.crm_api_client.get_project_org_policies(self.project_id)
        self.assertEqual([fake_crm_responses.TEST_ORG_POLICY_CONSTRAINT],
                         [r['constraint'] for r in response])
コード例 #13
0
    def test_get_curated_roles_raises(self):
        """Test get iam currated roles permission denied."""
        http_mocks.mock_http_response(fake_iam.PERMISSION_DENIED, '403')
        org_id = 'organizations/{}'.format(fake_iam.FAKE_ORG_ID)

        with self.assertRaises(api_errors.ApiExecutionError):
            self.iam_api_client.get_curated_roles(org_id)
コード例 #14
0
    def test_get_billing_info_not_found(self):
        """Test get project billing info handles project not found error."""
        http_mocks.mock_http_response(fake_cloudbilling.PROJECT_NOT_FOUND,
                                      '404')
        result = self.billing_api_client.get_billing_info(self.project_id)

        self.assertEquals({}, result)
コード例 #15
0
    def test_get_folder_raises_error(self):
        """Test get_folder() raises ApiExecutionError when HTTP error occurs."""
        http_mocks.mock_http_response(fake_crm_responses.GET_PROJECT_NOT_FOUND,
                                      '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.crm_api_client.get_folder(fake_crm_responses.FAKE_FOLDER_ID)
コード例 #16
0
 def test_get_text_file_raises(self):
     """Test get test file returns not found error."""
     http_mocks.mock_http_response(fake_storage.NOT_FOUND, '404')
     with self.assertRaises(storage.errors.HttpError):
         self.gcs_api_client.get_text_file(
             'gs://{}/{}'.format(fake_storage.FAKE_BUCKET_NAME,
                                 fake_storage.FAKE_OBJECT_NAME))
コード例 #17
0
    def test_get_project_error(self):
        """Test the error handling."""
        http_mocks.mock_http_response(fake_crm_responses.GET_PROJECT_NOT_FOUND,
                                      '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.crm_api_client.get_project(self.project_id)
コード例 #18
0
    def test_get_billing_account_sinks_raises(self):
        """Test get logging billing account sinks permission denied."""
        http_mocks.mock_http_response(fake_sd_logging.PERMISSION_DENIED, '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.logging_api_client.get_billing_account_sinks(
                fake_sd_logging.FAKE_BILLING_ACCOUNT_ID)
コード例 #19
0
    def test_get_projects_api_error(self):
        """Test get_projects() raises ApiExecutionError on HTTP error."""
        http_mocks.mock_http_response(fake_crm_responses.GET_PROJECT_NOT_FOUND,
                                      '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            list(self.crm_api_client.get_projects('projects'))
コード例 #20
0
    def test_get_organization_sinks_raises(self):
        """Test get logging organization sinks permission denied."""
        http_mocks.mock_http_response(fake_sd_logging.PERMISSION_DENIED, '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.logging_api_client.get_organization_sinks(
                fake_sd_logging.FAKE_ORG_ID)
コード例 #21
0
    def test_get_instance_not_found(self):
        http_mocks.mock_http_response(fae.APP_NOT_FOUND, '404')
        response = self.ae_api_client.get_instance(
            fae.FAKE_PROJECT_ID, fae.FAKE_SERVICE_ID, fae.FAKE_VERSION_ID,
            fae.FAKE_INSTANCE_ID)

        self.assertEqual({}, response)
コード例 #22
0
    def test_get_folder_sinks_raises(self):
        """Test get logging folder sinks not found."""
        http_mocks.mock_http_response(fake_sd_logging.NOT_FOUND, '404')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.logging_api_client.get_folder_sinks(
                fake_sd_logging.FAKE_ORG_ID)
コード例 #23
0
ファイル: iam_test.py プロジェクト: zhuzeng/forseti-security
    def test_get_service_account_iam_policy_raises(self):
        """Test get iam project service accounts not found."""
        http_mocks.mock_http_response(fake_iam.PERMISSION_DENIED, '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.iam_api_client.get_service_account_iam_policy(
                fake_iam.FAKE_SERVICEACCOUNT_NAME)
コード例 #24
0
    def test_get_project_iam_policies(self):
        """Test get project IAM policies."""
        http_mocks.mock_http_response(fake_crm_responses.GET_IAM_POLICY)

        response = self.crm_api_client.get_project_iam_policies(
            'foo', self.project_id)
        self.assertTrue('bindings' in response)
コード例 #25
0
 def test_update_firewall_rule_errors(self, name, response, status,
                                      expected_exception):
     """Verify error conditions for update firewall rule."""
     http_mocks.mock_http_response(response, status)
     with self.assertRaises(expected_exception):
         self.gce_api_client.update_firewall_rule(
             self.project_id, rule=fake_compute.FAKE_FIREWALL_RULE)
コード例 #26
0
    def test_get_org_iam_policies_raises_error(self):
        """Test get_org_iam_policies() raises ApiExecutionError on error."""
        http_mocks.mock_http_response(fake_crm_responses.GET_PROJECT_NOT_FOUND,
                                      '403')

        with self.assertRaises(api_errors.ApiExecutionError):
            self.crm_api_client.get_org_iam_policies('foo', self.project_id)
コード例 #27
0
    def test_get_quota(self):
        """Test get quota."""
        http_mocks.mock_http_response(fake_compute.GET_PROJECT_RESPONSE)

        results = self.gce_api_client.get_quota(self.project_id,
                                                metric='SNAPSHOTS')
        self.assertEquals(fake_compute.GET_QUOTA_RESPONSE, results)
コード例 #28
0
    def test_get_folder(self):
        """Test get_folder()."""
        http_mocks.mock_http_response(fake_crm_responses.GET_FOLDER)
        folder_id = fake_crm_responses.FAKE_FOLDER_ID

        response = self.crm_api_client.get_folder(folder_id)
        self.assertEqual('folders/{}'.format(folder_id), response.get('name'))
コード例 #29
0
    def test_get_disks(self):
        """Test get disks."""
        http_mocks.mock_http_response(fake_compute.DISKS_AGGREGATED_LIST)

        results = self.gce_api_client.get_disks(self.project_id)
        self.assertEquals(fake_compute.EXPECTED_DISKS_SELFLINKS,
                          [r.get('selfLink') for r in results])
コード例 #30
0
    def test_get_bucket_acls(self):
        """Test get bucket acls."""
        http_mocks.mock_http_response(fake_storage.GET_BUCKET_ACL)

        results = self.gcs_api_client.get_bucket_acls(
            fake_storage.FAKE_BUCKET_NAME)
        self.assertEqual(3, len(results))