diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-09-25 19:35:53 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-09-25 19:35:53 +0300 |
commit | 7a9e116bf7a31ecf410b9fd474abbe8c13dcb0ce (patch) | |
tree | 3ffd696c0d750eb19c8cdfd072464bfdddafa0ec | |
parent | e15496ed559c07996b12ccbddcd3491408bc5b0a (diff) | |
download | server-yarns-7a9e116bf7a31ecf410b9fd474abbe8c13dcb0ce.tar.gz |
Implement HTTP status testing
-rw-r--r-- | 900-implements.yarn | 6 | ||||
-rw-r--r-- | yarnhelper.py | 4 | ||||
-rw-r--r-- | yarnhelper_tests.py | 12 |
3 files changed, 21 insertions, 1 deletions
diff --git a/900-implements.yarn b/900-implements.yarn index 208a68f..19c3f9c 100644 --- a/900-implements.yarn +++ b/900-implements.yarn @@ -19,7 +19,11 @@ h.set_variable('http_body', body) IMPLEMENTS THEN HTTP status is (\d+) - pass + import yarnhelper + h = yarnhelper.YarnHelper() + expected = h.get_variable('http_status') + actual = int(h.get_next_match()) + h.assertEqual(expected, actual) IMPLEMENTS THEN HTTP body matches "(.*)" pass diff --git a/yarnhelper.py b/yarnhelper.py index ae16560..27ebcd0 100644 --- a/yarnhelper.py +++ b/yarnhelper.py @@ -86,6 +86,10 @@ class YarnHelper(object): resp = s.send(r) return resp.status_code, resp.content + def assertEqual(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 cae05cd..2f7409a 100644 --- a/yarnhelper_tests.py +++ b/yarnhelper_tests.py @@ -90,3 +90,15 @@ class HttpTests(unittest.TestCase): r = h.construct_aliased_http_request(server, 'GET', url) self.assertEqual(r.url, 'http://new.example.com/path') self.assertEqual(r.headers['Host'], 'www.example.com') + + +class AssertionTests(unittest.TestCase): + + def test_asserts_equals_correctly(self): + h = yarnhelper.YarnHelper() + self.assertEqual(h.assertEqual(0, 0), None) + + def test_assertEqual_raises_error_for_nonequal_values(self): + h = yarnhelper.YarnHelper() + with self.assertRaises(yarnhelper.Error): + h.assertEqual(0, 1) |