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"})
示例#2
0
 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)
示例#3
0
 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 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 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 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 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 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)
示例#9
0
 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)
示例#10
0
 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)
示例#11
0
 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)
示例#12
0
 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)
示例#13
0
 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)
示例#14
0
 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)
示例#15
0
  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")
示例#16
0
 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)
示例#17
0
 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)
示例#18
0
 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)
示例#19
0
    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")
示例#20
0
 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)
示例#21
0
 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)
示例#22
0
 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)
示例#23
0
 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)
示例#24
0
 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)
示例#25
0
 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"})
示例#27
0
 def testCreateModelEmpty(self, data, _engineMock):
   response = self.app.post("/", {}, headers=self.headers, status="*")
   assertions.assertBadRequest(self, response)
   self.assertTrue(data.called)