Skip to content

Commit

Permalink
Merge pull request #41 from roverdotcom/pytest
Browse files Browse the repository at this point in the history
Switched test runs to pytest
  • Loading branch information
melinath authored Mar 29, 2019
2 parents a54bf27 + 9cec151 commit a1be98f
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 90 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ env:
- DJANGO_VERSION=1.11
install:
- pip install -q Django==$DJANGO_VERSION
- python setup.py -q install
- pip install .[flake8]
- pip install -e .[flake8,tests]
script:
- flake8
- ./run_tests.py
- pytest
12 changes: 0 additions & 12 deletions django_inlinecss/tests/constants.py

This file was deleted.

17 changes: 9 additions & 8 deletions django_inlinecss/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@

import os

from django.conf import settings
from django.template.loader import get_template
from django.test import TestCase
from django.test.utils import override_settings
from django.utils.safestring import mark_safe
from mock import patch

from django_inlinecss.tests.constants import TESTS_STATIC_DIR


@override_settings(
STATIC_ROOT=TESTS_STATIC_DIR)
class InlinecssTests(TestCase):
def setUp(self):
super(InlinecssTests, self).setUp()
Expand Down Expand Up @@ -153,21 +150,25 @@ def test_comments_are_ignored(self):
r'This is the "bar" div.\s+<!-- comment three -->\s+')


@override_settings(
STATIC_ROOT=TESTS_STATIC_DIR)
class DebugModeStaticfilesTests(TestCase):
@override_settings(DEBUG=True)
@patch('django.contrib.staticfiles.finders.find')
def test_debug_mode_uses_staticfiles_finder(self, find):
full_path = os.path.join(TESTS_STATIC_DIR, "foobar.css")
full_path = os.path.join(
settings.STATIC_ROOT,
'foobar.css',
)
find.return_value = full_path
template = get_template('single_staticfiles_css.html')
template.render({})
find.assert_called_once_with("foobar.css")

@patch('django.contrib.staticfiles.storage.staticfiles_storage.path')
def test_non_debug_mode_uses_staticfiles_storage(self, path):
full_path = os.path.join(TESTS_STATIC_DIR, "foobar.css")
full_path = os.path.join(
settings.STATIC_ROOT,
'foobar.css',
)
path.return_value = full_path
template = get_template('single_staticfiles_css.html')
template.render({})
Expand Down
66 changes: 0 additions & 66 deletions run_tests.py

This file was deleted.

7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[aliases]
test=./run_tests.py
test=pytest

[flake8]
max-line-length=120
Expand All @@ -14,3 +14,8 @@ force_single_line=True
default_section=THIRDPARTY
lines_after_imports=2
use_parentheses=True

[tool:pytest]
django_find_project = false
DJANGO_SETTINGS_MODULE = test_settings
python_files = test_*.py
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# What packages are required only for tests?
TESTS = [
'mock==2.0.0',
'pytest==4.3.1',
'pytest-django==3.4.8',
]

# What packages are optional?
Expand All @@ -27,6 +29,7 @@
'isort==4.3.4',
'testfixtures==6.3.0',
],
'tests': TESTS,
}


Expand Down
139 changes: 139 additions & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
"""
Django settings for test_project project.
Generated by 'django-admin startproject' using Django 1.11.20.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(__file__)


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'NOT_SECRET'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_inlinecss',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'test_project.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(
BASE_DIR,
'django_inlinecss',
'tests',
'templates',
),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'test_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(
BASE_DIR,
'django_inlinecss',
'tests',
'static',
)

0 comments on commit a1be98f

Please sign in to comment.