aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorBonfaceKilz2020-09-29 15:57:01 +0300
committerBonfaceKilz2020-09-29 17:11:22 +0300
commitce728fa92e02725202bca486e8336b2e1158f4ef (patch)
treec3d82f2899c03efd7500cf82d569c981618cdb87 /wqflask/tests
parent21ec6863d7f8380d66c39f1ed3b8d9cc0dc86e49 (diff)
downloadgenenetwork2-ce728fa92e02725202bca486e8336b2e1158f4ef.tar.gz
Add test for process_traits from collections.py
* wqflask/tests/wqflask/test_collect.py: Add it.
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/wqflask/test_collect.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/wqflask/tests/wqflask/test_collect.py b/wqflask/tests/wqflask/test_collect.py
new file mode 100644
index 00000000..06609b4c
--- /dev/null
+++ b/wqflask/tests/wqflask/test_collect.py
@@ -0,0 +1,73 @@
+"""Test cases for some methods in collect.py"""
+
+import unittest
+import mock
+
+from flask import Flask
+from wqflask.collect import process_traits
+
+app = Flask(__name__)
+
+
+class MockSession:
+ """Helper class for mocking wqflask.collect.g.user_session.logged_in"""
+ def __init__(self, is_logged_in=False):
+ self.is_logged_in = is_logged_in
+
+ @property
+ def logged_in(self):
+ return self.is_logged_in
+
+
+class MockFlaskG:
+ """Helper class for mocking wqflask.collect.g.user_session"""
+ def __init__(self, is_logged_in=False):
+ self.is_logged_in = is_logged_in
+
+ @property
+ def user_session(self):
+ if self.is_logged_in:
+ return MockSession(is_logged_in=True)
+ return MockSession()
+
+
+class TestCollect(unittest.TestCase):
+
+ def setUp(self):
+ self.app_context = app.app_context()
+ self.app_context.push()
+
+ def tearDown(self):
+ self.app_context.pop()
+
+ @mock.patch("wqflask.collect.g", MockFlaskG())
+ def test_process_traits_with_bytestring(self):
+ """
+ Test that the correct traits are returned when the user is logged
+ out and bytes are used.
+ """
+ self.assertEqual(process_traits(
+ b'1452452_at:HC_M2_0606_P:163d04f7db7c9e110de6,'
+ b'1452447_at:HC_M2_0606_P:eeece8fceb67072debea,'
+ b'1451401_a_at:HC_M2_0606_P:a043d23b3b3906d8318e,'
+ b'1429252_at:HC_M2_0606_P:6fa378b349bc9180e8f5'),
+ set(['1429252_at:HC_M2_0606_P',
+ '1451401_a_at:HC_M2_0606_P',
+ '1452447_at:HC_M2_0606_P',
+ '1452452_at:HC_M2_0606_P']))
+
+ @mock.patch("wqflask.collect.g", MockFlaskG())
+ def test_process_traits_with_normal_string(self):
+ """
+ Test that the correct traits are returned when the user is logged
+ out and a normal string is used.
+ """
+ self.assertEqual(process_traits(
+ '1452452_at:HC_M2_0606_P:163d04f7db7c9e110de6,'
+ '1452447_at:HC_M2_0606_P:eeece8fceb67072debea,'
+ '1451401_a_at:HC_M2_0606_P:a043d23b3b3906d8318e,'
+ '1429252_at:HC_M2_0606_P:6fa378b349bc9180e8f5'),
+ set(['1429252_at:HC_M2_0606_P',
+ '1451401_a_at:HC_M2_0606_P',
+ '1452447_at:HC_M2_0606_P',
+ '1452452_at:HC_M2_0606_P']))