Example #1
0
    def test_proxy_ssl_cert(self):
        obj = HTTPClient()
        obj.add_proxy_settings({"ssl-cert": "i am server side cert",
                                "ssl-client-cert": "i am client side cert"})

        self.assertEqual(obj.session.verify, 'i am server side cert')
        self.assertEqual(obj.session.cert, 'i am client side cert')
    def test_download_fail(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        self.assertRaises(
            TaurusNetworkError,
            lambda: obj.download_file('http://non.existent.com/', tmpfile))
    def test_download_404(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        self.assertRaises(
            TaurusNetworkError,
            lambda: obj.download_file('http://localhost:8000/404', tmpfile))
Example #4
0
 def test_jvm_args(self):
     obj = HTTPClient()
     obj.add_proxy_settings({"address": "http://localhost:3128",
                             "username": "******",
                             "password": "******"})
     jvm_args = obj.get_proxy_jvm_args()
     for protocol in ['http', 'https']:
         for key in ['proxyHost', 'proxyPort', 'proxyUser', 'proxyPass']:
             combo_key = protocol + '.' + key
             self.assertIn(combo_key, jvm_args)
Example #5
0
    def test_proxy_setup(self):
        obj = HTTPClient()
        obj.add_proxy_settings({"address": "http://*****:*****@localhost:3128')
        self.assertEqual(obj.session.proxies['https'], 'http://*****:*****@localhost:3128')
    def test_download_file(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        obj.download_file('http://localhost:8000/', tmpfile)

        self.assertTrue(os.path.exists(tmpfile))

        with open(tmpfile) as fds:
            contents = fds.read()

        self.assertGreaterEqual(len(contents), 0)
Example #7
0
    def test_download_file(self):
        obj = HTTPClient()
        fd, tmpfile = tempfile.mkstemp()
        os.close(fd)

        obj.download_file('http://httpbin.org/anything', tmpfile)

        self.assertTrue(os.path.exists(tmpfile))

        with open(tmpfile) as fds:
            contents = fds.read()

        self.assertGreaterEqual(len(contents), 0)
Example #8
0
 def get_http_client(self):
     if self._http_client is None:
         self._http_client = HTTPClient()
         self._http_client.add_proxy_settings(
             self.config.get("settings").get("proxy"))
     return self._http_client
Example #9
0
 def test_request_fail(self):
     obj = HTTPClient()
     self.assertRaises(TaurusNetworkError, lambda: obj.request('GET', 'http://non.existent.com/'))
Example #10
0
 def test_request(self):
     obj = HTTPClient()
     resp = obj.request('GET', 'http://localhost:8000/')
     self.assertTrue(resp.ok)
Example #11
0
 def test_request(self):
     obj = HTTPClient()
     resp = obj.request('GET', 'http://httpbin.org/status/200')
     self.assertTrue(resp.ok)
Example #12
0
    def test_download_404(self):
        obj = HTTPClient()
        fd, tmpfile = tempfile.mkstemp()
        os.close(fd)

        self.assertRaises(TaurusNetworkError, lambda: obj.download_file('http://httpbin.org/status/404', tmpfile))