Skip to content

Commit 7be8ede

Browse files
committed
Improve coverage
1 parent f89a8dc commit 7be8ede

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/utils_tests.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding=utf-8
22
import unittest
33

4-
from consulate import utils
4+
from consulate import exceptions, utils
55

66

77
class QuoteTestCase(unittest.TestCase):
@@ -19,6 +19,43 @@ def byte_test(self):
1919
self.assertEqual(utils.maybe_encode(b'bar'), b'bar')
2020

2121

22+
class Response(object):
23+
def __init__(self, status_code=200, body=b'content'):
24+
self.status_code = status_code
25+
self.body = body
26+
27+
28+
class ResponseOkTestCase(unittest.TestCase):
29+
30+
def test_200(self):
31+
self.assertTrue(utils.response_ok(Response(200, b'ok')))
32+
33+
def test_400(self):
34+
with self.assertRaises(exceptions.ClientError):
35+
utils.response_ok(Response(400, b'Bad request'))
36+
37+
def test_401(self):
38+
with self.assertRaises(exceptions.ACLDisabled):
39+
utils.response_ok(Response(401, b'What ACL?'))
40+
41+
def test_403(self):
42+
with self.assertRaises(exceptions.Forbidden):
43+
utils.response_ok(Response(403, b'No'))
44+
45+
def test_404_not_raising(self):
46+
self.assertFalse(utils.response_ok(Response(404, b'not found')))
47+
48+
def test_404_raising(self):
49+
with self.assertRaises(exceptions.NotFound):
50+
utils.response_ok(Response(404, b'Not Found'), True)
51+
52+
def test_500(self):
53+
with self.assertRaises(exceptions.ServerError):
54+
utils.response_ok(Response(500, b'Opps'))
55+
56+
57+
58+
2259
class ValidateGoDurationTestCase(unittest.TestCase):
2360

2461
def test_valid_values(self):
@@ -43,3 +80,5 @@ def test_invalid_values(self):
4380
for value in {'localhost', 'a'}:
4481
print('Testing {}'.format(value))
4582
self.assertFalse(utils.validate_url(value))
83+
84+

0 commit comments

Comments
 (0)