unit test

This commit is contained in:
Mike McLean 2025-02-24 12:16:29 -05:00
parent af18c59623
commit abf33cea63
2 changed files with 18 additions and 1 deletions

View file

@ -17,4 +17,4 @@ if importlib:
sys.modules[INDEX_MOD] = webidx
spec.loader.exec_module(webidx)
else:
cli = imp.load_source(INDEX_MOD, INDEX_FILENAME)
webidx = imp.load_source(INDEX_MOD, INDEX_FILENAME)

View file

@ -19,6 +19,7 @@ class TestSearch(unittest.TestCase):
}
urlencode_data = "terms=test&type=package&match=testmatch"
self.fs = FieldStorageCompat({'QUERY_STRING': urlencode_data})
self.gen_html = mock.patch.object(webidx, '_genHTML').start()
def __get_server(env):
env['koji.form'] = self.fs
@ -29,6 +30,18 @@ class TestSearch(unittest.TestCase):
def tearDown(self):
mock.patch.stopall()
def test_no_args(self):
self.fs = FieldStorageCompat({'QUERY_STRING': ''})
webidx.search(self.environ)
self.gen_html.assert_called_once()
# extract values
# called as _genHTML(environ, 'search.chtml')
args = self.gen_html.call_args_list[0][0] # no kwargs passed here
environ = args[0]
self.assertEqual(environ['koji.values']['terms'], '')
def test_search_exception_match(self):
"""Test taskinfo function raises exception"""
self.server.getBuildTarget.return_info = None
@ -37,3 +50,7 @@ class TestSearch(unittest.TestCase):
with self.assertRaises(koji.GenericError) as cm:
webidx.search(self.environ)
self.assertEqual(str(cm.exception), "No such match type: 'testmatch'")
self.gen_html.assert_not_called()
# the end