diff --git a/tests/test_adapters.py b/tests/test_adapters.py index f12b7f2..9cfe6e2 100644 --- a/tests/test_adapters.py +++ b/tests/test_adapters.py @@ -1,46 +1,40 @@ # -*- coding: utf-8 -*- - import ssl -import sure # noqa import urllib3 +import pytest from cfscrape import CloudflareAdapter -class TestCloudflareAdapter: +@pytest.fixture +def adapter(): + adapter = CloudflareAdapter() + yield adapter + adapter.close() - def test_create_adapter(self): - adapter = CloudflareAdapter() - adapter.should.be.a("requests.adapters.HTTPAdapter") - adapter.close() - def test_get_connection(self): - adapter = CloudflareAdapter() +def test_create_adapter(adapter): + assert isinstance(adapter, urllib3.HTTPAdapter) - conn = adapter.get_connection("https://127.0.0.1", None) - conn.conn_kw.should.be.a("dict") - conn.conn_kw.should.have.key("ssl_context") - ssl_context = conn.conn_kw["ssl_context"] +def test_get_connection(adapter): + conn = adapter.get_connection("https://127.0.0.1", None) - # This should be ssl.SSLContext unless pyOpenSSL is installed. - # If pyOpenSSL is injected into urllib3, this should still work. - try: - assert isinstance(ssl_context, urllib3.contrib.pyopenssl.PyOpenSSLContext) - except BaseException: - assert isinstance(ssl_context, ssl.SSLContext) + assert isinstance(conn.conn_kw, dict) + assert "ssl_context" in conn.conn_kw + ssl_context = conn.conn_kw["ssl_context"] - adapter.close() + # This should be ssl.SSLContext unless pyOpenSSL is installed. + # If pyOpenSSL is injected into urllib3, this should still work. + assert isinstance(ssl_context, (ssl.SSLContext, urllib3.contrib.pyopenssl.PyOpenSSLContext)) - def test_set_ciphers(self): - adapter = CloudflareAdapter() - # Reinitialize the pool manager with a different context - ctx = ssl.create_default_context() - adapter.init_poolmanager(1, 1, ssl_context=ctx) - # Check to see if the context remains the same without error - conn = adapter.get_connection('https://127.0.0.1', None) - conn.conn_kw.should.be.a("dict") - assert conn.conn_kw["ssl_context"] is ctx +def test_set_ciphers(adapter): + # Reinitialize the pool manager with a different context + ctx = ssl.create_default_context() + adapter.init_poolmanager(1, 1, ssl_context=ctx) - adapter.close() + # Check to see if the context remains the same without error + conn = adapter.get_connection('https://127.0.0.1', None) + assert isinstance(conn.conn_kw, dict) + assert conn.conn_kw["ssl_context"] is ctx