From b3e432b9d6f5147e5da5f7731107d538acc9f6c3 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Thu, 7 Aug 2014 03:58:09 +0400 Subject: [PATCH] add more unit tests Change-Id: Id3c831fdfca03b5b70786d993e9c6bc78b3bf0fd --- tests/test_utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 6bb3132..6130cf5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -17,12 +17,22 @@ import base64 import hashlib import hmac +import mock + from osprofiler import _utils as utils from tests import test class UtilsTestCase(test.TestCase): + def test_split(self): + self.assertEqual([1, 2], utils.split([1, 2])) + self.assertEqual(["A", "B"], utils.split("A, B")) + self.assertEqual(["A", " B"], utils.split("A, B", strip=False)) + + def test_split_wrong_type(self): + self.assertRaises(TypeError, utils.split, 1) + def test_binary_encode_and_decode(self): self.assertEqual("text", utils.binary_decode(utils.binary_encode("text"))) @@ -87,6 +97,12 @@ class UtilsTestCase(test.TestCase): packed_data, hmac_data = utils.signed_pack(data, "secret") self.assertIsNone(utils.signed_unpack(packed_data, hmac_data, None)) self.assertIsNone(utils.signed_unpack(packed_data, None, "secret")) + self.assertIsNone(utils.signed_unpack(packed_data, " ", "secret")) + + @mock.patch("osprofiler._utils.generate_hmac") + def test_singed_unpack_generate_hmac_failed(self, mock_generate_hmac): + mock_generate_hmac.side_effect = Exception + self.assertIsNone(utils.signed_unpack("data", "hmac_data", "hmac_key")) def test_signed_unpack_invalid_json(self): hmac = "secret"