aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/utility/test_hmac.py
diff options
context:
space:
mode:
authorzsloan2020-09-22 16:50:07 -0500
committerzsloan2020-09-22 16:50:07 -0500
commitbb146e6d6d8fefa2f588bbaaede9867a4f132e4d (patch)
tree406ebbe6ee9b17edcce6725643171ee8c583b881 /wqflask/tests/utility/test_hmac.py
parent00cefa3d42c3e2b6633573eb124e1bcf68cea7ab (diff)
parent28b348c9956d21228d01cac6c3668e5ea7abf2e2 (diff)
downloadgenenetwork2-bb146e6d6d8fefa2f588bbaaede9867a4f132e4d.tar.gz
Merge branch 'testing' of github.com:genenetwork/genenetwork2 into testing
Diffstat (limited to 'wqflask/tests/utility/test_hmac.py')
-rw-r--r--wqflask/tests/utility/test_hmac.py39
1 files changed, 39 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..16b50771
--- /dev/null
+++ b/wqflask/tests/utility/test_hmac.py
@@ -0,0 +1,39 @@
+# -*- 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"""
+
+ @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"})
+ def test_hmac_creation(self):
+ """Test hmac creation with a utf-8 string"""
+ self.assertEqual(hmac_creation("ファイ"), "7410466338cfe109e946")
+
+ @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"})
+ def test_data_hmac(self):
+ """Test data_hmac fn with a utf-8 string"""
+ self.assertEqual(data_hmac("ファイ"), "ファイ:7410466338cfe109e946")
+
+ @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"})
+ @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=05bc39e659b1948f41e7")
+
+ @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"})
+ @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=4709c1708270644aed79")