From 4736f5e9bc0415f02e9c044202966279e44b503c Mon Sep 17 00:00:00 2001 From: Alex Zai Date: Sun, 22 Nov 2015 13:40:07 -0800 Subject: [PATCH] (feat) supress stdout in test --- src/venmo_api.py | 6 +- tests/venmo_test.py | 132 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 9 deletions(-) diff --git a/src/venmo_api.py b/src/venmo_api.py index 1016b6f..8d9ddf4 100644 --- a/src/venmo_api.py +++ b/src/venmo_api.py @@ -176,11 +176,11 @@ def show_options(cls, user_input): user_input, user inputted string in Alfred bar. """ - if 'login'.startswith(user_input): + if 'login'.startswith(user_input.lower()): cls.show_login() - if 'logout'.startswith(user_input): + if 'logout'.startswith(user_input.lower()): cls.show_logout() - if 'clear cache'.startswith(user_input): + if 'clear cache'.startswith(user_input.lower()): cls.show_clear_cache() if len(wf._items) == 0: diff --git a/tests/venmo_test.py b/tests/venmo_test.py index d15329e..3140b8a 100644 --- a/tests/venmo_test.py +++ b/tests/venmo_test.py @@ -5,6 +5,8 @@ import unittest import sys from src.config import LOGIN, LOGOUT, INVALID, CLEAR_CACHE +import os +import sys from src.venmo import main from src.venmo_api import wf @@ -12,6 +14,7 @@ class TestVenmo(unittest.TestCase): def test_settings(self): + wf._items = [] sys.argv = ['venmo.py','>'] main(None) self.assertEqual(len(wf._items), 3) @@ -20,9 +23,10 @@ def test_settings(self): self.assertEqual(wf._items[2].title, CLEAR_CACHE['title']) wf._items = [] - def test_invalid_options(self): - sys.argv = ['venmo.py.py','not here'] + wf._items = [] + + sys.argv = ['venmo.py.py','> not here'] main(None) self.assertEqual(len(wf._items), 1) self.assertEqual(wf._items[0].title, INVALID['title']) @@ -30,14 +34,130 @@ def test_invalid_options(self): self.assertFalse(wf._items[0].arg) wf._items = [] - def xtest_add_account(self): - sys.argv = ['venmo.py.py','add'] + def test_login(self): + sys.argv = ['venmo.py.py','> login'] main(None) self.assertEqual(len(wf._items), 1) - self.assertEqual(wf._items[0].title, 'Add Account') + self.assertEqual(wf._items[0].title, LOGIN['title']) + self.assertEqual(wf._items[0].arg, LOGIN['arg']) self.assertTrue(wf._items[0].valid) - self.assertTrue(wf._items[0].arg) wf._items = [] + sys.argv = ['venmo.py.py','>login'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGIN['title']) + self.assertEqual(wf._items[0].arg, LOGIN['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> login'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGIN['title']) + self.assertEqual(wf._items[0].arg, LOGIN['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> Login'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGIN['title']) + self.assertEqual(wf._items[0].arg, LOGIN['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> LOGIN'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGIN['title']) + self.assertEqual(wf._items[0].arg, LOGIN['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + def test_logout(self): + wf._items = [] + + sys.argv = ['venmo.py.py','> logout'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGOUT['title']) + self.assertEqual(wf._items[0].arg, LOGOUT['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','>logout'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGOUT['title']) + self.assertEqual(wf._items[0].arg, LOGOUT['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> logout'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGOUT['title']) + self.assertEqual(wf._items[0].arg, LOGOUT['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> Logout'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGOUT['title']) + self.assertEqual(wf._items[0].arg, LOGOUT['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> LOGOUT'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, LOGOUT['title']) + self.assertEqual(wf._items[0].arg, LOGOUT['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + def test_clear_cache(self): + wf._items = [] + + sys.argv = ['venmo.py.py','> cl'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, CLEAR_CACHE['title']) + self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> clear C'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, CLEAR_CACHE['title']) + self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','>cl'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, CLEAR_CACHE['title']) + self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + sys.argv = ['venmo.py.py','> clear cache'] + main(None) + self.assertEqual(len(wf._items), 1) + self.assertEqual(wf._items[0].title, CLEAR_CACHE['title']) + self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg']) + self.assertTrue(wf._items[0].valid) + wf._items = [] + + def setUp(self): + + # supress stdout of feedback + f = open(os.devnull, 'w') + sys.stdout = f + if __name__ == '__main__': unittest.main() \ No newline at end of file