diff options
author | Grant Lanham <contact@grantlanham.com> | 2024-08-31 18:04:37 -0400 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-09-22 08:03:02 +0200 |
commit | 14241e7dac009d3f58c0c168d6ab5a8131c8ece9 (patch) | |
tree | dfdfc5f8b1cbd18c93d967e1bf0ce046c5ec7f72 | |
parent | ea16c82d7840b7057f7aaf6b4c141ce9f39ec7a2 (diff) | |
download | searxng-14241e7dac009d3f58c0c168d6ab5a8131c8ece9.tar.gz searxng-14241e7dac009d3f58c0c168d6ab5a8131c8ece9.zip |
Add paramaterized with example of refactor
reduce test name size
fix imports
-rw-r--r-- | requirements-dev.txt | 2 | ||||
-rw-r--r-- | tests/unit/test_tineye.py | 18 |
2 files changed, 6 insertions, 14 deletions
diff --git a/requirements-dev.txt b/requirements-dev.txt index d5088b185..1c21d9ddf 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -22,4 +22,4 @@ wlc==1.15 coloredlogs==15.0.1 docutils<=0.21; python_version == '3.8' docutils>=0.21.2; python_version > '3.8' - +parameterized==0.9.0 diff --git a/tests/unit/test_tineye.py b/tests/unit/test_tineye.py index 0530b4c5e..5855a7313 100644 --- a/tests/unit/test_tineye.py +++ b/tests/unit/test_tineye.py @@ -5,6 +5,7 @@ from datetime import datetime from unittest.mock import Mock from requests import HTTPError +from parameterized import parameterized from searx.engines import load_engines, tineye from tests import SearxTestCase @@ -23,13 +24,13 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring response.raise_for_status.side_effect = HTTPError() self.assertRaises(HTTPError, lambda: tineye.response(response)) - def test_returns_empty_list_for_422(self): + @parameterized.expand([(400), (422)]) + def test_returns_empty_list(self, status_code): response = Mock() response.json.return_value = {} - response.status_code = 422 + response.status_code = status_code response.raise_for_status.side_effect = HTTPError() - with self.assertLogs(tineye.logger) as _dev_null: - results = tineye.response(response) + results = tineye.response(response) self.assertEqual(0, len(results)) def test_logs_format_for_422(self): @@ -62,15 +63,6 @@ class TinEyeTests(SearxTestCase): # pylint: disable=missing-class-docstring tineye.response(response) self.assertIn(tineye.DOWNLOAD_ERROR, ','.join(assert_logs_context.output)) - def test_empty_list_for_400(self): - response = Mock() - response.json.return_value = {} - response.status_code = 400 - response.raise_for_status.side_effect = HTTPError() - with self.assertLogs(tineye.logger) as _dev_null: - results = tineye.response(response) - self.assertEqual(0, len(results)) - def test_logs_description_for_400(self): description = 'There was a problem with that request. Error ID: ad5fc955-a934-43c1-8187-f9a61d301645' response = Mock() |