Exemplo n.º 1
0
    def testConnectAndCheckModelsResponseCode(self, getMock, reportIssueMock,
                                              removeIssueMock):
        """
    Test a request Response whose status code is not 200
    """
        url = "url"
        apiKey = "key"
        timeout = 1.0

        # Mock the returned value of requests.get, a requests.Response
        responseMock = Mock(spec=requests.models.Response)
        responseMock.status_code = 404
        getMock.return_value = responseMock
        emailParams = {"key": "val"}

        # Code under test
        modelsMonitor._connectAndCheckModels(url, apiKey, timeout, emailParams)

        getMock.assert_called_once_with(url,
                                        auth=(apiKey, ""),
                                        timeout=timeout,
                                        verify=False)
        removeIssueMock.assert_called_once_with(
            modelsMonitor._FLAG_REQUESTS_EXCEPTION)
        reportIssueMock.assert_called_once_with(
            modelsMonitor._FLAG_HTTP_STATUS_CODE, url,
            modelsMonitor._getIssueString("Received abnormal HTTP status code",
                                          404), {"key": "val"})
  def testConnectAndCheckModelsResponseCode(self,
                                            getMock,
                                            reportIssueMock,
                                            removeIssueMock):
    """
    Test a request Response whose status code is not 200
    """
    url = "url"
    apiKey = "key"
    timeout = 1.0

    # Mock the returned value of requests.get, a requests.Response
    responseMock = Mock(spec=requests.models.Response)
    responseMock.status_code = 404
    getMock.return_value = responseMock
    emailParams = {"key":"val"}

    # Code under test
    modelsMonitor._connectAndCheckModels(url, apiKey, timeout, emailParams)

    getMock.assert_called_once_with(url, auth=(apiKey, ""), timeout=timeout,
                                    verify=False)
    removeIssueMock.assert_called_once_with(
      ANY,
      modelsMonitor.Flags.REQUESTS_EXCEPTION)
    reportIssueMock.assert_called_once_with(
      modelsMonitor.Flags.HTTP_STATUS_CODE,
      url,
      modelsMonitor._getIssueString("Received abnormal HTTP status code", 404),
      {"key":"val"}
    )
Exemplo n.º 3
0
 def testGetIssueString(self):
     n = "name"
     msg = "watsup"
     res = modelsMonitor._getIssueString(n, msg)
     self.assertTrue(n in res)
     self.assertTrue(msg in res)
 def testGetIssueString(self):
   n = "name"
   msg = "watsup"
   res = modelsMonitor._getIssueString(n, msg)
   self.assertTrue(n in res)
   self.assertTrue(msg in res)