Skip to content

Commit

Permalink
0.3.12 (#27)
Browse files Browse the repository at this point in the history
* added tests for lang setting api_url; ensure lang is in lower case
* cleaned up set_api_url and fixed generate test data
* add contributors
  • Loading branch information
barrust committed Mar 18, 2017
1 parent 9787354 commit 46ffbc2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -96,10 +96,10 @@ information:
Pull requests are how you will be able to add new features, fix bugs, or update
documentation in the pymediawiki library. To create a pull request, you will
first need to fork the repository, make all necessary changes and then create
a pull request. There are a few guidelines for creating pull requests:
a pull request. There are a few guidelines for creating pull requests:

* All pull requests must be based off of the latest development branch and not
master
master (unless there is not a development branch!)

* If the PR only changes documentation, please add `[ci skip]` to the commit
message. To learn more, you can [read about skipping integration testing ](https://docs.travis-ci.com/user/customizing-the-build#Skipping-a-build)
Expand Down Expand Up @@ -159,3 +159,4 @@ pep8 mediawiki
A special thanks to all the code contributors to pymediawiki!

[@barrust](https://github.com/barrust) (Maintainer)
[@dan-blanchard](https://github.com/dan-blanchard) - Default URL conforms to passed in language
2 changes: 1 addition & 1 deletion docs/source/quickstart.rst
Expand Up @@ -59,7 +59,7 @@ Or one can update an already setup MediaWiki object:

.. code: python
>>> wikipedia.api_url = 'http://awoiaf.westeros.org/api.php'
>>> wikipedia.set_api_url('http://awoiaf.westeros.org/api.php')


Searching
Expand Down
10 changes: 5 additions & 5 deletions mediawiki/mediawiki.py
Expand Up @@ -16,7 +16,7 @@
from .utilities import (memoize)

URL = 'https://github.com/barrust/mediawiki'
VERSION = '0.3.11'
VERSION = '0.3.12'


class MediaWiki(object):
Expand All @@ -40,8 +40,8 @@ def __init__(self, url='http://{lang}.wikipedia.org/w/api.php', lang='en',
rate_limit_wait=timedelta(milliseconds=50)):
''' Init Function '''
self._version = VERSION
self._api_url = url.format(lang=lang)
self._lang = lang
self._lang = lang.lower()
self._api_url = url.format(lang=self._lang)
self._timeout = timeout
self._user_agent = ('python-mediawiki/VERSION-{0}'
'/({1})/BOT').format(VERSION, URL)
Expand Down Expand Up @@ -231,8 +231,8 @@ def set_api_url(self, api_url='http://{lang}.wikipedia.org/w/api.php',
'''
old_api_url = self._api_url
old_lang = self._lang
self._api_url = api_url.format(lang=lang)
self._lang = lang
self._lang = lang.lower()
self._api_url = api_url.format(lang=self._lang)
try:
self._get_site_info()
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_test_data.py
Expand Up @@ -48,7 +48,7 @@ def wrapper(*args, **kwargs):

class MediaWikiOverloaded(MediaWiki):
''' overloaded mediawiki class '''
def __init__(self, url='http://en.wikipedia.org/w/api.php', lang='en',
def __init__(self, url='http://{lang}.wikipedia.org/w/api.php', lang='en',
timeout=None, rate_limit=False,
rate_limit_wait=timedelta(milliseconds=50)):
''' overloaded init '''
Expand Down
30 changes: 29 additions & 1 deletion tests/mediawiki_test.py
Expand Up @@ -20,7 +20,7 @@

class MediaWikiOverloaded(MediaWiki):
''' Overload the MediaWiki class to change how wiki_request works '''
def __init__(self, url='http://en.wikipedia.org/w/api.php', lang='en',
def __init__(self, url='http://{lang}.wikipedia.org/w/api.php', lang='en',
timeout=None, rate_limit=False,
rate_limit_wait=timedelta(milliseconds=50)):
''' new init '''
Expand Down Expand Up @@ -76,6 +76,18 @@ def test_change_lang_same(self):
self.assertEqual(site.language, 'fr')
self.assertEqual(site.api_url, 'http://fr.wikipedia.org/w/api.php')

def test_api_lang_no_url(self):
''' test setting the language on init without api_url '''
site = MediaWikiOverloaded(lang='fr')
self.assertEqual(site.language, 'fr')
self.assertEqual(site.api_url, 'http://fr.wikipedia.org/w/api.php')

def test_api_lang_no_url_upper(self):
''' test setting the language on init without api_url upper case '''
site = MediaWikiOverloaded(lang='FR')
self.assertEqual(site.language, 'fr')
self.assertEqual(site.api_url, 'http://fr.wikipedia.org/w/api.php')

def test_change_lang_no_change(self):
''' test changing the language when url will not change '''
site = MediaWikiOverloaded(url='http://awoiaf.westeros.org/api.php')
Expand Down Expand Up @@ -109,6 +121,22 @@ def test_change_api_url(self):
self.assertEqual(site.api_version, response['api_version'])
self.assertEqual(site.extensions, response['extensions'])

def test_change_api_url_lang(self):
''' test changing the api url with only language '''
site = MediaWikiOverloaded()
self.assertEqual(site.api_url, 'http://en.wikipedia.org/w/api.php')
site.set_api_url(lang='fr')
self.assertEqual(site.api_url, 'http://fr.wikipedia.org/w/api.php')
self.assertEqual(site.language, 'fr')

def test_change_api_url_lang_upper(self):
''' test changing the api url with only language upper case '''
site = MediaWikiOverloaded()
self.assertEqual(site.api_url, 'http://en.wikipedia.org/w/api.php')
site.set_api_url(lang='FR')
self.assertEqual(site.api_url, 'http://fr.wikipedia.org/w/api.php')
self.assertEqual(site.language, 'fr')

def test_change_user_agent(self):
''' test changing the user agent '''
site = MediaWikiOverloaded()
Expand Down

0 comments on commit 46ffbc2

Please sign in to comment.