def list(self, pageToken=None): if self.call_count >= len(self.responses): return http_fake.HttpRequestFake({}) else: response = self.responses[self.call_count] self.call_count += 1 return http_fake.HttpRequestFake(response)
def get(self, projectId): for p in self.projects: if p['projectId'] == projectId: return http_fake.HttpRequestFake(p) return http_fake.HttpRequestFake( errors.HttpError(http_fake.HttpResponseFake(403), b'permission denied'))
def get(self, name): self.service_to_get_count[name] = ( self.service_to_get_count.get(name, 0) + 1) self._get_times += 1 if self._get_times >= self._query_times: return http_fake.HttpRequestFake(ENABLED_SERVICE_RESPONSE) else: return http_fake.HttpRequestFake(DISABLED_SERVICE_RESPONSE)
def create(self, name, body): if 'invalid' in name: return http_fake.HttpRequestFake( errors.HttpError( http_fake.HttpResponseFake(400), b'invalid resource name')) else: self.key_count += 1 return http_fake.HttpRequestFake(FAKE_CREATE_KEY_RESPONSE)
def search(self, body): if self._is_google: return http_fake.HttpRequestFake( {'organizations': [{ 'displayName': 'google.com', }]}) else: return http_fake.HttpRequestFake({})
def create(self, body): for p in self.projects: if p['projectId'] == body['projectId']: return http_fake.HttpRequestFake( errors.HttpError(http_fake.HttpResponseFake(409), b'Requested entity already exists')) self.projects.append(body) return http_fake.HttpRequestFake( {'name': 'operations/cp.7730969938063130608'})
def getIamPolicy(self, bucket): if 'invalid' in bucket: return http_fake.HttpRequestFake(INVALID_IAM_POLICY) elif 'no_permission' in bucket: return http_fake.HttpRequestFake( errors.HttpError(http_fake.HttpResponseFake(403), b'permission denied')) else: return http_fake.HttpRequestFake(self.iam_policy)
def insert(self, project, body): bucket_name = body['name'] if project != PROJECT_ID: return http_fake.HttpRequestFake( errors.HttpError(http_fake.HttpResponseFake(403), b'permission denied')) elif 'invalid' in bucket_name: return http_fake.HttpRequestFake({'invalid': 'response'}) else: self.buckets.append(bucket_name) return http_fake.HttpRequestFake(body)
def create(self, name, body): if 'invalid' in body['accountId']: return http_fake.HttpRequestFake( errors.HttpError(http_fake.HttpResponseFake(400), b'invalid account id')) elif body['accountId'] in self.service_accounts: return http_fake.HttpRequestFake( errors.HttpError(http_fake.HttpResponseFake(409), b'service account already exists')) else: self.service_accounts.append(body['accountId']) return http_fake.HttpRequestFake({'name': name})
def get(self, projectId, zone, clusterId): ca = base64.standard_b64encode(FAKE_CA).decode('utf-8') if 'invalid_response' in clusterId: return http_fake.HttpRequestFake( json.loads(CLUSTER_GET_RESPONSE_INVALID)) if clusterId not in self.clusters_to_get_count: status = 'ERROR' else: self.clusters_to_get_count[clusterId][0] += 1 get_count, total_get_count = self.clusters_to_get_count[clusterId] if get_count < total_get_count: status = 'PROVISIONING' else: status = 'RUNNING' response = CLUSTER_GET_RESPONSE_TEMPLATE.format(clusterId, ca, status) return http_fake.HttpRequestFake(json.loads(response))
def create(self, projectId, zone, body): name = body['cluster']['name'] if 'fail' not in name: if 'first' in name: # (current_get_count, total_get_count) self.clusters_to_get_count[name] = [0, 1] else: self.clusters_to_get_count[name] = [0, 2] return http_fake.HttpRequestFake( {'name': 'operations/cp.7730969938063130608'})
def updateBillingInfo(self, name, body): self.project_billing_map[name] = body['billingAccountName'] if 'invalid' in name: return http_fake.HttpRequestFake({}) else: return http_fake.HttpRequestFake(BILLING_INFO_ENABLED)
def getIamPolicy(self, resource): if 'invalid' in resource: return http_fake.HttpRequestFake(INVALID_IAM_POLICY) else: return http_fake.HttpRequestFake(self.iam_policy)
def setIamPolicy(self, resource, body): if 'bindings' in body['policy']: self.iam_policy = body['policy'] return http_fake.HttpRequestFake(body['policy'])
def setIamPolicy(self, bucket, body): self.iam_policy = body return http_fake.HttpRequestFake(body)
def insert(self, bucket, body, media_body): del media_body if bucket not in self.bucket_files: self.bucket_files[bucket] = [] self.bucket_files[bucket].append(body['name']) return http_fake.HttpRequestFake(body)
def getServerConfig(self, name): del name return http_fake.HttpRequestFake( {'defaultClusterVersion': '1.9.7-gke.6'})
def list(self, project): del project return http_fake.HttpRequestFake(FAKE_BUCKET_LIST_RESPONSE)
def list(self): return http_fake.HttpRequestFake(BILLING_ACCOUNT_LIST_RESPONSE)
def getBillingInfo(self, name): if name in self.project_billing_map: return http_fake.HttpRequestFake(BILLING_INFO_ENABLED) else: return http_fake.HttpRequestFake(BILLING_INFO_DISABLED)
def enable(self, name): self.service_to_get_count.setdefault(name, 0) return http_fake.HttpRequestFake({ 'name': 'operations/cp.7730969938063130608' })