diff --git a/.gitignore b/.gitignore index 085eaf9..001895b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ .DS_Store dist/* wp-config.cfg - -/docs/_build \ No newline at end of file +/docs/_build diff --git a/README.rst b/README.rst index 928273b..cc1bfaa 100644 --- a/README.rst +++ b/README.rst @@ -12,4 +12,7 @@ XML-RPC API methods provided by plugins. This library was developed against and tested on WordPress 3.5. This library is compatible with Python 2.6+ and 3.2+. -Please see docs for more information: http://python-wordpress-xmlrpc.rtfd.org \ No newline at end of file +This branch of python-wordpress-xmlrpc is tested on trunk of +WordPress 3.4 with the wp-xmlrpc-modernization plugin installed. + +Please see docs for more information: http://python-wordpress-xmlrpc.rtfd.org diff --git a/docs/ref/methods.rst b/docs/ref/methods.rst index 3bcb20f..15f056f 100644 --- a/docs/ref/methods.rst +++ b/docs/ref/methods.rst @@ -64,6 +64,11 @@ methods.users .. autoclass:: EditProfile(user) .. autoclass:: GetUsersBlogs() .. autoclass:: GetAuthors() + .. autoclass:: GetUsers([filter, fields]) + .. autoclass:: GetUser(user_id[, fields]) + .. autoclass:: NewUser(user) + .. autoclass:: EditUser(user_id, user) + .. autoclass:: DeleteUser(user_id[, reassign_id]) methods.media ------------- diff --git a/tests/test_users.py b/tests/test_users.py index 3cb2023..14b541e 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -70,3 +70,26 @@ def test_get_user_blogs(self): def test_get_authors(self): authors = self.client.call(users.GetAuthors()) self.assert_list_of_classes(authors, WordPressAuthor) + + @attr('users') + def test_user_lifecycle(self): + user = WordPressUser() + user.username = 'harrietsmith' + user.password = 'mysecretpassword' + user.email = 'harriet.smith@example.com' + user.role = 'subscriber' + user.last_name = 'Smith' + user_id = self.client.call(users.NewUser(user)) + self.assertTrue(user_id) + user.id = user_id + + user.first_name = 'Harriet' + response = self.client.call(users.EditUser(user.id, user)) + self.assertTrue(response) + + # re-fetch to confirm + user2 = self.client.call(users.GetUser(user.id)) + self.assertEqual(user.first_name, user2.first_name) + + response = self.client.call(users.DeleteUser(user.id)) + self.assertTrue(response) diff --git a/wordpress_xmlrpc/methods/users.py b/wordpress_xmlrpc/methods/users.py index e774c91..326fdc6 100644 --- a/wordpress_xmlrpc/methods/users.py +++ b/wordpress_xmlrpc/methods/users.py @@ -96,3 +96,82 @@ class GetAuthors(AuthenticatedMethod): """ method_name = 'wp.getAuthors' results_class = WordPressAuthor + + +class GetUsers(AuthenticatedMethod): + """ + Retrieve list of users in the blog. + + Parameters: + `filter`: optional `dict` of filters: + * `number` + * `offset` + * `role` + + `fields`: optional `list` of fields to return. Specific fields, or groups 'basic' or 'all'. + + Returns: `list` of :class:`WordPressUser` instances. + """ + method_name = 'wp.getUsers' + optional_args = ('filter', 'fields') + results_class = WordPressUser + + +class GetUser(AuthenticatedMethod): + """ + Retrieve an individual user. + + Parameters: + `user_id`: ID of the user + `fields`: (optional) `list` of fields to return. Specific fields, or groups 'basic' or 'all'. + + Returns: :class:`WordPressUser` instance. + """ + method_name = 'wp.getUser' + method_args = ('user_id',) + optional_args = ('fields',) + results_class = WordPressUser + + +class NewUser(AuthenticatedMethod): + """ + Create new user on the blog. + + Parameters: + `user`: A :class:`WordPressUser` instance with at least `username`, `password`, and `email`. + `send_mail`: (optional) Send a confirmation email to the new user. + + Returns: ID of the newly-created blog user (an integer). + """ + method_name = 'wp.newUser' + method_args = ('user',) + optional_args = ('send_mail',) + + +class EditUser(AuthenticatedMethod): + """ + Edit an existing blog post. + + Parameters: + `user_id`: ID of the user to edit. + `user`: `WordPressUser` instance. + + Returns: `True` on successful edit. + """ + method_name = 'wp.editUser' + method_args = ('user_id', 'user') + + +class DeleteUser(AuthenticatedMethod): + """ + Delete a blog user. + + Parameters: + `user_id`: ID of the blog user to delete. + `reassign_id`: ID of the blog user to reassign this user's posts to. + + Returns: `True` on successful deletion. + """ + method_name = 'wp.deleteUser' + method_args = ('user_id',) + optional_args = ('reassign_id',) diff --git a/wordpress_xmlrpc/wordpress.py b/wordpress_xmlrpc/wordpress.py index e1357b6..8919d56 100644 --- a/wordpress_xmlrpc/wordpress.py +++ b/wordpress_xmlrpc/wordpress.py @@ -186,6 +186,7 @@ class WordPressUser(WordPressBase): definition = { 'id': 'user_id', 'username': 'username', + 'password': 'password', 'roles': 'roles', 'nickname': 'nickname', 'url': 'url',