tests.http_tests module#

Tests for http module.

class tests.http_tests.BinaryTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestCase

Get binary file using requests and pywikibot.

abstract_class = False#
net = True#
classmethod setUpClass()[source]#

Set up test class.

sites = {'upload.wikimedia.org': {'hostname': 'upload.wikimedia.org'}}#
test_http()[source]#

Test with http, standard http interface for pywikibot.

test_requests()[source]#

Test with requests, underlying package.

url = 'https://upload.wikimedia.org/wikipedia/commons/f/fc/MP_sounds.png'#
class tests.http_tests.CharsetTestCase(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test that HttpRequest correct handles the charsets given.

CODEC_CANT_DECODE_RE = "codec can't decode byte"#
LATIN1_BYTES = b'\xe4\xf6\xfc'#
STR = 'äöü'#
UTF8_BYTES = b'\xc3\xa4\xc3\xb6\xc3\xbc'#
abstract_class = False#
test_charset_not_last()[source]#

Test charset not last part of content-type header.

test_code_charset()[source]#

Test decoding with different charsets and invalid header charset.

test_content_type_application_json_without_charset()[source]#

Test decoding without explicit charset but JSON content.

test_content_type_sparql_json_without_charset()[source]#

Test decoding without explicit charset but JSON content.

test_content_type_xml()[source]#

Test xml content with encoding given in content.

test_get_charset_from_content_type()[source]#

Test get_charset_from_content_type function.

test_header_charset()[source]#

Test decoding with different charsets and valid header charset.

test_invalid_charset()[source]#

Test decoding with different and invalid charsets.

test_no_charset()[source]#

Test decoding without explicit charset.

test_no_content_type()[source]#

Test decoding without content-type (and then no charset).

test_same_charset()[source]#

Test decoding with explicit and equal charsets.

test_server_charset()[source]#

Test decoding with server explicit charset.

class tests.http_tests.DataBodyParameterTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, HttpbinTestCase

Test data and body params of fetch/request methods are equivalent.

abstract_class = False#
maxDiff = None#
net = True#
site = True#
sites = {'httpbin': {'hostname': 'httpbin.org'}}#
test_fetch()[source]#

Test that using the data and body params produce same results.

class tests.http_tests.DefaultUserAgentTestCase(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

User agent formatting tests using the default config format string.

abstract_class = False#
setUp()[source]#

Set up unit test.

tearDown()[source]#

Tear down unit test.

test_default_user_agent()[source]#

Config defined format string test.

class tests.http_tests.HttpTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestCase

Tests for http module.

abstract_class = False#
net = True#
site = True#
sites = {'www-wp': {'hostname': 'www.wikipedia.org'}}#
test_fetch()[source]#

Test http.fetch using http://www.wikipedia.org/.

class tests.http_tests.HttpsCertificateTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestCase

HTTPS certificate test.

CERT_VERIFY_FAILED_RE = 'certificate verify failed'#
abstract_class = False#
net = True#
sites = {'testssl-expire-r2i2.disig.sk': {'hostname': 'testssl-expire-r2i2.disig.sk'}}#
test_https_cert_error()[source]#

Test if http.fetch respects disabled ssl certificate validation.

class tests.http_tests.LiveFakeUserAgentTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, HttpbinTestCase

Test the usage of fake user agent.

abstract_class = False#
net = True#
setUp()[source]#

Set up the unit test.

site = True#
sites = {'httpbin': {'hostname': 'httpbin.org'}}#
tearDown()[source]#

Tear down unit test.

test_argument_values_changes()[source]#

Test fake_user_agent with argument value changes.

test_empty_valu()[source]#

Test fake_user_agent with empty value.

test_existing_headers()[source]#

Test fake_user_agent with existing headers.

test_overridden_domains()[source]#

Test fake_user_agent with manually overridden domains.

test_parameter_set_to_none()[source]#

Test fake_user_agent with parameter wrongly set to None.

class tests.http_tests.QueryStringParamsTestCase(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, HttpbinTestCase

Test the query string parameter of request methods.

The /get endpoint of httpbin returns JSON that can include an ‘args’ key with urldecoded query string parameters.

abstract_class = False#
net = True#
setUp()[source]#

Set up tests.

site = True#
sites = {'httpbin': {'hostname': 'httpbin.org'}}#
test_encoded_params()[source]#

Test fetch method with encoded parameters to be re-encoded internally.

HTTPBin returns the args in their urldecoded form, so what we put in should be the same as what we get out.

test_no_params()[source]#

Test fetch method with no parameters.

test_unencoded_params()[source]#

Test fetch method with unencoded parameters to be encoded internally.

HTTPBin returns the args in their urldecoded form, so what we put in should be the same as what we get out.

class tests.http_tests.TestGetAuthenticationConfig(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test http.get_authentication.

abstract_class = False#
setUp()[source]#

Set up test by configuring config.authenticate.

tearDown()[source]#

Tear down test by resetting config.authenticate.

test_url_based_authentication()[source]#

Test url-based authentication info.

class tests.http_tests.TestHttpStatus(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, HttpbinTestCase

Test HTTP status code handling and errors.

abstract_class = False#
net = True#
site = True#
sites = {'enwp': {'hostname': 'en.wikipedia.org'}, 'httpbin': {'hostname': 'httpbin.org'}, 'wikia': {'hostname': 'en.wikia.com'}}#
test_follow_redirects()[source]#

Test follow 301 redirects correctly.

test_http_504()[source]#

Test that a HTTP 504 raises the correct exception.

test_invalid_scheme()[source]#

Test invalid scheme.

test_server_not_found()[source]#

Test server not found exception.

class tests.http_tests.UserAgentTestCase(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

User agent formatting tests using a format string.

abstract_class = False#
test_user_agent()[source]#

Test http.user_agent function.

test_user_agent_username()[source]#

Test http.user_agent_username function.