Split up tests.
This commit is contained in:
parent
399ebd1d6f
commit
cf84e4aa4a
5 changed files with 88 additions and 77 deletions
|
@ -31,6 +31,9 @@ The package requires Wagtail 2.5 or above.
|
|||
|
||||
1. `poetry build`
|
||||
|
||||
## Run tests
|
||||
1. `poetry install --dev`
|
||||
1. `poetry run pytest`
|
||||
|
||||
## Contributors
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ python = "^3.6"
|
|||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = "^3.0"
|
||||
wagtail = "^2.5"
|
||||
pytest-django = "^3.8"
|
||||
pytest-pythonpath = "^0.7.3"
|
||||
wagtail-factories = "^2.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry>=0.12"]
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
import pytest
|
||||
from wagtail.core.models import Site
|
||||
|
||||
from tests.testapp import factories
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def site():
|
||||
from wagtail.core.models import Site
|
||||
site = Site.objects.get(is_default_site=True)
|
||||
return site
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def advert():
|
||||
advert = factories.AdvertFactory(text="advert", url="https://www.example.com")
|
||||
advert.save()
|
||||
yield advert
|
||||
|
|
|
@ -2,85 +2,74 @@ import os
|
|||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
ADMINS = (
|
||||
('test@example.com', 'TEST-R'),
|
||||
)
|
||||
ADMINS = (("test@example.com", "TEST-R"),)
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': 'tests.db',
|
||||
},
|
||||
}
|
||||
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "tests.db"}}
|
||||
|
||||
SECRET_KEY = '_uobce43e5osp8xgsffssffsds2_16%y$sf*5(12vfg25hpnxik_*'
|
||||
SECRET_KEY = "_uobce43e5osp8xgsffssffsds2_16%y$sf*5(12vfg25hpnxik_*"
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'wagtail.contrib.forms',
|
||||
'wagtail.contrib.redirects',
|
||||
'wagtail.embeds',
|
||||
'wagtail.sites',
|
||||
'wagtail.users',
|
||||
'wagtail.snippets',
|
||||
'wagtail.documents',
|
||||
'wagtail.images',
|
||||
'wagtail.search',
|
||||
'wagtail.admin',
|
||||
'wagtail.core',
|
||||
'modelcluster',
|
||||
'taggit',
|
||||
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
"wagtail.contrib.forms",
|
||||
"wagtail.contrib.redirects",
|
||||
"wagtail.embeds",
|
||||
"wagtail.sites",
|
||||
"wagtail.users",
|
||||
"wagtail.snippets",
|
||||
"wagtail.documents",
|
||||
"wagtail.images",
|
||||
"wagtail.search",
|
||||
"wagtail.admin",
|
||||
"wagtail.core",
|
||||
"modelcluster",
|
||||
"taggit",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.sites",
|
||||
"django.contrib.staticfiles",
|
||||
# App Under test
|
||||
'wagtail_draftail_snippet',
|
||||
"wagtail_draftail_snippet",
|
||||
# Test app
|
||||
'tests.testapp'
|
||||
"tests.testapp",
|
||||
]
|
||||
|
||||
MIDDLEWARE = (
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'wagtail.core.middleware.SiteMiddleware',
|
||||
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.locale.LocaleMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"wagtail.core.middleware.SiteMiddleware",
|
||||
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
|
||||
)
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [
|
||||
os.path.join(BASE_DIR, 'templates'),
|
||||
],
|
||||
'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',
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [os.path.join(BASE_DIR, "templates")],
|
||||
"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",
|
||||
],
|
||||
"loaders": [
|
||||
"django.template.loaders.filesystem.Loader",
|
||||
"django.template.loaders.app_directories.Loader",
|
||||
],
|
||||
'loaders': [
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
ROOT_URLCONF = 'tests.urls'
|
||||
ROOT_URLCONF = "tests.urls"
|
||||
|
||||
WAGTAIL_SITE_NAME = "Test Site",
|
||||
WAGTAIL_SITE_NAME = ("Test Site",)
|
||||
SITE_ID = 1
|
||||
|
|
|
@ -1,22 +1,28 @@
|
|||
import pytest
|
||||
|
||||
from tests.testapp import factories
|
||||
from wagtail_draftail_snippet.richtext import SnippetLinkHandler
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_snippet_link_handler():
|
||||
advert = factories.AdvertFactory(text='advert', url='https://www.example.com')
|
||||
advert.save()
|
||||
class TestSnippetLinkHandler:
|
||||
@pytest.mark.django_db
|
||||
def test_advert_setup_correctly(self, advert):
|
||||
assert advert.text == "advert"
|
||||
assert advert.url == "https://www.example.com"
|
||||
|
||||
assert advert.text == 'advert'
|
||||
assert advert.url == 'https://www.example.com'
|
||||
@pytest.mark.django_db
|
||||
def test_snippet_create_empty_link_on_error(self, advert):
|
||||
"""
|
||||
Empty link created in case of exception
|
||||
"""
|
||||
|
||||
# Empty link created in case of exception
|
||||
result = SnippetLinkHandler.expand_db_attributes({'id': 0})
|
||||
assert result == "<a>"
|
||||
result = SnippetLinkHandler.expand_db_attributes({"id": 0})
|
||||
assert result == "<a>"
|
||||
|
||||
# Test snippet template render correctly
|
||||
attrs = {'id': 1, 'data-app-name': 'testapp', 'data-model-name': 'Advert'}
|
||||
result = SnippetLinkHandler.expand_db_attributes(attrs)
|
||||
assert result == f'<a href="{ advert.url }/{ advert.id }">'
|
||||
@pytest.mark.django_db
|
||||
def test_snippet_link_handler_renders(self, advert):
|
||||
"""
|
||||
Test snippet template renders correctly
|
||||
"""
|
||||
|
||||
attrs = {"id": 1, "data-app-name": "testapp", "data-model-name": "Advert"}
|
||||
result = SnippetLinkHandler.expand_db_attributes(attrs)
|
||||
assert result == f'<a href="{advert.url}/{advert.id}">'
|
||||
|
|
Reference in a new issue