Skip to content

Commit

Permalink
[sudiptob2#3] test: request parser tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sudiptob2 committed Aug 18, 2022
1 parent 119ddd2 commit 1897586
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
3 changes: 3 additions & 0 deletions tests/fixtures/response_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@pytest.fixture
def user_info():
"""Returns sample codeforces user.info API response."""
return {
"lastName": "Khodyrev",
"lastOnlineTimeSeconds": 1655498450,
Expand All @@ -23,6 +24,7 @@ def user_info():

@pytest.fixture
def user_submission():
"""Sample response of codeforces submission API."""
return [
{
"id": 157298399,
Expand Down Expand Up @@ -65,6 +67,7 @@ def user_submission():

@pytest.fixture
def rating_changes():
"""Sample response of user rating API."""
return [
{
"contestId": 1,
Expand Down
33 changes: 17 additions & 16 deletions tests/test_utils/test_cf_request_parser.py
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)

0 comments on commit 1897586

Please sign in to comment.