diff options
author | BonfaceKilz | 2020-10-09 15:47:43 +0300 |
---|---|---|
committer | GitHub | 2020-10-09 15:47:43 +0300 |
commit | 58c3815571f83db0296dc099f1e4c6ff69619f64 (patch) | |
tree | 2f1841afed3281c8eb179aa2c695caf650a4e1cf /wqflask/tests | |
parent | 7db8f7da013eefdf518ccf024477d0abf4324c03 (diff) | |
parent | eae4f1e6fad57a77063a637f0b03c171b6437565 (diff) | |
download | genenetwork2-58c3815571f83db0296dc099f1e4c6ff69619f64.tar.gz |
Merge pull request #458 from BonfaceKilz/tests/add-extra-tests-for-collections
Tests/add extra tests for collections
Diffstat (limited to 'wqflask/tests')
-rw-r--r-- | wqflask/tests/wqflask/test_collect.py | 57 |
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'])) |