Skip to content

Commit

Permalink
Added pytest and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VadVergasov committed Mar 16, 2021
1 parent 7f78460 commit 3d00c59
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 54 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install twine
run: >-
pip install -r requirements.txt
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Python package

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pytest tests/test_api.py --api_key ${{ secrets.codeforces_api_key }} --api_secret ${{ secrets.codeforces_api_secret }}
17 changes: 13 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@
!/LICENSE
!/*.md
!/requirements.txt

!tests/
tests/*
!tests/main.py
!tests/conf.py.template
!/codeforces_api
/codeforces_api/
!tests/test_api.py
!tests/conftest.py

!codeforces_api/
codeforces_api/*
!codeforces_api/__init__.py
!codeforces_api/api_request_maker.py
!codeforces_api/api_requests.py
!codeforces_api/parse_methods.py
!codeforces_api/types.py
!codeforces_api/version.py

!/.github
2 changes: 1 addition & 1 deletion codeforces_api/api_request_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def generate_request(self, method_name, **fields):
def check_return_code(self, response):
"""
Checks if a returned response is OK.
If not OK Exception will be raised will additional info.
"""
if response["status"] != "OK":
Expand Down
5 changes: 2 additions & 3 deletions codeforces_api/api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def user_info(self, handles):
Get user.info.
handles should be a list of users, up to 10000.
Returns parsed response from codeforces.com.
"""
if not isinstance(handles, list):
Expand Down Expand Up @@ -342,7 +342,7 @@ def user_rated_list(self, active_only=False):
def user_rating(self, handle):
"""
Get user.rating.
handle should be a string.
Returns parsed response from codeforces.com.
Expand Down Expand Up @@ -377,4 +377,3 @@ def user_status(self, handle, start=-1, count=-1):
Submission.de_json(submission)
for submission in self._make_request("user.status", **parameters)
]

4 changes: 2 additions & 2 deletions codeforces_api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(

def to_dict(self):
return {
"hand;e": self.handle,
"handle": self.handle,
"email": self.email,
"vk_id": self.vk_id,
"open_id": self.open_id,
Expand Down Expand Up @@ -352,7 +352,7 @@ def de_json(cls, json_string):
contest_name = obj["contestName"]
handle = obj["handle"]
rank = obj["rank"]
rating_update_time_seconds = ["ratingUpdateTimeSeconds"]
rating_update_time_seconds = obj["ratingUpdateTimeSeconds"]
old_rating = obj["oldRating"]
new_rating = obj["newRating"]
return cls(
Expand Down
2 changes: 1 addition & 1 deletion codeforces_api/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.3"
__version__ = "2.0.4"
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
appdirs==1.4.4
astroid==2.5.1
atomicwrites==1.4.0
attrs==20.3.0
black==20.8b1
bleach==3.3.0
certifi==2020.12.5
Expand All @@ -9,6 +11,7 @@ colorama==0.4.4
docutils==0.16
idna==2.10
importlib-metadata==3.7.3
iniconfig==1.1.1
isort==5.7.0
keyring==23.0.0
lazy-object-proxy==1.5.2
Expand All @@ -18,9 +21,12 @@ mypy-extensions==0.4.3
packaging==20.9
pathspec==0.8.1
pkginfo==1.7.0
pluggy==0.13.1
py==1.10.0
Pygments==2.8.1
pylint==2.7.2
pyparsing==2.4.7
pytest==6.2.2
pywin32-ctypes==0.2.0
readme-renderer==29.0
regex==2020.11.13
Expand Down
2 changes: 0 additions & 2 deletions tests/conf.py.template

This file was deleted.

29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Config file for tests
"""
import pytest


def pytest_addoption(parser):
parser.addoption(
"--api_key",
action="store",
default="api_key",
help="API key for tests",
)
parser.addoption(
"--api_secret",
action="store",
default="api_secret",
help="API secret for tests",
)


@pytest.fixture
def api_key(request):
return request.config.getoption("--api_key")


@pytest.fixture
def api_secret(request):
return request.config.getoption("--api_secret")
40 changes: 0 additions & 40 deletions tests/main.py

This file was deleted.

Loading

0 comments on commit 3d00c59

Please sign in to comment.