tests.api_tests module#

API test module.

class tests.api_tests.DummyThrottle(site, *, mindelay=None, maxdelay=None, writedelay=None)[source]#

Bases: Throttle

Dummy Throttle class.

Parameters:
  • site (Union[pywikibot.site.BaseSite, str]) –

  • mindelay (Optional[int]) –

  • maxdelay (Optional[int]) –

  • writedelay (Optional[Union[int, float]]) –

lag(lag)[source]#

Override lag method, save the lag value and exit the api loop.

class tests.api_tests.TestApiFunctions(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, DefaultSiteTestCase

API Request object test class.

abstract_class = False#
code = 'test'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
testObjectCreation()[source]#

Test api.Request() constructor with implicit site creation.

class tests.api_tests.TestCachedRequest(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, DefaultSiteTestCase

Test API Request caching.

This test class does not use the forced test caching.

abstract_class = False#
cached = False#
code = 'test'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_internals()[source]#

Test the caching of CachedRequest by faking a unique request.

test_normal_use()[source]#

Test the caching of CachedRequest with an ordinary request.

class tests.api_tests.TestDryApiFunctions(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

API Request object test class.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
testObjectCreation()[source]#

Test api.Request() constructor.

test_mixed_mode()[source]#

Test if parameters is used with kwargs.

class tests.api_tests.TestDryListGenerator(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, TestCase

Test ListGenerator.

abstract_class = False#
code = 'en'#
dry = True#
family = 'wikipedia'#
setUp()[source]#

Set up test case.

site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#
test_namespace_none()[source]#

Test ListGenerator set_namespace with None.

test_namespace_zero()[source]#

Test ListGenerator set_namespace with 0.

class tests.api_tests.TestDryOptionSet(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, DefaultDrySiteTestCase

OptionSet class test class.

abstract_class = False#
code = 'test'#
dry = True#
family = 'wikipedia'#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_mutable_mapping()[source]#

Test keys, values and items from MutableMapping.

class tests.api_tests.TestDryPageGenerator(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, TestCase

Dry API PageGenerator object test class.

abstract_class = False#
code = 'en'#
dry = True#
family = 'wikipedia'#
setUp()[source]#

Set up test case.

site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#
test_initial_limit()[source]#

Test the default limit.

test_limit_omit()[source]#

Test that limit omitted is the same as limit None.

test_limit_range()[source]#

Test that PageGenerator yields the requested amount of pages.

test_limit_zero()[source]#

Test that a limit of zero is the same as limit None.

test_namespace()[source]#

Test PageGenerator set_namespace.

test_results()[source]#

Test that PageGenerator yields pages with expected attributes.

test_set_limit_as_number()[source]#

Test setting the limit using an int.

test_set_limit_as_string()[source]#

Test setting the limit using an int cast into a string.

test_set_limit_not_number()[source]#

Test setting the limit to not a number.

titles = ('Broadcaster (definition)', 'Wiktionary', 'Broadcaster.com', 'Wikipedia:Disambiguation')#
class tests.api_tests.TestDryQueryGeneratorNamespaceParam(*args, **kwargs)[source]#

Bases: DisconnectedSiteMixin, TestCase

Test setting of namespace param with ListGenerator.

Generators with different characteristics are used. site._paraminfo is not always faithful to API, but serves the purpose here.

abstract_class = False#
code = 'en'#
dry = True#
family = 'wikipedia'#
setUp()[source]#

Set up test case.

site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#
test_namespace_for_module_with_no_limit()[source]#

Test PageGenerator set_namespace.

test_namespace_multi()[source]#

Test ListGenerator set_namespace when multi.

test_namespace_non_multi()[source]#

Test ListGenerator set_namespace when non multi.

test_namespace_none()[source]#

Test ListGenerator set_namespace with None.

test_namespace_param_is_not_settable()[source]#

Test ListGenerator support_namespace.

test_namespace_resolve_failed()[source]#

Test ListGenerator set_namespace when resolve fails.

class tests.api_tests.TestLagpattern(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, DefaultSiteTestCase

Test the lag pattern.

abstract_class = False#
cached = False#
code = 'test'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_individual_patterns()[source]#

Test api lagpattern with example patterns.

test_valid_lagpattern()[source]#

Test whether api lagpattern is valid.

class tests.api_tests.TestLazyLoginBase(*args, **kwargs)[source]#

Bases: TestCase

Test that it tries to login when read API access is denied.

Because there is no such family configured it creates an AutoFamily and BaseSite on it’s own. It’s testing against steward.wikimedia.org.

These tests are split into two subclasses as only the first failed login behaves as expected. All subsequent logins will raise an APIError, making it impossible to test two scenarios with the same APISite object.

abstract_class = True#
hostname = 'steward.wikimedia.org'#
classmethod setUpClass()[source]#

Set up steward Family.

class tests.api_tests.TestLazyLoginNoUsername(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestLazyLoginBase

Test no username.

abstract_class = False#
net = True#
sites = {'steward.wikimedia.org': {'hostname': 'steward.wikimedia.org'}}#
test_access_denied_no_username(error, warning)[source]#

Test the query without a username.

class tests.api_tests.TestLazyLoginNotExistUsername(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestLazyLoginBase

Test missing username.

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

Patch the LoginManager to avoid UI interaction.

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

Restore the original LoginManager.

test_access_denied_notexist_username(error, warning, output)[source]#

Test the query with a username which does not exist.

class tests.api_tests.TestOptionSet(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestCase

OptionSet class test class.

abstract_class = False#
code = 'en'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#
test_lazy_load()[source]#

Test OptionSet with delayed site initialisation.

test_non_lazy_load()[source]#

Test OptionSet with initialised site.

class tests.api_tests.TestOtherSubmodule(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestCase

Test handling multiple different modules having submodules.

abstract_class = False#
code = 'mediawiki'#
family = 'mediawiki'#
net = True#
site = True#
sites = {'mediawiki:mediawiki': {'code': 'mediawiki', 'family': 'mediawiki'}}#
test_other_submodule()[source]#

Test another module apart from query having submodules.

class tests.api_tests.TestParamInfo(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, DefaultSiteTestCase

Test ParamInfo.

abstract_class = False#
code = 'test'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_attributes()[source]#

Test attributes method.

test_generators()[source]#

Test requesting the generator parameter.

test_init()[source]#

Test common initialization.

test_init_pageset()[source]#

Test initializing with only the pageset.

test_init_query_first()[source]#

Test init where it first adds query and then main.

test_module_paths()[source]#

Test module paths use the complete paths.

test_multiple_modules()[source]#

Test requesting multiple modules in one fetch.

test_new_mode()[source]#

Test the new modules-only mode explicitly.

test_old_mode(*args)[source]#

Test the old mode explicitly.

test_prefix_map()[source]#

Test module prefixes use the path.

test_submodules()[source]#

Test another module apart from query having submodules.

test_with_invalid_module()[source]#

Test requesting different kind of invalid modules.

test_with_module_info()[source]#

Test requesting the module info.

test_with_module_revisions()[source]#

Test requesting the module revisions.

class tests.api_tests.TestParaminfoModules(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, DefaultSiteTestCase

Test loading all paraminfo modules.

abstract_class = False#
code = 'test'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:test': {'code': 'test', 'family': 'wikipedia'}}#
test_action_modules()[source]#

Test loading all action modules.

test_query_modules()[source]#

Test loading all query modules.

class tests.api_tests.TestPropertyGenerator(*args, **kwargs)[source]#

Bases: CheckHostnameMixin, TestCase

API PropertyGenerator object test class.

abstract_class = False#
code = 'en'#
family = 'wikipedia'#
net = True#
site = True#
sites = {'wikipedia:en': {'code': 'en', 'family': 'wikipedia'}}#
test_info()[source]#

Test PropertyGenerator with prop ‘info’.

test_many_continuations_limited()[source]#

Test PropertyGenerator with many limited props.

test_one_continuation()[source]#

Test PropertyGenerator with prop ‘revisions’.

test_two_continuations()[source]#

Test PropertyGenerator with prop ‘revisions’ and ‘coordinates’.

test_two_continuations_limited()[source]#

Test PropertyGenerator with many limited props and continuations.

class tests.api_tests.TestUrlEncoding(*args, **kwargs)[source]#

Bases: DisableSiteMixin, TestCase

Test encode_url() function.

abstract_class = False#
test_moving_special_tokens()[source]#

Test moving wpEditToken to the very end.

test_url_encoding_from_dict()[source]#

Test moving ‘token’ parameters from a dict to the end.

test_url_encoding_from_list()[source]#

Test moving ‘token’ parameters from a list to the end.

test_url_encoding_from_str()[source]#

Test encoding str values.

test_url_encoding_from_unicode()[source]#

Test encoding unicode values.