mirror of
https://github.com/laramies/theHarvester.git
synced 2026-09-07 18:27:42 +02:00
Fix mypy errors lee to qa
This commit is contained in:
@@ -17,13 +17,17 @@ class TestSearchGithubCode:
|
||||
def __init__(self):
|
||||
self.response = Response()
|
||||
self.response.status_code = 200
|
||||
self.response.json = MagicMock(
|
||||
return_value={
|
||||
"items": [
|
||||
{"text_matches": [{"fragment": "test1"}]},
|
||||
{"text_matches": [{"fragment": "test2"}]},
|
||||
]
|
||||
}
|
||||
object.__setattr__(
|
||||
self.response,
|
||||
"json",
|
||||
MagicMock(
|
||||
return_value={
|
||||
"items": [
|
||||
{"text_matches": [{"fragment": "test1"}]},
|
||||
{"text_matches": [{"fragment": "test2"}]},
|
||||
]
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
class FailureResponse:
|
||||
@@ -32,13 +36,13 @@ class TestSearchGithubCode:
|
||||
def __init__(self):
|
||||
self.response = Response()
|
||||
self.response.status_code = 401
|
||||
self.response.json = MagicMock(return_value={})
|
||||
object.__setattr__(self.response, "json", MagicMock(return_value={}))
|
||||
|
||||
class RetryResponse:
|
||||
def __init__(self):
|
||||
self.response = Response()
|
||||
self.response.status_code = 403
|
||||
self.response.json = MagicMock(return_value={})
|
||||
object.__setattr__(self.response, "json", MagicMock(return_value={}))
|
||||
|
||||
class MalformedResponse:
|
||||
response = Response()
|
||||
@@ -46,23 +50,27 @@ class TestSearchGithubCode:
|
||||
def __init__(self):
|
||||
self.response = Response()
|
||||
self.response.status_code = 200
|
||||
self.response.json = MagicMock(
|
||||
return_value={
|
||||
"items": [
|
||||
{"fail": True},
|
||||
{"text_matches": []},
|
||||
{"text_matches": [{"weird": "result"}]},
|
||||
]
|
||||
}
|
||||
object.__setattr__(
|
||||
self.response,
|
||||
"json",
|
||||
MagicMock(
|
||||
return_value={
|
||||
"items": [
|
||||
{"fail": True},
|
||||
{"text_matches": []},
|
||||
{"text_matches": [{"weird": "result"}]},
|
||||
]
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
async def test_missing_key(self):
|
||||
with pytest.raises(MissingKey):
|
||||
Core.github_key = MagicMock(return_value=None)
|
||||
Core.github_key = MagicMock(return_value=None) # type: ignore[method-assign]
|
||||
githubcode.SearchGithubCode(word="test", limit=500)
|
||||
|
||||
async def test_fragments_from_response(self):
|
||||
Core.github_key = MagicMock(return_value="test_key")
|
||||
Core.github_key = MagicMock(return_value="test_key") # type: ignore[method-assign]
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = await test_class_instance.fragments_from_response(
|
||||
self.OkResponse().response.json()
|
||||
@@ -71,7 +79,7 @@ class TestSearchGithubCode:
|
||||
assert test_result == ["test1", "test2"]
|
||||
|
||||
async def test_invalid_fragments_from_response(self):
|
||||
Core.github_key = MagicMock(return_value="test_key")
|
||||
Core.github_key = MagicMock(return_value="test_key") # type: ignore[method-assign]
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = await test_class_instance.fragments_from_response(
|
||||
self.MalformedResponse().response.json()
|
||||
@@ -79,20 +87,20 @@ class TestSearchGithubCode:
|
||||
assert test_result == []
|
||||
|
||||
async def test_next_page(self):
|
||||
Core.github_key = MagicMock(return_value="test_key")
|
||||
Core.github_key = MagicMock(return_value="test_key") # type: ignore[method-assign]
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = githubcode.SuccessResult(list(), next_page=2, last_page=4)
|
||||
assert 2 == await test_class_instance.next_page_or_end(test_result)
|
||||
|
||||
async def test_last_page(self):
|
||||
Core.github_key = MagicMock(return_value="test_key")
|
||||
Core.github_key = MagicMock(return_value="test_key") # type: ignore[method-assign]
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
test_result = githubcode.SuccessResult(list(), 0, 0)
|
||||
assert await test_class_instance.next_page_or_end(test_result) is 0
|
||||
|
||||
async def test_infinite_loop_fix_page_zero(self):
|
||||
"""Test that the loop condition properly exits when page becomes 0"""
|
||||
Core.github_key = MagicMock(return_value="test_key")
|
||||
Core.github_key = MagicMock(return_value="test_key") # type: ignore[method-assign]
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
|
||||
# Test the fixed condition: page != 0
|
||||
@@ -106,7 +114,7 @@ class TestSearchGithubCode:
|
||||
|
||||
async def test_infinite_loop_fix_page_nonzero(self):
|
||||
"""Test that the loop condition continues when page is non-zero"""
|
||||
Core.github_key = MagicMock(return_value="test_key")
|
||||
Core.github_key = MagicMock(return_value="test_key") # type: ignore[method-assign]
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
|
||||
# Test with non-zero page values
|
||||
@@ -120,7 +128,7 @@ class TestSearchGithubCode:
|
||||
|
||||
async def test_infinite_loop_fix_old_vs_new_condition(self):
|
||||
"""Test that demonstrates the difference between old and new conditions"""
|
||||
Core.github_key = MagicMock(return_value="test_key")
|
||||
Core.github_key = MagicMock(return_value="test_key") # type: ignore[method-assign]
|
||||
test_class_instance = githubcode.SearchGithubCode(word="test", limit=500)
|
||||
|
||||
page = 0
|
||||
|
||||
Reference in New Issue
Block a user