Beispiel #1
0
  def testModelHandlerPOSTModel(self, createModel, getMetricDisplayFieldsMock,
                                _engineMock):
    cols = []
    for key in METRIC_DISPLAY_FIELDS:
      m = Mock()
      m.configure_mock(name=key)
      cols.append(m)

    getMetricDisplayFieldsMock.return_value=cols

    metric = Mock(**dict((col, getattr(self.metric, col))
                         for col in METRIC_DISPLAY_FIELDS))
    metric.keys.return_value = [col for col in METRIC_DISPLAY_FIELDS]
    metric.name = self.metric.name

    createModel.return_value = metric

    params = {"type": "metric",
              "region": "us-east-1",
              "namespace": "AWS/EC2",
              "datasource": "cloudwatch",
              "metric": "CPUUtilization",
              "dimensions": {
                "InstanceId": "i-0c149c66"
              }}
    response = self.app.post("/", json.dumps(params), headers=self.headers)
    assertions.assertResponseStatusCode(self, response, 201)
    assertions.assertResponseHeaders(self, response, "json")
    self.assertTrue(createModel.called)
    def testGETInvalidSection(self):
        """
    Test for GET for '/_settings/section, List Some invalid Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("/dddd", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)
        self.assertEqual(app_utils.jsonDecode(response.body), {})
    def testGETInvalidSection(self):
        """
    Test for GET for '/_settings/section, List Some invalid Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("/dddd", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)
        self.assertEqual(app_utils.jsonDecode(response.body), {})
    def testGETValidSection(self):
        """
    Test for GET for '/_settings/section, List Some Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("/aws", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)

        result = app_utils.jsonDecode(response.body)
        self.assertIsInstance(result, dict)
        for key in set(self.configurable_options["aws"]):
            if key in settings_api.HIDDEN_SETTINGS["aws"]:
                self.assertNotIn(key, result)
            else:
                self.assertIn(key, result)
    def testGETValidSection(self):
        """
    Test for GET for '/_settings/section, List Some Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("/aws", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)

        result = app_utils.jsonDecode(response.body)
        self.assertIsInstance(result, dict)
        for key in set(self.configurable_options["aws"]):
            if key in settings_api.HIDDEN_SETTINGS["aws"]:
                self.assertNotIn(key, result)
            else:
                self.assertIn(key, result)
    def testSettingsHandlerDefault(self):
        """
    Test for GET for '/_settings', List All Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)

        result = app_utils.jsonDecode(response.body)
        self.assertIsInstance(result, dict)
        for config in self.configurable_options:
            self.assertTrue(result.has_key(config))
            for key in self.configurable_options[config]:
                if key in settings_api.HIDDEN_SETTINGS[config]:
                    self.assertNotIn(key, result[config])
                else:
                    self.assertIn(key, result[config])
    def testSettingsHandlerDefault(self):
        """
    Test for GET for '/_settings', List All Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)

        result = app_utils.jsonDecode(response.body)
        self.assertIsInstance(result, dict)
        for config in self.configurable_options:
            self.assertTrue(result.has_key(config))
            for key in self.configurable_options[config]:
                if key in settings_api.HIDDEN_SETTINGS[config]:
                    self.assertNotIn(key, result[config])
                else:
                    self.assertIn(key, result[config])
Beispiel #8
0
  def testModelHandlerPUTMonitorMetric(self,
                                       repositoryMock,
                                       createDatasourceAdapterMock,
                                       getMetricDisplayFieldsMock,
                                       quotaRepositoryMock,
                                       engineMock):

    cols = []
    for key in METRIC_DISPLAY_FIELDS:
      m = Mock()
      m.configure_mock(name=key)
      cols.append(m)

    getMetricDisplayFieldsMock.return_value=cols

    metric = Mock(**dict((col, getattr(self.metric, col))
                         for col in METRIC_DISPLAY_FIELDS))
    metric.keys.return_value = [col for col in METRIC_DISPLAY_FIELDS]
    metric.name = self.metric.name

    quotaRepositoryMock.getInstanceCount.return_value = 0
    repositoryMock.getMetric.return_value = metric

    params = {
        "region": "us-east-1",
        "namespace": "AWS/EC2",
        "datasource": "cloudwatch",
        "metric": "CPUUtilization",
        "dimensions": {
            "InstanceId": "i-0c149c66"
        }
    }

    response = self.app.put("/", json.dumps(params), headers=self.headers)
    assertions.assertResponseStatusCode(self, response, 201)
    assertions.assertResponseHeaders(self, response, "json")
    repositoryMock.getMetric.assert_called_once_with(
      engineMock.return_value.connect.return_value.__enter__.return_value,
      createDatasourceAdapterMock.return_value.monitorMetric.return_value)
 def testModelHandlerDELETEModel(self, deleteModel, _engineMock):
     response = self.app.delete("/12232-jn939", headers=self.headers)
     self.assertTrue(deleteModel.called)
     assertions.assertResponseStatusCode(self, response, 200)
     assertions.assertResponseHeaders(self, response, "json")