Skip to content

Commit

Permalink
Small fixes (#14)
Browse files Browse the repository at this point in the history
* Linted with black

* Bump isort from 5.7.0 to 5.8.0 (#12)

* Updated cache in workflows

* Reusing code for checking user

* Added dependabot workflow

* Added GitHub actions to dependabot

* Added Github QL checking

* Added error info in get_response

* More info added on JSONDecodeError exception

* Updated version
  • Loading branch information
VadVergasov committed Mar 23, 2021
1 parent dd33ba6 commit a5ab427
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 58 deletions.
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
target-branch: develop
reviewers:
- VadVergasov
assignees:
- VadVergasov
allow:
- dependency-type: direct
- dependency-type: indirect
ignore:
- dependency-name: "idna"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
target-branch: develop
reviewers:
- VadVergasov
assignees:
- VadVergasov
33 changes: 33 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "CodeQL"

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
schedule:
- cron: "0 0 * * *"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: ["python"]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 0 additions & 2 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ jobs:
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
6 changes: 4 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- master
- develop
tags:
- "*"
pull_request:
branches:
- master
Expand All @@ -17,6 +19,8 @@ jobs:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- name: Print Github refs
run: echo ${{github.ref}}
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
Expand All @@ -27,8 +31,6 @@ jobs:
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 wheel
Expand Down
2 changes: 1 addition & 1 deletion codeforces_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
__all__ = ["CodeforcesApi", "CodeforcesApiRequestMaker", "CodeforcesParser"]
from codeforces_api.api_requests import CodeforcesApi
from codeforces_api.api_request_maker import CodeforcesApiRequestMaker
from codeforces_api.api_requests import CodeforcesApi
from codeforces_api.parse_methods import CodeforcesParser
from codeforces_api.types import *
9 changes: 5 additions & 4 deletions codeforces_api/api_request_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import random
import time
import hashlib
import collections
import hashlib
import json
import random
import time


class CodeforcesApiRequestMaker:
Expand Down Expand Up @@ -116,5 +116,6 @@ def get_response(self, request):
return response["result"]
except json.decoder.JSONDecodeError as error:
raise ValueError(
"A lot of users, try to reduce the number of users in the list"
"A lot of users, try to reduce the number of users in the list.\nError: %s.\nResponse text: %s"
% (str(error), request.text)
)
10 changes: 5 additions & 5 deletions codeforces_api/api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

from codeforces_api.api_request_maker import CodeforcesApiRequestMaker
from codeforces_api.types import (
User,
BlogEntry,
Comment,
RecentAction,
RatingChange,
Contest,
Hack,
Problem,
ProblemStatistic,
Submission,
Hack,
RanklistRow,
RatingChange,
RecentAction,
Submission,
User,
)


Expand Down
1 change: 1 addition & 0 deletions codeforces_api/parse_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
import requests
from lxml import html

from codeforces_api.api_requests import CodeforcesApi


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.6"
__version__ = "2.0.7"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ docutils==0.16
idna==2.10
importlib-metadata==3.7.3
iniconfig==1.1.1
isort==5.7.0
isort==5.8.0
keyring==23.0.0
lazy-object-proxy==1.5.2
lxml==4.6.2
Expand Down
26 changes: 26 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,29 @@ def api_key(request):
@pytest.fixture
def api_secret(request):
return request.config.getoption("--api_secret")


@pytest.fixture
def check_user():
def check(user):
assert user.email is None or isinstance(user.email, str)
assert user.open_id is None or isinstance(user.open_id, str)
assert user.first_name is None or isinstance(user.first_name, str)
assert user.last_name is None or isinstance(user.last_name, str)
assert user.country is None or isinstance(user.country, str)
assert user.vk_id is None or isinstance(user.vk_id, str)
assert user.country is None or isinstance(user.country, str)
assert user.city is None or isinstance(user.city, str)
assert user.organization is None or isinstance(user.organization, str)
assert isinstance(user.contribution, int)
assert user.rank is None or isinstance(user.rank, str)
assert user.rating is None or isinstance(user.rating, int)
assert user.max_rank is None or isinstance(user.max_rank, str)
assert user.max_rating is None or isinstance(user.max_rating, int)
assert isinstance(user.last_online, int)
assert isinstance(user.registration_time_seconds, int)
assert isinstance(user.friend_of_count, int)
assert isinstance(user.avatar, str)
assert isinstance(user.title_photo, str)

return check
48 changes: 6 additions & 42 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,54 +270,18 @@ def test_user_friends(api_key, api_secret):
assert "aropan" in friends or "gepardo" in friends


def test_user_info(api_key, api_secret):
def test_user_info(api_key, api_secret, check_user):
api = CodeforcesApi(api_key, api_secret)
info = api.user_info(["VadVergasov", "tourist"])
for user in info:
assert user.email is None or isinstance(user.email, str)
assert user.open_id is None or isinstance(user.open_id, str)
assert user.first_name is None or isinstance(user.first_name, str)
assert user.last_name is None or isinstance(user.last_name, str)
assert user.country is None or isinstance(user.country, str)
assert user.vk_id is None or isinstance(user.vk_id, str)
assert user.country is None or isinstance(user.country, str)
assert user.city is None or isinstance(user.city, str)
assert user.organization is None or isinstance(user.organization, str)
assert isinstance(user.contribution, int)
assert user.rank is None or isinstance(user.rank, str)
assert user.rating is None or isinstance(user.rating, int)
assert user.max_rank is None or isinstance(user.max_rank, str)
assert user.max_rating is None or isinstance(user.max_rating, int)
assert isinstance(user.last_online, int)
assert isinstance(user.registration_time_seconds, int)
assert isinstance(user.friend_of_count, int)
assert isinstance(user.avatar, str)
assert isinstance(user.title_photo, str)


def test_user_rated_list():
check_user(user)


def test_user_rated_list(check_user):
api = CodeforcesApi()
users = api.user_rated_list(True)
for user in users:
assert user.email is None or isinstance(user.email, str)
assert user.open_id is None or isinstance(user.open_id, str)
assert user.first_name is None or isinstance(user.first_name, str)
assert user.last_name is None or isinstance(user.last_name, str)
assert user.country is None or isinstance(user.country, str)
assert user.vk_id is None or isinstance(user.vk_id, str)
assert user.country is None or isinstance(user.country, str)
assert user.city is None or isinstance(user.city, str)
assert user.organization is None or isinstance(user.organization, str)
assert isinstance(user.contribution, int)
assert user.rank is None or isinstance(user.rank, str)
assert user.rating is None or isinstance(user.rating, int)
assert user.max_rank is None or isinstance(user.max_rank, str)
assert user.max_rating is None or isinstance(user.max_rating, int)
assert isinstance(user.last_online, int)
assert isinstance(user.registration_time_seconds, int)
assert isinstance(user.friend_of_count, int)
assert isinstance(user.avatar, str)
assert isinstance(user.title_photo, str)
check_user(user)


def test_user_rating():
Expand Down

0 comments on commit a5ab427

Please sign in to comment.