Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gmr committed Feb 27, 2018
1 parent f89a8dc commit 7be8ede
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/utils_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8
import unittest

from consulate import utils
from consulate import exceptions, utils


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


class Response(object):
def __init__(self, status_code=200, body=b'content'):
self.status_code = status_code
self.body = body


class ResponseOkTestCase(unittest.TestCase):

def test_200(self):
self.assertTrue(utils.response_ok(Response(200, b'ok')))

def test_400(self):
with self.assertRaises(exceptions.ClientError):
utils.response_ok(Response(400, b'Bad request'))

def test_401(self):
with self.assertRaises(exceptions.ACLDisabled):
utils.response_ok(Response(401, b'What ACL?'))

def test_403(self):
with self.assertRaises(exceptions.Forbidden):
utils.response_ok(Response(403, b'No'))

def test_404_not_raising(self):
self.assertFalse(utils.response_ok(Response(404, b'not found')))

def test_404_raising(self):
with self.assertRaises(exceptions.NotFound):
utils.response_ok(Response(404, b'Not Found'), True)

def test_500(self):
with self.assertRaises(exceptions.ServerError):
utils.response_ok(Response(500, b'Opps'))




class ValidateGoDurationTestCase(unittest.TestCase):

def test_valid_values(self):
Expand All @@ -43,3 +80,5 @@ def test_invalid_values(self):
for value in {'localhost', 'a'}:
print('Testing {}'.format(value))
self.assertFalse(utils.validate_url(value))


0 comments on commit 7be8ede

Please sign in to comment.