phenny-1/modules/test/test_archwiki.py

78 lines
2.2 KiB
Python
Raw Normal View History

2012-06-15 23:04:44 -04:00
"""
test_archwiki.py - tests for the arch wiki module
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
import unittest
2018-03-22 12:40:57 -04:00
from mock import MagicMock
2012-06-15 23:04:44 -04:00
from modules import archwiki
2018-03-22 12:40:57 -04:00
import wiki
2012-06-15 23:04:44 -04:00
class TestArchwiki(unittest.TestCase):
def setUp(self):
self.phenny = MagicMock()
2018-03-22 12:40:57 -04:00
self.input = MagicMock()
self.term = None
self.section = None
def prepare(self):
if self.section:
self.text = self.term + '#' + self.section
url_text = wiki.format_term(self.term) +\
'#' + wiki.format_section(self.section)
else:
self.text = self.term
url_text = wiki.format_term(self.term)
self.input.group = lambda x: [None, self.text][x]
self.url = 'https://wiki.archlinux.org/index.php/{0}'.format(url_text)
def check_snippet(self, output):
self.assertIn(self.url, output)
for keyword in self.keywords:
self.assertIn(keyword, output)
2012-06-15 23:04:44 -04:00
def test_awik(self):
2018-03-22 12:40:57 -04:00
self.term = "OpenDMARC"
self.prepare()
2012-06-15 23:04:44 -04:00
2018-03-22 12:40:57 -04:00
archwiki.awik(self.phenny, self.input)
2012-06-15 23:04:44 -04:00
out = self.phenny.say.call_args[0][0]
2018-03-22 12:40:57 -04:00
self.keywords = ['policy', 'mail', 'transfer', 'providers']
self.check_snippet(out)
def test_awik_fragment(self):
self.term = "KVM"
self.section = "Kernel support"
self.prepare()
archwiki.awik(self.phenny, self.input)
out = self.phenny.say.call_args[0][0]
self.keywords = ['kernel', 'modules', 'KVM', 'VIRTIO']
self.check_snippet(out)
2012-06-15 23:04:44 -04:00
2012-06-24 00:55:37 -04:00
def test_awik_invalid(self):
2018-03-22 12:40:57 -04:00
self.term = "KVM"
self.section = "Enabling KSM"
self.prepare()
2012-06-24 00:55:37 -04:00
2018-03-22 12:40:57 -04:00
archwiki.awik(self.phenny, self.input)
out = self.phenny.say.call_args[0][0]
message = "No '{0}' section found.".format(self.section)
self.assertEqual(out, '"{0}" - {1}'.format(message, self.url))
2012-06-24 00:55:37 -04:00
2012-06-15 23:04:44 -04:00
def test_awik_none(self):
2018-03-22 12:40:57 -04:00
self.term = "Ajgoajh"
self.prepare()
archwiki.awik(self.phenny, self.input)
out = self.phenny.say.call_args[0][0]
2012-06-15 23:04:44 -04:00
2018-03-22 12:40:57 -04:00
expected = "Can't find anything in the ArchWiki for \"{0}\"."
self.assertEqual(out, expected.format(self.text))