Skip to content

Commit

Permalink
Add codecoverage measurement (#271)
Browse files Browse the repository at this point in the history
Co-authored-by: Brzuszek Maël <[email protected]>
  • Loading branch information
armanddidierjean and Brzuszek Maël authored Oct 20, 2023
1 parent 9adfbeb commit d72be92
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ jobs:
key: pytest_cache-${{ github.head_ref }}

- name: Run unit tests
run: python -m pytest
run: python -m pytest --cov

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ firebase.json
logs/

# Migrations scripts
migrations/versions/*.py
migrations/versions/*.py

# Pytest-cov
.coverage
3 changes: 0 additions & 3 deletions app/utils/types/raffle_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ class RaffleStatusType(str, Enum):
creation = "creation" # Can edit every parameter
open = "open" # Ordering is possible, no edition possible
lock = "lock" # Can't order

def __str__(self):
return f"{self.name}<{self.value}"
7 changes: 0 additions & 7 deletions app/utils/types/router.py

This file was deleted.

21 changes: 19 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extend-exclude = '''

[tool.isort]
profile = "black"
py_version=310
py_version = 310
skip_gitignore = true
skip_glob = [".git", "migrations/*"]

Expand All @@ -30,4 +30,21 @@ warn_unreachable = true

[tool.pytest.ini_options]
asyncio_mode = "auto"
filterwarnings = "error"
filterwarnings = "error"

[tool.coverage.run]
source_pkgs = ["app"]
omit = [
"main.py", # Main is just a wrapper and is not used during tests
"mailworker.py", # We don't use send mails during tests
"*matrix*", # We don't send logs to matrix during tests
]


[tool.coverage.report]
# Regexes for lines to exclude from consideration
# See https://coverage.readthedocs.io/en/latest/excluding.html#excluding for more info
exclude_also = []

skip_covered = true
show_missing = true
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ types-requests==2.31.0.2
types-redis==4.6.0.5
mypy==1.5.1
types-pytz==2023.3.1.1
pytest-cov==4.1.0
17 changes: 9 additions & 8 deletions tests/test_ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

def test_limiter():
change_redis_client_status(activated=True)
for _ in range(settings.REDIS_LIMIT - 1):
response = client.get(
"/health"
) # Fake endpoint, we don't care about the response
assert response.status_code == 404
response = client.get("/health")
assert response.status_code == 429
change_redis_client_status(activated=False)
try:
for _ in range(settings.REDIS_LIMIT - 1):
response = client.get("/information")
assert response.status_code == 200
for i in range(2):
response = client.get("/information")
assert response.status_code == 429
finally:
change_redis_client_status(activated=False)

0 comments on commit d72be92

Please sign in to comment.