Update Wikipedia tests

master
Robin Richtsfeld 2018-03-22 17:40:57 +01:00
parent e91f3bd16b
commit a6c525ee1f
4 changed files with 170 additions and 54 deletions

1
.coverage Normal file

File diff suppressed because one or more lines are too long

View File

@ -2,38 +2,76 @@
test_archwiki.py - tests for the arch wiki module test_archwiki.py - tests for the arch wiki module
author: mutantmonkey <mutantmonkey@mutantmonkey.in> author: mutantmonkey <mutantmonkey@mutantmonkey.in>
""" """
import re
import unittest import unittest
from mock import MagicMock, Mock from mock import MagicMock
from modules import archwiki from modules import archwiki
import wiki
class TestArchwiki(unittest.TestCase): class TestArchwiki(unittest.TestCase):
def setUp(self): def setUp(self):
self.phenny = MagicMock() self.phenny = MagicMock()
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)
def test_awik(self): def test_awik(self):
input = Mock(groups=lambda: ['', "KVM"]) self.term = "OpenDMARC"
archwiki.awik(self.phenny, input) self.prepare()
archwiki.awik(self.phenny, self.input)
out = self.phenny.say.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^.* - https:\/\/wiki\.archlinux\.org\/index\.php\/KVM$',
out, flags=re.UNICODE) self.keywords = ['policy', 'mail', 'transfer', 'providers']
self.assertTrue(m) 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)
def test_awik_invalid(self): def test_awik_invalid(self):
term = "KVM#Enabling_KSM" self.term = "KVM"
input = Mock(groups=lambda: ['', term]) self.section = "Enabling KSM"
archwiki.awik(self.phenny, input) self.prepare()
self.phenny.say.assert_called_once_with( "Can't find anything in "\ archwiki.awik(self.phenny, self.input)
"the ArchWiki for \"{0}\".".format(term)) 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))
def test_awik_none(self): def test_awik_none(self):
term = "Ajgoajh" self.term = "Ajgoajh"
input = Mock(groups=lambda: ['', term]) self.prepare()
archwiki.awik(self.phenny, input)
self.phenny.say.assert_called_once_with( "Can't find anything in "\ archwiki.awik(self.phenny, self.input)
"the ArchWiki for \"{0}\".".format(term)) out = self.phenny.say.call_args[0][0]
expected = "Can't find anything in the ArchWiki for \"{0}\"."
self.assertEqual(out, expected.format(self.text))

View File

@ -2,38 +2,77 @@
test_vtluugwiki.py - tests for the VTLUUG wiki module test_vtluugwiki.py - tests for the VTLUUG wiki module
author: mutantmonkey <mutantmonkey@mutantmonkey.in> author: mutantmonkey <mutantmonkey@mutantmonkey.in>
""" """
import re
import unittest import unittest
from mock import MagicMock, Mock from mock import MagicMock
from modules import vtluugwiki from modules import vtluugwiki
import wiki
class TestVtluugwiki(unittest.TestCase): class TestVtluugwiki(unittest.TestCase):
def setUp(self): def setUp(self):
self.phenny = MagicMock() self.phenny = MagicMock()
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.groups.return_value = [None, self.text]
self.url = 'https://vtluug.org/wiki/{0}'.format(url_text)
def check_snippet(self, output):
self.assertIn(self.url, output)
for keyword in self.keywords:
self.assertIn(keyword, output)
def test_vtluug(self): def test_vtluug(self):
input = Mock(groups=lambda: ['', "VT-Wireless"]) self.term = "VT-Wireless"
vtluugwiki.vtluug(self.phenny, input) self.prepare()
vtluugwiki.vtluug(self.phenny, self.input)
out = self.phenny.say.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^.* - https:\/\/vtluug\.org\/wiki\/VT-Wireless$',
out, flags=re.UNICODE) self.keywords = ['campus', 'wireless', 'networks']
self.assertTrue(m) self.check_snippet(out)
def test_vtluug_fragment(self):
self.term = "EAP-TLS"
self.section = "netctl"
self.prepare()
vtluugwiki.vtluug(self.phenny, self.input)
out = self.phenny.say.call_args[0][0]
self.keywords = ['Arch', 'Linux', 'netctl']
self.check_snippet(out)
def test_vtluug_invalid(self): def test_vtluug_invalid(self):
term = "EAP-TLS#netcfg" self.term = "EAP-TLS"
input = Mock(groups=lambda: ['', term]) self.section = "netcfg"
vtluugwiki.vtluug(self.phenny, input) self.prepare()
self.phenny.say.assert_called_once_with( "Can't find anything in "\ vtluugwiki.vtluug(self.phenny, self.input)
"the VTLUUG Wiki for \"{0}\".".format(term)) 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))
def test_vtluug_none(self): def test_vtluug_none(self):
term = "Ajgoajh" self.term = "Ajgoajh"
input = Mock(groups=lambda: ['', term]) self.prepare()
vtluugwiki.vtluug(self.phenny, input)
vtluugwiki.vtluug(self.phenny, self.input)
out = self.phenny.say.call_args[0][0]
expected = "Can't find anything in the VTLUUG Wiki for \"{0}\"."
self.assertEqual(out, expected.format(self.text))
self.phenny.say.assert_called_once_with( "Can't find anything in "\
"the VTLUUG Wiki for \"{0}\".".format(term))

View File

@ -2,38 +2,76 @@
test_wikipedia.py - tests for the wikipedia module test_wikipedia.py - tests for the wikipedia module
author: mutantmonkey <mutantmonkey@mutantmonkey.in> author: mutantmonkey <mutantmonkey@mutantmonkey.in>
""" """
import re
import unittest import unittest
from mock import MagicMock, Mock from mock import MagicMock
from modules import wikipedia from modules import wikipedia
import wiki
class TestWikipedia(unittest.TestCase): class TestWikipedia(unittest.TestCase):
def setUp(self): def setUp(self):
self.phenny = MagicMock() self.phenny = MagicMock()
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.groups.return_value = [None, self.text]
self.url = 'https://en.wikipedia.org/wiki/{0}'.format(url_text)
def check_snippet(self, output):
self.assertIn(self.url, output)
for keyword in self.keywords:
self.assertIn(keyword, output)
def test_wik(self): def test_wik(self):
input = Mock(groups=lambda: ['', "Human back"]) self.term = "Human back"
wikipedia.wik(self.phenny, input) self.prepare()
wikipedia.wik(self.phenny, self.input)
out = self.phenny.say.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^.* - https:\/\/en\.wikipedia\.org\/wiki\/Human_back$',
out, flags=re.UNICODE) self.keywords = ['human', 'back', 'body', 'buttocks', 'neck']
self.assertTrue(m) self.check_snippet(out)
def test_wik_fragment(self):
self.term = "New York City"
self.section = "Climate"
self.prepare()
wikipedia.wik(self.phenny, self.input)
out = self.phenny.say.call_args[0][0]
self.keywords = ['New York', 'climate', 'humid', 'subtropical']
self.check_snippet(out)
def test_wik_invalid(self): def test_wik_invalid(self):
term = "New York City#Climate" self.term = "New York City"
input = Mock(groups=lambda: ['', term]) self.section = "Physics"
wikipedia.wik(self.phenny, input) self.prepare()
self.phenny.say.assert_called_once_with( "Can't find anything in "\ wikipedia.wik(self.phenny, self.input)
"Wikipedia for \"{0}\".".format(term)) 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))
def test_wik_none(self): def test_wik_none(self):
term = "Ajgoajh" self.term = "Ajgoajh"
input = Mock(groups=lambda: ['', term]) self.prepare()
wikipedia.wik(self.phenny, input)
self.phenny.say.assert_called_once_with( "Can't find anything in "\ wikipedia.wik(self.phenny, self.input)
"Wikipedia for \"{0}\".".format(term)) out = self.phenny.say.call_args[0][0]
expected = "Can't find anything in Wikipedia for \"{0}\"."
self.assertEqual(out, expected.format(self.text))