Skip to content

Commit 72c0160

Browse files
authored
Merge pull request #22 from darjeeling/add_testing_spondor_model
2 parents 69160a1 + 092955b commit 72c0160

File tree

8 files changed

+98
-2
lines changed

8 files changed

+98
-2
lines changed

.github/workflows/pull-request-merge-precondition.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Pull Request Merge Precondition
33
on:
44
pull_request:
55

6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
610
jobs:
711
build:
812
runs-on: ubuntu-latest
@@ -11,7 +15,11 @@ jobs:
1115
python-version: [3.8]
1216

1317
steps:
14-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
19+
with:
20+
persist-credentials: true # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
21+
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
22+
1523
- uses: psf/black@stable
1624
with:
1725
options: "--check --verbose --exclude migrations"
@@ -20,3 +28,19 @@ jobs:
2028
with:
2129
configuration: "--check-only --diff --profile black"
2230
requirementsFiles: "requirements.txt"
31+
32+
- name: install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install -r requirements-dev.txt
36+
pip install pytest-cov
37+
38+
- name: run pytest
39+
run: |
40+
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=pyconkr ./ | tee pytest-coverage.txt
41+
42+
#- name: Pytest coverage comment
43+
# uses: MishaKav/pytest-coverage-comment@main
44+
# with:
45+
# pytest-coverage-path: ./pytest-coverage.txt
46+
# junitxml-path: ./pytest.xml

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@
1010
* mac
1111
* brew install mysql-client
1212
* pip install -r requirements.txt
13+
14+
## how to run localtesting ( sqlite3 based )
15+
```
16+
# to setup pytest and requirements
17+
pip install -r requirements-dev.txt
18+
# run test
19+
pytest
20+
```

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
3+
4+
# TODO
5+
# https://djangostars.com/blog/django-pytest-testing/#header17
6+
@pytest.fixture
7+
def api_client():
8+
from rest_framework.test import APIClient
9+
10+
return APIClient()

manage.py

100644100755
File mode changed.

pyconkr/settings-localtest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
3+
from pyconkr.settings import *
4+
5+
DEBUG = True
6+
7+
ALLOWED_HOSTS += [
8+
"*",
9+
]
10+
11+
12+
# RDS
13+
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
14+
15+
# django-storages: TODO fix to in memory?
16+
del MEDIA_ROOT
17+
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
18+
STATICFILES_STORAGE = "storages.backends.s3boto3.S3StaticStorage"
19+
AWS_S3_ACCESS_KEY_ID = os.getenv("AWS_S3_ACCESS_KEY_ID")
20+
AWS_S3_SECRET_ACCESS_KEY = os.getenv("AWS_S3_SECRET_ACCESS_KEY")
21+
AWS_STORAGE_BUCKET_NAME = "pyconkr-api-v2-static-dev"

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
DJANGO_SETTINGS_MODULE = pyconkr.settings-localtest
3+
# -- recommended but optional:
4+
python_files = tests.py test_*.py *_tests.py
5+
addopts = --no-migrations

requirements-dev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-r requirements.txt
2+
black
3+
isort
4+
pytest
5+
pytest-django

sponsor/tests.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1-
from django.test import TestCase
1+
import pytest
2+
from django.contrib.auth import get_user_model
3+
4+
from sponsor.models import SponsorLevel
5+
6+
pytestmark = pytest.mark.django_db
7+
8+
UserModel = get_user_model()
9+
10+
11+
@pytest.mark.django_db
12+
class TestSponsorLevelModel:
13+
pytestmark = pytest.mark.django_db
14+
15+
def test_sponsor_level_creation_success(self):
16+
assert SponsorLevel.objects.count() == 0
17+
SponsorLevel.objects.create(
18+
name="test",
19+
desc="test desc",
20+
visible=True,
21+
limit=1,
22+
)
23+
assert SponsorLevel.objects.count() != 0
24+
225

326
# Create your tests here.

0 commit comments

Comments
 (0)