aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorBonfaceKilz2020-09-29 15:57:01 +0300
committerBonfaceKilz2020-10-09 15:40:47 +0300
commit4d16656304b9702c124721e82ea0dcda3c40ae44 (patch)
treeff775aefe464d3780a30c86f2ba2f097dd542f6e /wqflask/tests
parentd34258bed3ef13350499414100401df3bf08a105 (diff)
downloadgenenetwork2-4d16656304b9702c124721e82ea0dcda3c40ae44.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.py57
1 files changed, 57 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..6b8d7931
--- /dev/null
+++ b/wqflask/tests/wqflask/test_collect.py
@@ -0,0 +1,57 @@
+"""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_when_user_is_logged_out(self):
+ """
+ Test that the correct traits are returned when the user is logged
+ out
+ """
+ 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']))