Page MenuHomePhabricator
Paste P3248

Design for tests/ v2.0

Authored by darthbhyrava on Jun 15 2016, 3:08 PM.
# -*- coding: utf-8 -*-
"""Test suite for the thanks script"""
# (C) Pywikibot team, 2016
from __future__ import absolute_import, unicode_literals
__version__ = '$Id: 27c941f3adf07987aeeb0a30c4428fc4290e26a5 $'
import pywikibot
from scripts.thanks import thank_rev
from tests.aspects import unittest, TestCase
class TestThankedRevs(TestCase):
""" Test if the revisions are being thanked """
family = 'test'
code= 'test'
def test_thank(self):
"""Makes an edit to test and thanks it. Then checks log to confirm."""
site = pywikibot.Site()
page = pywikibot.Page(site, u"Thank Tests")
# Check if logged in user is anonymous, and then proceed.
user = pywikibot.User(site, site.user())
if user.thanks_enabled:
#1 Make an edit on a test page
write_edit = site.editpage(page=page, text="Test Edit\n")
#2 Check Special:Log/thanks for latest thanks, store it.
log_initial = site.logevents(logtype='thanks', page=page)
print log_initial
#3 Extract the rev made in #1 thank it
rev_id = page.latest_revision_id
#Throws "APIError: invalidrecipient: You cannot thank yourself" error.
#We need to login with another user to thank, and then logout. Is this possible?
#4 Check Special:Log/thanks again for latest thanks, compare it with the earlier one.
log_final = site.logevents(logtype='thanks', page=page)
print log_final
if __name__ == '__main__':