Skip to content

Commit

Permalink
Add paramaterized with example of refactor
Browse files Browse the repository at this point in the history
reduce test name size

fix imports
  • Loading branch information
glanham-jr authored and return42 committed Sep 22, 2024
1 parent ea16c82 commit 14241e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 5 additions & 13 deletions tests/unit/test_tineye.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,13 +24,13 @@ def test_status_code_raises(self):
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):
Expand Down Expand Up @@ -62,15 +63,6 @@ def test_logs_download_for_422(self):
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()
Expand Down

0 comments on commit 14241e7

Please sign in to comment.