From b4d52b537614fca6bd8a66a7ee5e334edcc65241 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Tue, 9 Jun 2020 11:58:39 +0200 Subject: [PATCH] tests: lib.ListUsers tests done Even more coverage is on it's way. Have still to figure out in which manner i'm going to test the things i want to. It's actually not as easy as i expected... --- private/test/test_ListUsers.py | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 private/test/test_ListUsers.py diff --git a/private/test/test_ListUsers.py b/private/test/test_ListUsers.py new file mode 100644 index 0000000..667c45d --- /dev/null +++ b/private/test/test_ListUsers.py @@ -0,0 +1,45 @@ +import unittest +import test.testcfg as testcfg +import sys +import os +from lib.ListUsers import ListUsers +sys.path.append('..') + +f = open(os.devnull, 'w') +sys.stdout = f + + +class TestListUsers(unittest.TestCase): + def setUp(self) -> None: + try: + self.list = ListUsers(testcfg.test_db, unapproved=False, approved=False) + except IOError as fs_err: + self.fail(fs_err) + + def test_output_as_list(self): + # count newlines in string, everything under 3 is wrong, and above 20 too. + out = self.list.output_as_list().splitlines() + self.assertGreater(len(out), testcfg.ListUsers_output_newlines, + "Newlines in OUTPUT doesn't exceed minimum of at least " + f"{testcfg.ListUsers_output_newlines} " + "lines!") + print(out) + + def test_pretty_print(self): + # wont going to compare the stdout sorry very much + return + + def test_get_fetch(self): + fetch = self.list.get_fetch() + self.assertIsInstance(fetch, list) + self.assertGreater(len(fetch), + testcfg.ListUsers_fetch_size_min, "fetch is NOT greater than" + "the configured fetch minimum") + try: + print(fetch[0]) + except (KeyError, IOError) as suddenly_not_there: + self.fail(f"Expected fetch to have at least one argument! {suddenly_not_there}") + + +if __name__ == '__main__': + unittest.main()