From f84eb9061c327b782ffa1ec2ec3adb57933703c5 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Sat, 2 Jun 2012 15:11:51 -0700 Subject: [PATCH] validate: fix and add test --- modules/test/test_validate.py | 31 +++++++++++++++++++++++++++++++ modules/validate.py | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 modules/test/test_validate.py diff --git a/modules/test/test_validate.py b/modules/test/test_validate.py new file mode 100644 index 0000000..aefc119 --- /dev/null +++ b/modules/test/test_validate.py @@ -0,0 +1,31 @@ +""" +test_validate.py - tests for the validation module +author: mutantmonkey +""" + +import re +import unittest +from mock import MagicMock, Mock +from modules.validate import val + + +class TestValidate(unittest.TestCase): + def setUp(self): + self.phenny = MagicMock() + + def test_valid(self): + url = 'http://vtluug.org/' + input = Mock(group=lambda x: url) + val(self.phenny, input) + + self.phenny.reply.assert_called_once_with('{0} is Valid'.format(url)) + + def test_invalid(self): + url = 'http://microsoft.com/' + input = Mock(group=lambda x: url) + val(self.phenny, input) + + out = self.phenny.reply.call_args[0][0] + m = re.match('^{0} is Invalid \(\d+ errors\)'.format(url), + out, flags=re.UNICODE) + self.assertTrue(m) diff --git a/modules/validate.py b/modules/validate.py index 624b51d..7b1b612 100644 --- a/modules/validate.py +++ b/modules/validate.py @@ -17,7 +17,7 @@ def val(phenny, input): if not uri.startswith('http://'): uri = 'http://' + uri - path = '/check?uri=%s;output=xml' % web.urllib.quote(uri) + path = '/check?uri=%s;output=xml' % web.quote(uri) info = web.head('http://validator.w3.org' + path) result = uri + ' is '