improve tests and test coverage

master
mutantmonkey 2013-08-25 14:32:42 -07:00
parent f5fb2fc37d
commit 23d99dd326
6 changed files with 55 additions and 20 deletions

View File

@ -17,25 +17,32 @@ class TestHs(unittest.TestCase):
data = search('john')
assert len(data) >= 1
assert 'uid' in data[0]
assert 'cn' in data[0]
self.assertIn('uid', data[0])
self.assertIn('cn', data[0])
def test_single(self):
input = Mock(group=lambda x: 'marchany')
hs(self.phenny, input)
out = self.phenny.reply.call_args[0][0]
m = re.match(
pattern = re.compile(
'^.* - http://search\.vt\.edu/search/person\.html\?person=\d+$',
out, flags=re.UNICODE)
self.assertTrue(m)
flags=re.UNICODE)
out = self.phenny.reply.call_args[0][0]
self.assertRegex(out, pattern)
def test_multi(self):
input = Mock(group=lambda x: 'john')
hs(self.phenny, input)
out = self.phenny.reply.call_args[0][0]
m = re.match(
pattern = re.compile(
'^Multiple results found; try http://search\.vt\.edu/search/people\.html\?q=.*$',
out, flags=re.UNICODE)
self.assertTrue(m)
flags=re.UNICODE)
out = self.phenny.reply.call_args[0][0]
self.assertRegex(out, pattern)
def test_none(self):
input = Mock(group=lambda x: 'THIS_IS_NOT_A_REAL_SEARCH_QUERY')
hs(self.phenny, input)
out = self.phenny.reply.call_args[0][0]
self.phenny.reply.assert_called_once_with("No results found")

View File

@ -25,6 +25,15 @@ class TestImdb(unittest.TestCase):
input = Mock(group=lambda x: 'Antitrust')
imdb(self.phenny, input)
out = self.phenny.reply.call_args[0][0]
m = re.match('^.* \(.*\): .* http://imdb.com/title/[a-z\d]+$', out, flags=re.UNICODE)
self.assertTrue(m)
out = self.phenny.say.call_args[0][0]
pattern = re.compile(
r'^.* \(.*\): .* http://imdb.com/title/[a-z\d]+$',
flags=re.UNICODE)
self.assertRegex(out, pattern)
def test_imdb_none(self):
input = Mock(group=lambda x: None)
imdb(self.phenny, input)
self.phenny.say.assert_called_once_with(
".imdb what?")

View File

@ -24,6 +24,10 @@ class TestMylife(unittest.TestCase):
mylife.mlib(self.phenny, None)
assert self.phenny.say.called is True
def test_mlig(self):
mylife.mlib(self.phenny, None)
assert self.phenny.say.called is True
def test_mlih(self):
mylife.mlih(self.phenny, None)
assert self.phenny.say.called is True

View File

@ -16,6 +16,11 @@ class TestNsfw(unittest.TestCase):
def test_nsfw(self):
input = Mock(group=lambda x: "test")
nsfw(self.phenny, input)
self.phenny.say.assert_called_once_with(
"!!NSFW!! -> test <- !!NSFW!!")
"!!NSFW!! -> test <- !!NSFW!!")
def test_nsfw_none(self):
input = Mock(group=lambda x: None)
nsfw(self.phenny, input)
self.phenny.say.assert_called_once_with(
".nsfw <link> - for when a link isn't safe for work")

View File

@ -15,5 +15,10 @@ class TestShort(unittest.TestCase):
def test_short(self):
input = Mock(group=lambda x: 'http://vtluug.org/')
short(self.phenny, input)
self.phenny.reply.assert_called_once_with('http://vtlu.ug/bLQYAy')
def test_short_none(self):
input = Mock(group=lambda x: None)
short(self.phenny, input)
self.phenny.reply.assert_called_once_with(
"No URL provided. CAN I HAS?")

View File

@ -14,12 +14,17 @@ class TestSlogan(unittest.TestCase):
def test_sloganize(self):
out = sloganize('slogan')
assert len(out) > 0
self.assertRegex(out, ".*slogan.*")
def test_slogan(self):
input = Mock(group=lambda x: 'slogan')
slogan(self.phenny, input)
out = self.phenny.say.call_args[0][0]
self.assertNotEqual(out, "Looks like an issue with sloganizer.net")
out = self.phenny.say.call_args[0][0]
self.assertRegex(out, ".*slogan.*")
def test_slogan_none(self):
input = Mock(group=lambda x: None)
slogan(self.phenny, input)
self.phenny.say.assert_called_once_with(
"You need to specify a word; try .slogan Granola")