Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

## 0.3.3 (2017-12-04)

* Parameters added to the endpoints of categories [lccruz]

## 0.3.2 (2017-10-25)

* Added base Headers in request.
Expand Down
4 changes: 2 additions & 2 deletions python_wpapi/python_wpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def get_taxonomy(self, slug):
endpoint = '{}/taxonomies/{}'.format(self.base_url, slug)
return self._request(endpoint)

def get_categories(self):
endpoint = '{}/categories'.format(self.base_url)
def get_categories(self, parameters='?per_page=10'):
endpoint = '{}/categories/{}'.format(self.base_url, parameters)
return self._request(endpoint)

def get_category(self, id, context='view'):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.2
current_version = 0.3.3
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name='python_wpapi',
version='0.3.2',
version='0.3.3',
description="Simple wrapper around the Wordpress REST API",
long_description=readme + '\n\n' + history,
author="Lucas Lobosque",
Expand Down
11 changes: 10 additions & 1 deletion tests/test_python_wpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,16 @@ def test_get_taxonomy(mock, api):
@patch.object(python_wpapi.WpApi, '_request')
def test_get_categories(mock, api):
api.get_categories()
mock.assert_called_with('http://base.url/wp-json/wp/v2/categories')
mock.assert_called_with('http://base.url/wp-json/wp/v2/categories/?per_page=10')

@patch.object(python_wpapi.WpApi, '_request')
def test_get_categories_with_20_items(mock, api):
categories_len = 20
mock.return_value = range(categories_len)
categories = api.get_categories('?per_page={}'.format(categories_len))
url_result = 'http://base.url/wp-json/wp/v2/categories/?per_page={}'.format(categories_len)
mock.assert_called_with(url_result)
assert len(categories) == categories_len

@patch.object(python_wpapi.WpApi, '_request')
def test_get_category(mock, api):
Expand Down