forked from sudiptob2/cf-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sudiptob2#3] test: request parser tests added
- Loading branch information
Showing
2 changed files
with
20 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import pytest | ||
|
||
from app.constant import Constant | ||
from app.models.user import User | ||
from app.services.cf_request_handler import CFRequestHandler | ||
from app.services.cf_response_parser import CFResponseParser | ||
|
||
|
||
class TestCFReqParser: | ||
"""Class for testing codeforces request parser.""" | ||
|
||
class TestCFReqHandler: | ||
"""Class for testing codeforces request handlers.""" | ||
def test_parse_response(self, mocker, user_info, user_submission, rating_changes): | ||
"""Tests CFResponseParser.parse_response.""" | ||
user = User() | ||
|
||
def test_make_request(self): | ||
"""Tests CFRequestHandler.make_request.""" | ||
CFRequestHandler.make_request() | ||
def fake_make_request(): | ||
CFRequestHandler.user_info = user_info | ||
CFRequestHandler.user_submission = user_submission | ||
CFRequestHandler.rating_changes = rating_changes | ||
|
||
assert CFRequestHandler.user_info is not None | ||
assert CFRequestHandler.user_submission is not None | ||
assert CFRequestHandler.user_submission is not None | ||
mocker.patch.object(CFRequestHandler, 'make_request', fake_make_request) | ||
CFResponseParser.parse() | ||
|
||
def test_make_request_invalid(self): | ||
"""Tests CFRequestHandler.make_request.""" | ||
with pytest.raises(SystemExit): | ||
Constant.USER_INFO = 'https://somedsdfdf.com' | ||
CFRequestHandler.make_request() | ||
assert user.rating == user_info.get('rating') | ||
assert user.submissions == len(user_submission) | ||
assert user.contests == len(rating_changes) |