jenkins-bot has submitted this change and it was merged.
Change subject: Create classes (with UUIDs) for Flow boards, topics, and posts
......................................................................
Create classes (with UUIDs) for Flow boards, topics, and posts
This change will create four new classes representing Flow entities:
* FlowPage: a superclass for page-like Flow objects
* Board: Flow boards
* Topic: Flow topics
* Post: Flow posts
These classes implement UUID-related functionality, including properties
and private methods to load object data. This entails creating new API
hooks to perform calls for loading data from boards, topics, and posts.
Three tests have been added to test the proper working of this UUID
functionality.
Bug: T101146
Change-Id: I37691cd209b4ee9cc6aa03358bdc5d13fa9f1362
---
M docs/api_ref/tests/page_tests.rst
A pywikibot/flow.py
M pywikibot/page.py
M pywikibot/site.py
A tests/flow_tests.py
M tests/page_tests.py
6 files changed, 244 insertions(+), 27 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/api_ref/tests/page_tests.rst
b/docs/api_ref/tests/page_tests.rst
index aa9ffb5..3a18cca 100644
--- a/docs/api_ref/tests/page_tests.rst
+++ b/docs/api_ref/tests/page_tests.rst
@@ -22,8 +22,6 @@
:members:
.. autoclass:: tests.page_tests.TestPageRedirects
:members:
- .. autoclass:: tests.page_tests.TestFlow
- :members:
.. autoclass:: tests.page_tests.TestPageUserAction
:members:
.. autoclass:: tests.page_tests.TestPageDelete
diff --git a/pywikibot/flow.py b/pywikibot/flow.py
new file mode 100644
index 0000000..8645532
--- /dev/null
+++ b/pywikibot/flow.py
@@ -0,0 +1,137 @@
+# -*- coding: utf-8 -*-
+"""Objects representing Flow entities, like boards, topics, and posts."""
+#
+# (C) Pywikibot team, 2015
+#
+# Distributed under the terms of the MIT license.
+#
+from __future__ import unicode_literals
+
+__version__ = '$Id$'
+
+import logging
+
+from pywikibot.page import BasePage
+
+
+logger = logging.getLogger('pywiki.wiki.flow')
+
+
+# Flow page-like objects (boards and topics)
+class FlowPage(BasePage):
+
+ """
+ The base page for the Flow extension.
+
+ There should be no need to instantiate this directly.
+
+ Subclasses must provide a _load() method to load and cache
+ the object's internal data from the API.
+ """
+
+ def __init__(self, source, title=''):
+ """Constructor.
+
+ @param source: A Flow-enabled site or a Link or Page on such a site
+ @type source: Site, Link, or Page
+ @param title: normalized title of the page
+ @type title: unicode
+
+ @raise TypeError: incorrect use of parameters
+ @raise ValueError: use of non-Flow-enabled Site
+ """
+ super(FlowPage, self).__init__(source, title)
+
+ if not self.site.has_extension('Flow'):
+ raise ValueError('site is not Flow-enabled')
+
+ def _load_uuid(self):
+ """Load and save the UUID of the page."""
+ self._uuid = self._load()['workflowId']
+
+ @property
+ def uuid(self):
+ """Return the UUID of the page.
+
+ @return: UUID of the page
+ @rtype: unicode
+ """
+ if not hasattr(self, '_uuid'):
+ self._load_uuid()
+ return self._uuid
+
+
+class Board(FlowPage):
+
+ """A Flow discussion board."""
+
+ def _load(self):
+ """Load and cache the Board's data, derived from its topic list."""
+ if not hasattr(self, '_data'):
+ self._data = self.site.load_board(self)
+ return self._data
+
+
+class Topic(FlowPage):
+
+ """A Flow discussion topic."""
+
+ def _load(self):
+ """Load and cache the Topic's data."""
+ if not hasattr(self, '_data'):
+ self._data = self.site.load_topic(self)
+ return self._data
+
+
+# Flow non-page-like objects (currently just posts)
+class Post(object):
+
+ """A post to a Flow discussion topic."""
+
+ def __init__(self, page, uuid):
+ """
+ Constructor.
+
+ @param page: Flow topic or board
+ @type page: FlowPage
+ @param uuid: UUID of a Flow post
+ @type uuid: unicode
+
+ @raise TypeError: incorrect types of parameters
+ @raise ValueError: use of non-Flow-enabled Site or invalid UUID
+ """
+ if not isinstance(page, FlowPage):
+ raise TypeError('page must be a FlowPage object')
+
+ if not uuid:
+ raise ValueError('post UUID must be provided')
+
+ self._page = page
+ self._uuid = uuid
+
+ @property
+ def uuid(self):
+ """Return the UUID of the post.
+
+ @return: UUID of the post
+ @rtype: unicode
+ """
+ return self._uuid
+
+ @property
+ def site(self):
+ """Return the site associated with the post.
+
+ @return: Site associated with the post
+ @rtype: Site
+ """
+ return self._page.site
+
+ @property
+ def page(self):
+ """Return the page associated with the post.
+
+ @return: Page associated with the post
+ @rtype: FlowPage
+ """
+ return self._page
diff --git a/pywikibot/page.py b/pywikibot/page.py
index dfc538f..5bbb043 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -77,7 +77,7 @@
reading from or writing to the wiki. All other methods are delegated
to the Site object.
- Will be subclassed by Page and WikibasePage.
+ Will be subclassed by Page, WikibasePage, and FlowPage.
"""
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 238c133..130ddb8 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -5561,6 +5561,37 @@
comparison = data['compare']['*']
return comparison
+ # Flow API calls
+ @need_extension('Flow')
+ def load_board(self, page):
+ """Retrieve the data for a Flow board.
+
+ @param page: A Flow board
+ @type page: Board
+ @return: A dict representing the board's data.
+ @rtype: dict
+ """
+ title = page.title(withSection=False)
+ req = api.Request(site=self, action='flow', page=title,
+ submodule='view-topiclist')
+ data = req.submit()
+ return data['flow']['view-topiclist']['result']['topiclist']
+
+ @need_extension('Flow')
+ def load_topic(self, page):
+ """Retrieve the data for a Flow topic.
+
+ @param page: A Flow topic
+ @type page: Topic
+ @return: A dict representing the topic's data.
+ @rtype: dict
+ """
+ title = page.title(withSection=False)
+ req = api.Request(site=self, action='flow', page=title,
+ submodule='view-topic')
+ data = req.submit()
+ return data['flow']['view-topic']['result']['topic']
+
# aliases for backwards compatibility
isBlocked = redirect_func(is_blocked, old_name='isBlocked',
class_name='APISite')
diff --git a/tests/flow_tests.py b/tests/flow_tests.py
new file mode 100644
index 0000000..575fcb6
--- /dev/null
+++ b/tests/flow_tests.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+"""Tests for the flow module."""
+#
+# (C) Pywikibot team, 2015
+#
+# Distributed under the terms of the MIT license.
+#
+from __future__ import unicode_literals
+
+__version__ = '$Id$'
+
+import pywikibot
+import pywikibot.flow
+
+from tests.aspects import (
+ TestCase,
+)
+
+
+class TestFlowBasePage(TestCase):
+
+ """Test Flow pages using BasePage-defined methods."""
+
+ family = 'mediawiki'
+ code = 'mediawiki'
+
+ cached = True
+
+ def test_methods(self):
+ """Test basic Page methods on a Flow page."""
+ site = self.get_site()
+ page = pywikibot.Page(site, u'Talk:Sandbox')
+ self.assertEqual(page.exists(), True)
+ page.get()
+ self.assertEqual(page.isRedirectPage(), False)
+
+ def test_content_model(self):
+ """Test Flow page content model."""
+ site = self.get_site()
+ page = pywikibot.Page(site, u'Talk:Sandbox')
+ self.assertEqual(page.content_model, 'flow-board')
+
+
+class TestFlowLoading(TestCase):
+
+ """Test loading of Flow objects from the API."""
+
+ family = 'mediawiki'
+ code = 'mediawiki'
+
+ cached = True
+
+ def test_board_uuid(self):
+ """Test retrieval of Flow board UUID."""
+ site = self.get_site()
+ board = pywikibot.flow.Board(site, u'Talk:Sandbox')
+ self.assertEqual(board.uuid, u'rl7iby6wgksbpfno')
+
+ def test_topic_uuid(self):
+ """Test retrieval of Flow topic UUID."""
+ site = self.get_site()
+ topic = pywikibot.flow.Topic(site, u'Topic:Sh6wgo5tu3qui1w2')
+ self.assertEqual(topic.uuid, u'sh6wgo5tu3qui1w2')
+
+ def test_post_uuid(self):
+ """Test retrieval of Flow post UUID.
+
+ This doesn't really "load" anything from the API. It just tests
+ the property to make sure the UUID passed to the constructor is
+ stored properly.
+ """
+ site = self.get_site()
+ topic = pywikibot.flow.Topic(site, u'Topic:Sh6wgo5tu3qui1w2')
+ post = pywikibot.flow.Post(topic, u'sh6wgoagna97q0ia')
+ self.assertEqual(post.uuid, u'sh6wgoagna97q0ia')
diff --git a/tests/page_tests.py b/tests/page_tests.py
index a23d6c6..89ebac0 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -714,30 +714,6 @@
self.assertRaises(pywikibot.exceptions.NoPage, p3.get)
-class TestFlow(TestCase):
-
- """Test Flow pages using Page layer."""
-
- family = 'mediawiki'
- code = 'mediawiki'
-
- cached = True
-
- def test_methods(self):
- """Test basic Page methods on a Flow page."""
- site = self.get_site()
- page = pywikibot.Page(site, u'Talk:Sandbox')
- self.assertEqual(page.exists(), True)
- page.get()
- self.assertEqual(page.isRedirectPage(), False)
-
- def test_content_model(self):
- """Test Flow page content model."""
- site = self.get_site()
- page = pywikibot.Page(site, u'Talk:Sandbox')
- self.assertEqual(page.content_model, 'flow-board')
-
-
class TestPageUserAction(DefaultSiteTestCase):
"""Test page user actions."""
--
To view, visit https://gerrit.wikimedia.org/r/215392
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I37691cd209b4ee9cc6aa03358bdc5d13fa9f1362
Gerrit-PatchSet: 15
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 <[email protected]>
Gerrit-Reviewer: Happy5214 <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits