summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2016-09-25 19:52:22 +0300
committerLars Wirzenius <liw@liw.fi>2016-09-25 19:52:22 +0300
commitf5e8890e5adeeadae130417e0735a90afff3da5c (patch)
tree4017e2bff48e355f2c8f0e0206425831905e7699
parent13f8989a714563077e96446a76658d52b13ec8af (diff)
downloadserver-yarns-f5e8890e5adeeadae130417e0735a90afff3da5c.tar.gz
Implement http body matching
-rw-r--r--900-implements.yarn7
-rw-r--r--yarnhelper.py4
-rw-r--r--yarnhelper_tests.py11
3 files changed, 20 insertions, 2 deletions
diff --git a/900-implements.yarn b/900-implements.yarn
index 19c3f9c..0195a72 100644
--- a/900-implements.yarn
+++ b/900-implements.yarn
@@ -26,4 +26,9 @@
h.assertEqual(expected, actual)
IMPLEMENTS THEN HTTP body matches "(.*)"
- pass
+ import re, yarnhelper
+ h = yarnhelper.YarnHelper()
+ body = h.get_variable('http_body')
+ pattern = h.get_next_match()
+ m = re.search(pattern, body)
+ h.assertNotEqual(m, None)
diff --git a/yarnhelper.py b/yarnhelper.py
index c12d08d..51b4d4b 100644
--- a/yarnhelper.py
+++ b/yarnhelper.py
@@ -90,6 +90,10 @@ class YarnHelper(object):
if a != b:
raise Error('assertion {!r} == {!r} failed'.format(a, b))
+ def assertNotEqual(self, a, b):
+ if a == b:
+ raise Error('assertion {!r} != {!r} failed'.format(a, b))
+
class Error(Exception):
diff --git a/yarnhelper_tests.py b/yarnhelper_tests.py
index 2f7409a..756a165 100644
--- a/yarnhelper_tests.py
+++ b/yarnhelper_tests.py
@@ -94,7 +94,7 @@ class HttpTests(unittest.TestCase):
class AssertionTests(unittest.TestCase):
- def test_asserts_equals_correctly(self):
+ def test_assertEqual_asserts_equals_correctly(self):
h = yarnhelper.YarnHelper()
self.assertEqual(h.assertEqual(0, 0), None)
@@ -102,3 +102,12 @@ class AssertionTests(unittest.TestCase):
h = yarnhelper.YarnHelper()
with self.assertRaises(yarnhelper.Error):
h.assertEqual(0, 1)
+
+ def test_assertNotEqual_asserts_nonequal_correct(self):
+ h = yarnhelper.YarnHelper()
+ self.assertEqual(h.assertNotEqual(0, 1), None)
+
+ def test_assertNotEqual_raises_error_for_equal_values(self):
+ h = yarnhelper.YarnHelper()
+ with self.assertRaises(yarnhelper.Error):
+ h.assertNotEqual(0, 0)