Exemplo n.º 1
0
    def testModelHandlerPUTModelCreate(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.put("/", json.dumps(params), headers=self.headers)
        assertions.assertResponseStatusCode(self, response, 201)
        assertions.assertResponseHeaders(self, response, "json")
        self.assertTrue(createModel.called)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    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), {})
Exemplo n.º 4
0
  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), {})
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
  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)
Exemplo n.º 7
0
    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])
Exemplo n.º 8
0
  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])
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
 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")