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 testCreateModelWithInvalidDimensionsArg(self): """ Test for the invalid dimension field in json. """ data = utils.jsonEncode(self.modelsTestData["create_invalid_dimension_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 dimension")
def testInstanceDefaultsHandlerPOSTInvalidRegion(self, _engineFactoryMock): """ Test for POST "/_instances/region/namespace/instanceId" with invalid region response is validated for appropriate headers, body and status """ response = self.app.post("/fake-region/AWS/EC2/abcd1234", headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertIn("Not supported.", response.body)
def testInstanceDefaultsHandlerPOSTWithoutInstanceId(self, _engineFactoryMock): """ Test for POST "/_instances/region/namespace/instanceId" without instanceId response is validated for appropriate headers, body and status """ 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 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 testDeleteInstancesHandlerNonJSONData(self, listMetricIDsMock, _engineFactoryMock): """ Test for Delete "/_instances" with non JSON input response is validated for appropriate headers, body and status """ response = self.app.delete("", params="params", headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertFalse(listMetricIDsMock.called)
def testDeleteInstancesHandlerEmptyData(self, listMetricIDsMock, _engineFactoryMock): """ Test for Delete "/_instances" with with empty input data response is validated for appropriate headers, body and status """ params = [] response = self.app.delete("", params=app_utils.jsonEncode(params), headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") self.assertFalse(listMetricIDsMock.called)
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 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 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 testInstanceDefaultsHandlerPOSTWithoutInstanceId( self, _engineFactoryMock): """ Test for POST "/_instances/region/namespace/instanceId" without instanceId response is validated for appropriate headers, body and status """ 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 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 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)
def testInstanceDefaultsHandlerPOST(self, listMetricIDsMock, _engineFactoryMock): """ Test for POST "/_instances/region/namespace/instanceId" response is validated for appropriate headers, body and status """ listMetricIDsMock.return_value = [] region = "us-west-2" # Currently we are not supporting certain namespaces # unsupportedNamespaces reflects such unsupported namespaces # These namespaces are currently validated for "400 Bad Request" # and expected error message. # Update this list with changes in namespace support unsupportedNamespaces = ("Billing", "StorageGateway") for namespace in unsupportedNamespaces: response = self.app.post("/%s/AWS/%s/abcd1234" % (region, namespace), headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") result = json.loads(response.body)["result"] self.assertTrue(result.startswith("Not supported.")) cwAdapter = datasource.createDatasourceAdapter("cloudwatch") supportedNamespaces = set() for resourceInfo in cwAdapter.describeSupportedMetrics().values(): for metricInfo in resourceInfo.values(): supportedNamespaces.add(metricInfo["namespace"]) for namespace in supportedNamespaces: response = self.app.post("/%s/%s/abcd1234" % (region, namespace), headers=self.headers) assertions.assertSuccess(self, response) result = app_utils.jsonDecode(response.body) self.assertIsInstance(result, dict) self.assertEqual(result, {"result": "success"})
def testInstanceDefaultsHandlerPOST( self, listMetricIDsMock, _engineFactoryMock): """ Test for POST "/_instances/region/namespace/instanceId" response is validated for appropriate headers, body and status """ listMetricIDsMock.return_value = [] region = "us-west-2" # Currently we are not supporting certain namespaces # unsupportedNamespaces reflects such unsupported namespaces # These namespaces are currently validated for "400 Bad Request" # and expected error message. # Update this list with changes in namespace support unsupportedNamespaces = ("Billing", "StorageGateway") for namespace in unsupportedNamespaces: response = self.app.post( "/%s/AWS/%s/abcd1234" % (region, namespace), headers=self.headers, status="*") assertions.assertBadRequest(self, response, "json") result = json.loads(response.body)["result"] self.assertTrue(result.startswith("Not supported.")) cwAdapter = datasource.createDatasourceAdapter("cloudwatch") supportedNamespaces = set() for resourceInfo in cwAdapter.describeSupportedMetrics().values(): for metricInfo in resourceInfo.values(): supportedNamespaces.add(metricInfo["namespace"]) for namespace in supportedNamespaces: response = self.app.post( "/%s/%s/abcd1234" % (region, namespace), headers=self.headers) assertions.assertSuccess(self, response) result = app_utils.jsonDecode(response.body) self.assertIsInstance(result, dict) self.assertEqual(result, {"result": "success"})
def testCreateModelEmpty(self, data, _engineMock): response = self.app.post("/", {}, headers=self.headers, status="*") assertions.assertBadRequest(self, response) self.assertTrue(data.called)