diff options
author | Grant Lanham <contact@grantlanham.com> | 2024-09-23 23:37:30 -0400 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-10-03 13:20:32 +0200 |
commit | 44a06190bbb1b412f0ed16a76b0a4aeef80975b7 (patch) | |
tree | dd6e94d656fe4b11918e6cb5bd6183535dcc7254 /tests/unit/test_search.py | |
parent | 042c7190e6fe092a8a85997713a2511fffb09625 (diff) | |
download | searxng-44a06190bbb1b412f0ed16a76b0a4aeef80975b7.tar.gz searxng-44a06190bbb1b412f0ed16a76b0a4aeef80975b7.zip |
[refactor] unit tests to utilize paramaterized and break down monolithic tests
- for tests which perform the same arrange/act/assert pattern but with different
data, the data portion has been moved to the ``paramaterized.expand`` fields
- for monolithic tests which performed multiple arrange/act/asserts,
they have been broken up into different unit tests.
- when possible, change generic assert statements to more concise
asserts (i.e. ``assertIsNone``)
This work ultimately is focused on creating smaller and more concise tests.
While paramaterized may make adding new configurations for existing tests
easier, that is just a beneficial side effect. The main benefit is that smaller
tests are easier to reason about, meaning they are easier to debug when they
start failing. This improves the developer experience in debugging what went
wrong when refactoring the project.
Total number of tests went from 192 -> 259; or, broke apart larger tests into 69
more concise ones.
Diffstat (limited to 'tests/unit/test_search.py')
-rw-r--r-- | tests/unit/test_search.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/unit/test_search.py b/tests/unit/test_search.py index a60089aef..be95fb08e 100644 --- a/tests/unit/test_search.py +++ b/tests/unit/test_search.py @@ -110,7 +110,7 @@ class SearchTestCase(SearxTestCase): # pylint: disable=missing-class-docstring search.search() self.assertEqual(search.actual_timeout, 10.0) - def test_external_bang(self): + def test_external_bang_valid(self): search_query = SearchQuery( 'yes yes', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], @@ -124,8 +124,9 @@ class SearchTestCase(SearxTestCase): # pylint: disable=missing-class-docstring search = searx.search.Search(search_query) results = search.search() # For checking if the user redirected with the youtube external bang - self.assertTrue(results.redirect_url is not None) + self.assertIsNotNone(results.redirect_url) + def test_external_bang_none(self): search_query = SearchQuery( 'youtube never gonna give you up', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], @@ -140,4 +141,4 @@ class SearchTestCase(SearxTestCase): # pylint: disable=missing-class-docstring with self.app.test_request_context('/search'): results = search.search() # This should not redirect - self.assertTrue(results.redirect_url is None) + self.assertIsNone(results.redirect_url) |