aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/utility/test_hmac.py
diff options
context:
space:
mode:
authorBonfaceKilz2020-09-17 16:07:01 +0300
committerBonfaceKilz2020-09-17 16:07:01 +0300
commit81f6c22573db69e8ab0d2b831fc659147a839bbd (patch)
tree59cea49c4e8ed05dab9a26b6835492b1ebe85d17 /wqflask/tests/utility/test_hmac.py
parent90475fed0b2d1bd192a641bd417f6dfef79653d0 (diff)
parent8da6a70916d2cf18e476ab0adf47f802c481205d (diff)
downloadgenenetwork2-81f6c22573db69e8ab0d2b831fc659147a839bbd.tar.gz
Merge branch 'testing' into build/python3-migration
Diffstat (limited to 'wqflask/tests/utility/test_hmac.py')
-rw-r--r--wqflask/tests/utility/test_hmac.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/wqflask/tests/utility/test_hmac.py b/wqflask/tests/utility/test_hmac.py
new file mode 100644
index 00000000..c7927685
--- /dev/null
+++ b/wqflask/tests/utility/test_hmac.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+"""Test hmac utility functions"""
+
+import unittest
+import mock
+
+from utility.hmac import data_hmac
+from utility.hmac import url_for_hmac
+from utility.hmac import hmac_creation
+
+
+class TestHmacUtil(unittest.TestCase):
+ """Test Utility method for hmac creation"""
+
+ def test_hmac_creation(self):
+ """Test hmac creation with a utf-8 string"""
+ self.assertEqual(hmac_creation("ファイ"), "21fa1d935bbbb07a7875")
+
+ def test_data_hmac(self):
+ """Test data_hmac fn with a utf-8 string"""
+ self.assertEqual(data_hmac("ファイ"), "ファイ:21fa1d935bbbb07a7875")
+
+ @mock.patch("utility.hmac.url_for")
+ def test_url_for_hmac_with_plain_url(self, mock_url):
+ """Test url_for_hmac without params"""
+ mock_url.return_value = "https://mock_url.com/ファイ/"
+ self.assertEqual(url_for_hmac("ファイ"),
+ "https://mock_url.com/ファイ/?hm=a62896a50d9ffcff7deb")
+
+ @mock.patch("utility.hmac.url_for")
+ def test_url_for_hmac_with_param_in_url(self, mock_url):
+ """Test url_for_hmac with params"""
+ mock_url.return_value = "https://mock_url.com/?ファイ=1"
+ self.assertEqual(url_for_hmac("ファイ"),
+ "https://mock_url.com/?ファイ=1&hm=b2128fb28bc32da3b5b7")