def post_to_flow_board(self, page, post): """Post message as a Flow topic.""" board = Board(page) header, rest = post.split('\n', 1) title = header.strip('=') content = rest.lstrip() board.new_topic(title, content)
def test_topiclist(self): """Test loading of topiclist.""" board = Board(self.site, 'Talk:Sandbox') i = 0 for topic in board.topics(limit=7): i += 1 if i == 10: break self.assertEqual(i, 10)
def test_create_topic(self): """Test creation of topic.""" content = 'If you can read this, the Flow code in Pywikibot works!' board = Board(self.site, 'Talk:Pywikibot test') topic = board.new_topic('Pywikibot test', content, 'wikitext') first_post = topic.replies()[0] wikitext = first_post.get(format='wikitext') self.assertIn('wikitext', first_post._content) self.assertNotIn('html', first_post._content) self.assertIsInstance(wikitext, unicode) self.assertEqual(wikitext, content)
def test_invalid_data(self): """Test invalid "API" data.""" board = Board(self.site, 'Talk:Pywikibot test') real_topic = Topic(self.site, 'Topic:Slbktgav46omarsd') # Topic.from_topiclist_data self.assertRaises(ValueError, Topic.from_topiclist_data, board, 'slbktgav46omarsd', {'stuff': 'blah'}) self.assertRaises(ValueError, Topic.from_topiclist_data, board, 'slbktgav46omarsd', {'posts': [], 'revisions': []}) self.assertRaises(ValueError, Topic.from_topiclist_data, board, 'slbktgav46omarsd', {'posts': {'slbktgav46omarsd': ['123']}, 'revisions': {'456': []}}) self.assertRaises(AssertionError, Topic.from_topiclist_data, board, 'slbktgav46omarsd', {'posts': {'slbktgav46omarsd': ['123']}, 'revisions': {'123': {'content': 789}}}) # Post.fromJSON self.assertRaises(ValueError, Post.fromJSON, real_topic, 'abc', {}) self.assertRaises(ValueError, Post.fromJSON, real_topic, 'abc', {'stuff': 'blah'}) self.assertRaises(ValueError, Post.fromJSON, real_topic, 'abc', {'posts': {'abc': ['123']}, 'revisions': {'456': []}}) self.assertRaises(AssertionError, Post.fromJSON, real_topic, 'abc', {'posts': {'abc': ['123']}, 'revisions': {'123': {'content': 789}}})
def test_illegal_arguments(self): """Test illegal method arguments.""" board = Board(self.site, 'Talk:Pywikibot test') real_topic = Topic(self.site, 'Topic:Slbktgav46omarsd') fake_topic = Topic(self.site, 'Topic:Abcdefgh12345678') # Topic.from_topiclist_data self.assertRaises(TypeError, Topic.from_topiclist_data, self.site, '', {}) self.assertRaises(TypeError, Topic.from_topiclist_data, board, 521, {}) self.assertRaises(TypeError, Topic.from_topiclist_data, board, 'slbktgav46omarsd', [0, 1, 2]) self.assertRaises(NoPage, Topic.from_topiclist_data, board, 'abc', {'stuff': 'blah'}) # Post.fromJSON self.assertRaises(TypeError, Post.fromJSON, board, 'abc', {}) self.assertRaises(TypeError, Post.fromJSON, real_topic, 1234, {}) self.assertRaises(TypeError, Post.fromJSON, real_topic, 'abc', []) self.assertRaises(NoPage, Post.fromJSON, fake_topic, 'abc', {'posts': [], 'revisions': []})
class TestBoardBasePageMethods(BasePageMethodsTestBase): """Test Flow board pages using BasePage-defined methods.""" family = 'mediawiki' code = 'mediawiki' def setUp(self): """Set up unit test.""" self._page = Board(self.site, 'Talk:Sandbox') super(TestBoardBasePageMethods, self).setUp() def test_basepage_methods(self): """Test basic Page methods on a Flow board page.""" self._test_invoke() self._test_return_datatypes() self.assertFalse(self._page.isRedirectPage()) self.assertEqual(self._page.latest_revision.parent_id, 0) def test_content_model(self): """Test Flow page content model.""" self.assertEqual(self._page.content_model, 'flow-board')
def test_board_uuid(self): """Test retrieval of Flow board UUID.""" board = Board(self.site, 'Talk:Sandbox') self.assertEqual(board.uuid, 'rl7iby6wgksbpfno')
def setUp(self): """Set up unit test.""" self._page = Board(self.site, 'Talk:Sandbox') super(TestLoadRevisionsCaching, self).setUp()
def setUp(self): """Set up unit test.""" self._page = Board(self.site, 'Talk:Sandbox') super(TestBoardBasePageMethods, self).setUp()
def setUp(self): """Set up unit test.""" self._page = Board(self.site, 'Project talk:Sandbox/Structured_Discussions_test') super().setUp()
def setUp(self): """Set up unit test.""" self._page = Board(self.site, 'Project_talk:Sandbox/Flow test') super(TestMediaWikiFlowSandbox, self).setUp()