Skip to content

Commit a446392

Browse files
committed
added workflow tests for different python versions, 3.9+ tuple to Tuple in security
1 parent 773548c commit a446392

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

.github/workflows/tests.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-20.04
10+
strategy:
11+
matrix:
12+
python-version: [3.6, 3.7, 3.8, 3.9]
13+
14+
services:
15+
postgres:
16+
image: postgres
17+
env:
18+
POSTGRES_DB: test
19+
POSTGRES_USER: test
20+
POSTGRES_PASSWORD: test
21+
options: >-
22+
--health-cmd pg_isready
23+
--health-interval 10s
24+
--health-timeout 5s
25+
--health-retries 5
26+
ports:
27+
- 30000:5432
28+
steps:
29+
- uses: actions/checkout@v2
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v2
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
- name: Load cached venv
36+
id: cached-poetry-dependencies
37+
uses: actions/cache@v2
38+
with:
39+
path: .venv
40+
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
41+
- name: Install dependencies and actiavte virtualenv
42+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
43+
run: |
44+
python -m venv .venv
45+
source .venv/bin/activate
46+
pip install -r {{cookiecutter.project_name}}/requirements-dev.txt
47+
pip install cookiecutter
48+
- name: Lint with flake8
49+
run: |
50+
source .venv/bin/activate
51+
# stop the build if there are Python syntax errors or undefined names
52+
cd \{\{cookiecutter.project_name\}\}/
53+
flake8 app --count --exit-zero --statistics
54+
- name: Test new cookiecuttered project is passing pytest test
55+
run: |
56+
source .venv/bin/activate
57+
python tests/create_test_project.py
58+
export TEST_DATABASE_HOSTNAME=localhost
59+
export TEST_DATABASE_USER=test
60+
export TEST_DATABASE_PASSWORD=test
61+
export TEST_DATABASE_PORT=30000
62+
export TEST_DATABASE_DB=test
63+
64+
pytest generated_project_for_tests

tests/__init__.py

Whitespace-only changes.

tests/create_test_project.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Creates template project in root folder with default values
3+
"""
4+
5+
from pathlib import Path
6+
7+
from cookiecutter.main import cookiecutter
8+
9+
ROOT_FOLDER = Path(__file__).parent.parent
10+
11+
12+
def main():
13+
cookiecutter(
14+
template=str(ROOT_FOLDER),
15+
no_input=True,
16+
extra_context={
17+
"project_name": "generated_project_for_tests",
18+
},
19+
)
20+
21+
22+
if __name__ == "__main__":
23+
main()

{{cookiecutter.project_name}}/app/core/security.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from datetime import datetime, timedelta
8-
from typing import Any, Union
8+
from typing import Any, Union, Tuple
99

1010
from jose import jwt
1111
from passlib.context import CryptContext
@@ -18,7 +18,7 @@
1818
ALGORITHM = "HS256"
1919

2020

21-
def create_access_token(subject: Union[str, Any]) -> tuple[str, datetime]:
21+
def create_access_token(subject: Union[str, Any]) -> Tuple[str, datetime]:
2222
now = datetime.utcnow()
2323
expire = now + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
2424

@@ -31,7 +31,7 @@ def create_access_token(subject: Union[str, Any]) -> tuple[str, datetime]:
3131
return encoded_jwt, expire
3232

3333

34-
def create_refresh_token(subject: Union[str, Any]) -> tuple[str, datetime]:
34+
def create_refresh_token(subject: Union[str, Any]) -> Tuple[str, datetime]:
3535
now = datetime.utcnow()
3636
expire = now + timedelta(minutes=settings.REFRESH_TOKEN_EXPIRE_MINUTES)
3737

0 commit comments

Comments
 (0)