Skip to content

Commit 4351a2c

Browse files
committed
Add test infrastructure
1 parent a3bf809 commit 4351a2c

File tree

9 files changed

+242
-0
lines changed

9 files changed

+242
-0
lines changed

runtests.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import os
5+
import shutil
6+
import sys
7+
import warnings
8+
9+
from django.core.management import execute_from_command_line
10+
11+
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
12+
13+
14+
def make_parser():
15+
parser = argparse.ArgumentParser()
16+
parser.add_argument('--deprecation', choices=['pending', 'imminent', 'none'], default='imminent')
17+
return parser
18+
19+
20+
def parse_args(args=None):
21+
return make_parser().parse_known_args(args)
22+
23+
24+
def runtests():
25+
args, rest = parse_args()
26+
27+
if args.deprecation == 'pending':
28+
# Show all deprecation warnings
29+
warnings.simplefilter('default', DeprecationWarning)
30+
warnings.simplefilter('default', PendingDeprecationWarning)
31+
elif args.deprecation == 'imminent':
32+
# Show only imminent deprecation warnings
33+
warnings.simplefilter('default', DeprecationWarning)
34+
elif args.deprecation == 'none':
35+
# Deprecation warnings are ignored by default
36+
pass
37+
38+
argv = [sys.argv[0], 'test'] + rest
39+
40+
try:
41+
execute_from_command_line(argv)
42+
finally:
43+
from tests.settings import STATIC_ROOT
44+
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
45+
46+
47+
if __name__ == '__main__':
48+
runtests()

tests/__init__.py

Whitespace-only changes.

tests/settings.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
"""
2+
Django settings for django_libsass tests.
3+
4+
Generated by 'django-admin startproject' using Django 2.0.13.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.0/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'snbicjfchnkjnyhcojinbcojnghjn=*uv2e$gr5-7w2^j2y9y!'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'tests',
35+
36+
'compressor',
37+
38+
'django.contrib.admin',
39+
'django.contrib.auth',
40+
'django.contrib.contenttypes',
41+
'django.contrib.sessions',
42+
'django.contrib.messages',
43+
'django.contrib.staticfiles',
44+
]
45+
46+
MIDDLEWARE = [
47+
'django.middleware.security.SecurityMiddleware',
48+
'django.contrib.sessions.middleware.SessionMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.messages.middleware.MessageMiddleware',
53+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
54+
]
55+
56+
ROOT_URLCONF = 'tests.urls'
57+
58+
TEMPLATES = [
59+
{
60+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
61+
'DIRS': [],
62+
'APP_DIRS': True,
63+
'OPTIONS': {
64+
'context_processors': [
65+
'django.template.context_processors.debug',
66+
'django.template.context_processors.request',
67+
'django.contrib.auth.context_processors.auth',
68+
'django.contrib.messages.context_processors.messages',
69+
],
70+
},
71+
},
72+
]
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
76+
77+
DATABASES = {
78+
'default': {
79+
'ENGINE': 'django.db.backends.sqlite3',
80+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81+
}
82+
}
83+
84+
85+
# Password validation
86+
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
87+
88+
AUTH_PASSWORD_VALIDATORS = [
89+
{
90+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91+
},
92+
{
93+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94+
},
95+
{
96+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97+
},
98+
{
99+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100+
},
101+
]
102+
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/2.0/topics/i18n/
106+
107+
LANGUAGE_CODE = 'en-us'
108+
109+
TIME_ZONE = 'UTC'
110+
111+
USE_I18N = True
112+
113+
USE_L10N = True
114+
115+
USE_TZ = True
116+
117+
118+
# Static files (CSS, JavaScript, Images)
119+
# https://docs.djangoproject.com/en/2.0/howto/static-files/
120+
121+
STATIC_URL = '/static/'
122+
STATIC_ROOT = os.path.join(BASE_DIR, 'test-static')
123+
124+
# List of finder classes that know how to find static files in
125+
# various locations.
126+
STATICFILES_FINDERS = (
127+
'django.contrib.staticfiles.finders.FileSystemFinder',
128+
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
129+
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
130+
'compressor.finders.CompressorFinder',
131+
)
132+
133+
COMPRESS_PRECOMPILERS = (
134+
('text/x-scss', 'django_libsass.SassCompiler'),
135+
)

tests/static/css/index.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$background-color: #ddffdd;
2+
$foreground-color: #008800;
3+
4+
body {
5+
background-color: $background-color;
6+
7+
h1 {
8+
color: $foreground-color;
9+
}
10+
}

tests/templates/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% load compress static %}
2+
<!DOCTYPE HTML>
3+
<html>
4+
<head>
5+
<title>Hello django-libsass</title>
6+
{% compress css %}
7+
<link rel="stylesheet" type="text/x-scss" href="{% static "css/index.scss" %}" />
8+
{% endcompress %}
9+
</head>
10+
<body>
11+
<h1>It worked!</h1>
12+
</body>
13+
</html>

tests/tests/__init__.py

Whitespace-only changes.

tests/tests/test_sass.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.test import TestCase
2+
3+
4+
print("hello from test_sass")
5+
6+
class TestSass(TestCase):
7+
def test_sass(self):
8+
response = self.client.get('/')
9+
self.assertEqual(response.status_code, 200)

tests/urls.py

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

tests/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.shortcuts import render
2+
3+
4+
def index(request):
5+
return render(request, 'index.html')

0 commit comments

Comments
 (0)