Skip to content

Commit b2e79a5

Browse files
committed
add test app and github action
1 parent 14f4b72 commit b2e79a5

File tree

9 files changed

+239
-0
lines changed

9 files changed

+239
-0
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Django CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.9'
23+
24+
- name: Uninstall globally installed referrals (if any)
25+
run: |
26+
python -m pip uninstall -y referrals || true # Uninstall if globally installed
27+
28+
- name: Install project dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install -e . # Install the package in editable mode
32+
33+
- name: Set environment variables
34+
run: echo "BASE_REFERRAL_LINK=http://localhost:8000/" >> $GITHUB_ENV
35+
36+
- name: Set up the test database
37+
run: |
38+
python test_app/manage.py migrate --noinput
39+
40+
- name: Run Django tests
41+
run: |
42+
python test_app/manage.py test referrals

test_app/db.sqlite3

200 KB
Binary file not shown.

test_app/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_app.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

test_app/test_app/__init__.py

Whitespace-only changes.

test_app/test_app/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for test_app project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_app.settings')
15+
16+
application = get_asgi_application()

test_app/test_app/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
django-referral-system

test_app/test_app/settings.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
"""
2+
Django settings for test_app project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
from datetime import timedelta
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
# Quick-start development settings - unsuitable for production
19+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
20+
21+
# SECURITY WARNING: keep the secret key used in production secret!
22+
SECRET_KEY = 'django-insecure-@qjf@x+&h4^+idzim^d(lk@4@^v+x9=#%$757^+)ocqxw=k%$x'
23+
24+
# SECURITY WARNING: don't run with debug turned on in production!
25+
DEBUG = True
26+
27+
ALLOWED_HOSTS = ['*']
28+
29+
# Application definition
30+
31+
INSTALLED_APPS = [
32+
'django.contrib.admin',
33+
'django.contrib.auth',
34+
'django.contrib.contenttypes',
35+
'django.contrib.sessions',
36+
'django.contrib.messages',
37+
'django.contrib.staticfiles',
38+
'referrals',
39+
]
40+
41+
MIDDLEWARE = [
42+
'django.middleware.security.SecurityMiddleware',
43+
'django.contrib.sessions.middleware.SessionMiddleware',
44+
'django.middleware.common.CommonMiddleware',
45+
'django.middleware.csrf.CsrfViewMiddleware',
46+
'django.contrib.auth.middleware.AuthenticationMiddleware',
47+
'django.contrib.messages.middleware.MessageMiddleware',
48+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
49+
]
50+
51+
ROOT_URLCONF = 'test_app.urls'
52+
53+
TEMPLATES = [
54+
{
55+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
56+
'DIRS': [],
57+
'APP_DIRS': True,
58+
'OPTIONS': {
59+
'context_processors': [
60+
'django.template.context_processors.debug',
61+
'django.template.context_processors.request',
62+
'django.contrib.auth.context_processors.auth',
63+
'django.contrib.messages.context_processors.messages',
64+
],
65+
},
66+
},
67+
]
68+
69+
WSGI_APPLICATION = 'test_app.wsgi.application'
70+
71+
# Database
72+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
73+
74+
DATABASES = {
75+
'default': {
76+
'ENGINE': 'django.db.backends.sqlite3',
77+
'NAME': BASE_DIR / 'db.sqlite3',
78+
}
79+
}
80+
81+
# Password validation
82+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
83+
84+
AUTH_PASSWORD_VALIDATORS = [
85+
{
86+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
87+
},
88+
{
89+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
90+
},
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
96+
},
97+
]
98+
99+
# Internationalization
100+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
101+
102+
LANGUAGE_CODE = 'en-us'
103+
104+
TIME_ZONE = 'UTC'
105+
106+
USE_I18N = True
107+
108+
USE_TZ = True
109+
110+
# Static files (CSS, JavaScript, Images)
111+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
112+
113+
STATIC_URL = 'static/'
114+
115+
# Default primary key field type
116+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
117+
118+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

test_app/test_app/urls.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
URL configuration for test_app project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.1/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
from django.contrib import admin
18+
from django.urls import path, include
19+
20+
21+
urlpatterns = [
22+
path('admin/', admin.site.urls),
23+
path('referrals/', include("referrals.urls")),
24+
]

test_app/test_app/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for test_app project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_app.settings')
15+
16+
application = get_wsgi_application()

0 commit comments

Comments
 (0)