Page MenuHomePhabricator

flow_thanks_tests.py v1.0

Authored By
darthbhyrava
Jun 19 2016, 2:08 PM
Size
2 KB
Referenced Files
None
Subscribers
None

flow_thanks_tests.py v1.0

# -*- coding: utf-8 -*-
"""Test suite for the flow based thanks script."""
#
# (C) Pywikibot team, 2016
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals
import pywikibot
from scripts.flow_thanks import thank_flow_post
from pywikibot.flow import Board, Topic, Post
from tests.aspects import unittest, TestCase
class TestFlowThank(TestCase):
"""Test thanks for revisions."""
family = 'test'
code = 'test'
def test_topic (self):
"""
Method to test thanks for a Flow post
Note: This approach requires a new topic and flow post to be added atop
the Talk:Sandbox page between reruns, and will fail otherwise.
Alternatively, one could devise a method to use the post_ids list
in a better way.
"""
# A list which will store ids of posts from Talk:Sandbox, which can be
# thanked.
post_ids = []
site = pywikibot.Site()
# Getting the 'Talk:Sandbox' flow page on test:test
page = Board(self.site, 'Talk:Sandbox')
# Getting the a generator for topics on that page.
topics_list = page.topics(limit=5)
# The exception handling feature has been added to deal with the
# anomalous nature of 'Topic:Sel4ipu6maqlbm0d' which throws up a error.
#TODO: Fix the above.
try:
# Extracting each topic, and then the posts in each topic,
# and then appending these post_ids to a list.
for topic in topics_list:
post_list = topic.replies()
for post in post_list:
post_ids.append(post.uuid)
except Exception as a:
pass
# Checking log before the thanks action
log_initial = site.logevents(logtype='thanks', total=1)
for x in log_initial:
initial_id = x.logid()
# Thanking the most recent post on Talk:Sandbox
thank_flow_post(post_ids[0])
# Checking log for new thanks, and then comparing with earlier log.
log_final = site.logevents(logtype='thanks', total=1)
for x in log_final:
final_id = x.logid()
# Asserting that the ids are unequal, implying a successful
# thanks action.
self.assertNotEqual(initial_id, final_id)
if __name__ == "__main__":
unittest.main()

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3807870
Default Alt Text
flow_thanks_tests.py v1.0 (2 KB)

Event Timeline