Skip to content

add testing on pyconkr-api-v2 #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/pull-request-merge-precondition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Pull Request Merge Precondition
on:
pull_request:

permissions:
contents: read
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -11,7 +15,11 @@ jobs:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
persist-credentials: true # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo

- uses: psf/black@stable
with:
options: "--check --verbose --exclude migrations"
Expand All @@ -20,3 +28,19 @@ jobs:
with:
configuration: "--check-only --diff --profile black"
requirementsFiles: "requirements.txt"

- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install pytest-cov

- name: run pytest
run: |
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=pyconkr ./ | tee pytest-coverage.txt

#- name: Pytest coverage comment
# uses: MishaKav/pytest-coverage-comment@main
# with:
# pytest-coverage-path: ./pytest-coverage.txt
# junitxml-path: ./pytest.xml
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@
* mac
* brew install mysql-client
* pip install -r requirements.txt

## how to run localtesting ( sqlite3 based )
```
# to setup pytest and requirements
pip install -r requirements-dev.txt
# run test
pytest
```
10 changes: 10 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest


# TODO
# https://djangostars.com/blog/django-pytest-testing/#header17
@pytest.fixture
def api_client():
from rest_framework.test import APIClient

return APIClient()
Empty file modified manage.py
100644 → 100755
Empty file.
21 changes: 21 additions & 0 deletions pyconkr/settings-localtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

from pyconkr.settings import *

DEBUG = True

ALLOWED_HOSTS += [
"*",
]


# RDS
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}

# django-storages: TODO fix to in memory?
del MEDIA_ROOT
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
STATICFILES_STORAGE = "storages.backends.s3boto3.S3StaticStorage"
AWS_S3_ACCESS_KEY_ID = os.getenv("AWS_S3_ACCESS_KEY_ID")
AWS_S3_SECRET_ACCESS_KEY = os.getenv("AWS_S3_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = "pyconkr-api-v2-static-dev"
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
DJANGO_SETTINGS_MODULE = pyconkr.settings-localtest
# -- recommended but optional:
python_files = tests.py test_*.py *_tests.py
addopts = --no-migrations
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-r requirements.txt
black
isort
pytest
pytest-django
25 changes: 24 additions & 1 deletion sponsor/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
from django.test import TestCase
import pytest
from django.contrib.auth import get_user_model

from sponsor.models import SponsorLevel

pytestmark = pytest.mark.django_db

UserModel = get_user_model()


@pytest.mark.django_db
class TestSponsorLevelModel:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오 좋아요 :-)

짬짬이 테스트 추가해보겠습니다

pytestmark = pytest.mark.django_db

def test_sponsor_level_creation_success(self):
assert SponsorLevel.objects.count() == 0
SponsorLevel.objects.create(
name="test",
desc="test desc",
visible=True,
limit=1,
)
assert SponsorLevel.objects.count() != 0


# Create your tests here.