def testPutMethodWithNoData(self): """ Test making a PUT call with no data. """ response = self.app.put("/", status="*", headers=self.headers) self.assertIn("Metric data is missing", response.body) assertions.assertBadRequest(self, response)
def testPostWithoutInstanceId(self): """ Test for post '/_instances/region/namespace/instanceId' without instanceId response is validated for appropriate headers, body and status This invokes post call with without instanceId """ response = self.app.post("/us-west-2/AWS/EC2/", headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertIn("Invalid request", response.body)
def testCreateModelWithInvalidMetricArg(self): """ Test for the invalid metric field in json. """ data = utils.jsonEncode(self.modelsTestData["create_invalid_metric_data"]) response = self.app.put("/", data, status="*", headers=self.headers) assertions.assertBadRequest(self, response, "json") response = self.app.get("/", headers=self.headers) self.assertFalse(json.loads(response.body), "Model actually created with invalid metric")
def testDeleteMultipleinstancesWithInvalidData(self): """ Test for post '/_instances' response is validated for appropriate headers, body and status invoke delete with invalid Instance id """ params = [] response = self.app.delete("", params=params, headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertIn("Invalid request", response.body)
def testPostMultipleWithInstanceToIncorrectRegion(self): """ Test for post '/_instances' response is validated for appropriate headers, body and status invoke post with valid instance id to incorrect region """ params = [VALID_EC2_INSTANCES["jenkins-master"]] response = self.app.post("/us-east-1/AWS/EC2", params=app_utils.jsonEncode(params), headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertIn("InvalidArgumentsError", response.body)
def testPostMultipleWithNonJsonData(self): """ Test for '/_instances' response is validated for appropriate headers, body and status Invoke post with non-json data """ params = [] response = self.app.post("/us-west-2/AWS/EC2", params=params, headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertIn("Invalid request", response.body)
def testPostMultipleWithEmptyData(self): """ Test for post '/_instances' response is validated for appropriate headers, body and status Invoke post with empty data """ params = [] response = self.app.post("/us-west-2/AWS/EC2", params=app_utils.jsonEncode(params), headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertIn("InvalidArgumentsError", response.body)
def testPostWithInvalidNamespace(self): """ Test for post '/_instances/region/namespace/instanceId' response is validated for appropriate headers, body and status Invoke Api call with namespace that does not exists """ region = "us-west-2" namespace = "foo" instanceId = VALID_EC2_INSTANCES["jenkins-master"]["instanceId"] response = self.app.post("/%s/AWS/%s/%s" % (region, namespace, instanceId), headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertIn("Not supported.", response.body)