Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Artanias committed Aug 16, 2023
1 parent b309eed commit 8d8821c
Showing 1 changed file with 39 additions and 56 deletions.
95 changes: 39 additions & 56 deletions test/unit/webparsers/test_github_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from webparsers.types import Branch, Commit, PullRequest, Repository, WorkInfo

_REQUEST_PARAMS_1 = {'per_page': 100, 'page': 1}
_REQUEST_PARAMS_2 = {'per_page': 100, 'page': 2}
_REQUEST_PARAMS_3 = {'per_page': 100, 'page': 3}

_COMMIT1: Final[Commit] = Commit('zkueqwrkjsalu', '2022-12-20T20:13:58Z')
Expand Down Expand Up @@ -228,8 +227,6 @@ def test_get_list_of_repos(self, mock_send_get_request):
'send_calls': [
call('/users/OSLL'),
call('/orgs/OSLL/repos', params=_REQUEST_PARAMS_1),
call('/orgs/OSLL/repos', params=_REQUEST_PARAMS_2),
call('/orgs/OSLL/repos', params=_REQUEST_PARAMS_3)
],
'send_rvs': [
Response({'type': 'Organization'}),
Expand All @@ -242,11 +239,7 @@ def test_get_list_of_repos(self, mock_send_get_request):
{
'name': 'aido-auto-feedback',
'html_url': 'https://github.com/OSLL/aido-auto-feedback'
}
]
),
Response(
[
},
{
'name': 'MD-Code_generator',
'html_url': 'https://github.com/OSLL/MD-Code_generator'
Expand All @@ -257,7 +250,6 @@ def test_get_list_of_repos(self, mock_send_get_request):
}
]
),
Response([])
],
'expected_result': [
Repository(
Expand All @@ -283,14 +275,6 @@ def test_get_list_of_repos(self, mock_send_get_request):
'send_calls': [
call('/users/OSLL'),
call('/orgs/OSLL/repos', params=_REQUEST_PARAMS_1),
call(
'/orgs/OSLL/repos',
params=_REQUEST_PARAMS_2
),
call(
'/orgs/OSLL/repos',
params=_REQUEST_PARAMS_3
)
],
'send_rvs': [
Response({'type': 'Organization'}),
Expand All @@ -303,11 +287,7 @@ def test_get_list_of_repos(self, mock_send_get_request):
{
'name': 'aido-auto-feedback',
'html_url': 'https://github.com/OSLL/aido-auto-feedback'
}
]
),
Response(
[
},
{
'name': 'MD-Code_generator',
'html_url': 'https://github.com/OSLL/MD-Code_generator'
Expand All @@ -318,7 +298,6 @@ def test_get_list_of_repos(self, mock_send_get_request):
}
]
),
Response([])
],
'expected_result': [
Repository(
Expand Down Expand Up @@ -407,10 +386,6 @@ def test_get_pulls_info(self, mock_send_get_request):
'https://api.github.com/repos/OSLL/code-plagiarism/pulls/2/commits',
address=''
),
call(
'/repos/OSLL/code-plagiarism/pulls',
params=_REQUEST_PARAMS_2
),
call(
'https://api.github.com/repos/OSLL/code-plagiarism/pulls/3/commits',
address=''
Expand All @@ -419,10 +394,6 @@ def test_get_pulls_info(self, mock_send_get_request):
'https://api.github.com/repos/OSLL/code-plagiarism/pulls/4/commits',
address=''
),
call(
'/repos/OSLL/code-plagiarism/pulls',
params=_REQUEST_PARAMS_3
),
],
'send_rvs': [
Response(
Expand All @@ -444,13 +415,7 @@ def test_get_pulls_info(self, mock_send_get_request):
},
'state': 'Open',
'draft': True
}
]
),
Response([{'sha': 'jskfjsjskjfl'}]),
Response([{'sha': 'jzxvjipwerknmzxvj'}]),
Response(
[
},
{
'commits_url': 'https://api.github.com/repos/OSLL/code-plagiarism/pulls/3/commits',
'number': 3,
Expand All @@ -473,7 +438,8 @@ def test_get_pulls_info(self, mock_send_get_request):
),
Response([{'sha': 'jskfjsjskjfl'}]),
Response([{'sha': 'jzxvjipwerknmzxvj'}]),
Response([])
Response([{'sha': 'jskfjsjskjfl'}]),
Response([{'sha': 'jzxvjipwerknmzxvj'}]),
],
'expected_result': [
PullRequest(
Expand Down Expand Up @@ -768,7 +734,7 @@ def test_get_files_generator_from_sha_commit(self, mock_send_get_request,
'get_file_content_se': _GET_FILE_CONTENT_RES,
'expected_result': _GET_FILE_CONTENT_RES
},
{ # Check cache
{
'arguments': {
'owner': 'OSLL',
'repo': 'aido-auto-feedback',
Expand All @@ -780,9 +746,37 @@ def test_get_files_generator_from_sha_commit(self, mock_send_get_request,
call(
'/repos/OSLL/aido-auto-feedback/git/trees/zkueqwrkjsalu'
),
call(
api_url='/repos/OSLL/aido-auto-feedback/commits',
params={
'path': '/src',
'page': 1,
'per_page': 1,
'sha': _BRANCH1.name
}
),
call(
'/repos/OSLL/aido-auto-feedback/git/trees/jslkfjjeuwijsdmvd'
),
call(
api_url='/repos/OSLL/aido-auto-feedback/commits',
params={
'path': '/src/utils.py',
'page': 1,
'per_page': 1,
'sha': _BRANCH1.name
}
),
call(
api_url='/repos/OSLL/aido-auto-feedback/commits',
params={
'path': '/src/tests.py',
'page': 1,
'per_page': 1,
'sha': _BRANCH1.name
}
),

],
'send_se': [
Response(
Expand All @@ -801,6 +795,7 @@ def test_get_files_generator_from_sha_commit(self, mock_send_get_request,
],
}
),
Response(_COMMIT1_RESP),
Response(
{
'tree': [
Expand All @@ -817,6 +812,9 @@ def test_get_files_generator_from_sha_commit(self, mock_send_get_request,
]
}
),
Response(_COMMIT2_RESP),
Response(_COMMIT1_RESP),
Response(_COMMIT2_RESP),
],
'get_file_content_calls': [
call(
Expand Down Expand Up @@ -886,14 +884,9 @@ def test_get_list_repo_branches(self, mock_send_get_request):
'/repos/OSLL/aido-auto-feedback/branches',
params=_REQUEST_PARAMS_1
),
call(
'/repos/OSLL/aido-auto-feedback/branches',
params=_REQUEST_PARAMS_2
),
],
'send_se': [
Response([_BRANCH_INFO1, _BRANCH_INFO2]),
Response([])
],
'expected_result': [
Branch(
Expand All @@ -914,19 +907,9 @@ def test_get_list_repo_branches(self, mock_send_get_request):
'/repos/moevm/asm_web_debug/branches',
params=_REQUEST_PARAMS_1
),
call(
'/repos/moevm/asm_web_debug/branches',
params=_REQUEST_PARAMS_2
),
call(
'/repos/moevm/asm_web_debug/branches',
params=_REQUEST_PARAMS_3
),
],
'send_se': [
Response([_BRANCH_INFO1]),
Response([_BRANCH_INFO2]),
Response([])
Response([_BRANCH_INFO1, _BRANCH_INFO2]),
],
'expected_result': [
Branch(
Expand Down

0 comments on commit 8d8821c

Please sign in to comment.