예제 #1
0
    def test_018_http(self):
        """ Test http post with mocked in responses giving back a
        failed response with headers.
        """

        # set up the mock test data
        def mock_request(**kwargs):
            raise req.RequestException

        http.requests.request = mock_request

        # run the test
        with self.assertRaises(VaporRequestError):
            http.post('http://test.url')
예제 #2
0
    def test_020_http(self):
        """ Test http post with mocked in responses giving back a
        failed response with headers. In this case the failure is
        due to some unknown exception.
        """

        # set up the mock test data
        def mock_request(**kwargs):
            raise Exception

        http.requests.request = mock_request

        # run the test
        with self.assertRaises(VaporError):
            http.post('http://test.url')
예제 #3
0
    def test_016_http(self):
        """ Test http post with mocked in responses giving back a
        "bad" response with headers.
        """

        # set up the mock test data
        def mock_request(**kwargs):
            resp = MockResponse({'TEST_HEADER': 'value'}, **kwargs)
            resp.status_code = 404
            return resp

        http.requests.request = mock_request

        # run the test
        with self.assertRaises(VaporHTTPError):
            http.post('http://test.url')
예제 #4
0
    def test_013_http(self):
        """ Test http post with mocked in responses giving back a
        "bad" response.
        """

        # set up the mock test data
        def mock_request(**kwargs):
            resp = MockResponse(**kwargs)
            resp.status_code = 500
            return resp

        http.requests.request = mock_request

        # run the test
        with self.assertRaises(VaporHTTPError):
            http.post('http://test.url')
예제 #5
0
    def test_02_endpoint(self):
        """ Hit the OpenDCRE 'test' endpoint to verify that it is running.
        """
        r = http.post(PREFIX + '/test')
        self.assertTrue(http.request_ok(r.status_code))

        response = r.json()
        self.assertEqual(response['status'], 'ok')
예제 #6
0
    def test_02_version(self):
        """ Hit the OpenDCRE versionless version endpoint to verify it is
        running the correct API version.
        """
        # remove the last 4 chars (the api version) from the prefix as this endpoint
        # is version-less.
        r = http.post(PREFIX[:-4] + '/version')
        self.assertTrue(http.request_ok(r.status_code))

        response = r.json()
        self.assertEqual(response['version'], __api_version__)
예제 #7
0
    def test_012_http(self):
        """ Test http post with mocked in responses giving back a
        "good" response with headers.
        """

        # set up the mock test data
        def mock_request(**kwargs):
            return MockResponse({'TEST_HEADER': 'value'}, **kwargs)

        http.requests.request = mock_request

        # run the test
        r = http.post('http://test.url')

        self.assertEqual(r.headers, {'TEST_HEADER': 'value'})
        self.assertEqual(r.status_code, 200)
예제 #8
0
    def test_024_http(self):
        """ Test http post, passing in some kwargs as well. While not
        typically the case, we will have the response "echo" back all the
        kwargs to test that all the kwargs we set are making it to the
        request call.
        """

        # set up the mock test data
        def mock_request(**kwargs):
            return MockResponse(**kwargs)

        http.requests.request = mock_request

        # run the test
        r = http.post('http://test.url', key1='test', timeout=10)

        self.assertEqual(r.headers, {})
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.key1, 'test')
        self.assertEqual(r.timeout, 10)
        self.assertEqual(r.method, http.POST)
        self.assertEqual(r.url, 'http://test.url')
예제 #9
0
 def test_022_http(self):
     """ Test issuing an http call without providing the needed args.
     """
     with self.assertRaises(TypeError):
         http.post()