Skip to content

Commit

Permalink
Tests (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolab committed Jun 19, 2021
1 parent eb51d71 commit 87e956a
Show file tree
Hide file tree
Showing 25 changed files with 461 additions and 102 deletions.
87 changes: 34 additions & 53 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,40 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}

# test:
# runs-on: ubuntu-latest
# needs: lint
# continue-on-error: ${{ matrix.experimental }}
# strategy:
# matrix:
# include:
# - python: "3.6"
# django: "Django>=2.2,<2.3"
# wagtail: "wagtail>=2.10,<2.11"
# experimental: false
# - python: "3.7"
# django: "Django>=3.0,<3.1"
# wagtail: "wagtail>=2.11,<2.14"
# experimental: false
# - python: "3.8"
# django: "Django>=3.1,<3.2"
# wagtail: "wagtail>=2.11,<2.14"
# experimental: false
# - python: "3.9"
# django: "Django>=3.1,<3.2"
# wagtail: "wagtail>=2.11,<2.14"
# experimental: false
# - python: "3.9"
# django: "Django>=3.1,<3.3"
# wagtail: "git+https://github.com/wagtail/wagtail.git@main#egg=wagtail"
# experimental: true
# services:
# postgres:
# image: postgres:13
# ports:
# - 5432:5432
# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
# steps:
# - uses: actions/checkout@v2
# - name: Set up Python ${{ matrix.python }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python }}
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install "psycopg2>=2.6"
# pip install "${{ matrix.django }}"
# pip install "${{ matrix.wagtail }}"
# pip install -e .[testing]
# - name: Test
# run: python runtests.py
# env:
# DATABASE_ENGINE: django.db.backends.postgresql
# DATABASE_HOST: localhost
# DATABASE_USER: postgres
# DATABASE_PASS: postgres
tests:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
needs: lint

strategy:
matrix:
python-version: ["3.8", "3.9"]
experimental: [false]
include:
- python-version: "3.x"
toxenv: "djangomain"
experimental: true

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade tox tox-py tox-venv
- name: Run tox targets for Python ${{ matrix.python-version }}
if: ${{ matrix.toxenv != 'djangomain' }}
continue-on-error: ${{ matrix.experimental }}
run: tox --py current

- name: Run '${{ matrix.toxenv }}' tox targets
if: ${{ matrix.toxenv == 'djangomain' }}
continue-on-error: ${{ matrix.experimental }}
run: tox -e ${{ matrix.toxenv }}

build_and_publish:
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build/
dist/
.tox/
venv/

db.sqlite3
.coverage
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## 0.7.0 - 18 June 2021

- Add test suite
- Move all options in a single setting and allow further customisations ([#82](https://github.com/torchbox/wagtail-markdown/pull/82)) - Thanks @rokdd

### 0.7.0-rc2 - 15th June 2021
Expand Down
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
global-exclude *.py[cod] __pycache__
include LICENSE *.md
graft wagtailmarkdown
prune wagtailmarkdown/tests
exclude .pre-commit-config.yaml runtests.py tox.ini
exclude .pre-commit-config.yaml tox.ini venv db.sqlite3 .tox
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ known_django = "django"
known_wagtail = "wagtail"
known_first_party = ['wagtailmarkdown']
sections = ['FUTURE', 'STDLIB', 'DJANGO', 'WAGTAIL', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER']
skip=['migrations', '.git', '__pycache__', 'venv']
skip=['migrations', '.git', '__pycache__', 'venv', '.github', '.tox', 'build', 'dist']
18 changes: 0 additions & 18 deletions runtests.py

This file was deleted.

7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ universal = 1
max-line-length=88
select = C,E,F,W,B,B950,I
ignore = E203,E501,W503

[coverage:run]
source = wagtailmarkdown

[coverage:report]
exclude_lines =
pragma: no cover
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ def get_git_revision_hash():
]


TESTING_REQUIRES = [
"dj_database_url==0.5.0",
]


CLASSIFIERS = [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
Expand Down Expand Up @@ -74,5 +69,4 @@ def get_git_revision_hash():
packages=find_packages(),
include_package_data=True,
classifiers=CLASSIFIERS,
extras_require={"testing": TESTING_REQUIRES},
)
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testapp.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
Empty file added tests/testapp/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/testapp/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testapp.settings.dev")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
72 changes: 72 additions & 0 deletions tests/testapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Generated by Django 3.2.4 on 2021-06-18 11:36

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.fields
import wagtailmarkdown.blocks
import wagtailmarkdown.fields


class Migration(migrations.Migration):

initial = True

dependencies = [
("wagtailcore", "0059_apply_collection_ordering"),
]

operations = [
migrations.CreateModel(
name="TestPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("body", wagtailmarkdown.fields.MarkdownField(blank=True)),
],
options={
"abstract": False,
},
bases=("wagtailcore.page",),
),
migrations.CreateModel(
name="TestWithStreamFieldPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
(
"body",
wagtail.core.fields.StreamField(
[
(
"markdown",
wagtailmarkdown.blocks.MarkdownBlock(icon="code"),
)
],
blank=True,
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page",),
),
]
Empty file.
22 changes: 22 additions & 0 deletions tests/testapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.core.blocks import StreamBlock
from wagtail.core.fields import StreamField
from wagtail.core.models import Page

from wagtailmarkdown.blocks import MarkdownBlock
from wagtailmarkdown.edit_handlers import MarkdownPanel
from wagtailmarkdown.fields import MarkdownField


class TestPage(Page):
body = MarkdownField(blank=True)
content_panels = [MarkdownPanel("body")]


class MyStreamBlock(StreamBlock):
markdown = MarkdownBlock(icon="code")


class TestWithStreamFieldPage(Page):
body = StreamField(MyStreamBlock, blank=True)
content_panels = [StreamFieldPanel("body")]
57 changes: 57 additions & 0 deletions tests/testapp/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

SECRET_KEY = "fake_secret_key_to_run_tests" # pragma: allowlist secret

INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"wagtail.documents",
"wagtail.images",
"wagtail.users",
"wagtail.core",
"wagtail.admin",
"taggit",
"wagtailmarkdown",
"testapp",
]

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
],
},
},
]

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

MEDIA_ROOT = os.path.join(BASE_DIR, "media")

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"

ROOT_URLCONF = "testapp.urls"

MIDDLEWARE = [
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
]

ALLOWED_HOSTS = ["*"]

PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]
Empty file added tests/testapp/tests/__init__.py
Empty file.

0 comments on commit 87e956a

Please sign in to comment.