예제 #1
0
    def test_ssl_verification(self, mock_requests):
        """Test ssl usage"""
        # ensure error is raised if http is supplied and use_ssl is true
        with self.assertRaises(APIClientError) as conm:
            JSONAPI('http://example.org')
        exception = conm.exception
        expected = SSL_ERROR
        self.assertEqual(expected, str(exception))

        # ensure error is raised if https is supplied and use_ssl is false
        with self.assertRaises(APIClientError) as conm:
            JSONAPI('https://example.org', use_ssl=False)
        exception = conm.exception
        expected = SSL_ERROR2
        self.assertEqual(expected, str(exception))

        # test defaults to https
        api = JSONAPI('example.org')
        api._get()
        mock_requests.get.assert_called_with('https://example.org',
                                             timeout=None,
                                             headers=None)

        # use_ssl is False
        api = JSONAPI('example.org', use_ssl=False)
        api._get()
        mock_requests.get.assert_called_with('http://example.org',
                                             timeout=None,
                                             headers=None)
예제 #2
0
 def setUp(self):
     self.url = 'example.org'
     self.api = JSONAPI(self.url)