Skip to content

Commit

Permalink
Merge pull request #4 from radiac/feature/django2.22
Browse files Browse the repository at this point in the history
Add tests and fix lint
  • Loading branch information
radiac committed Sep 13, 2020
2 parents 8f40271 + c58af8f commit e9fc3d2
Show file tree
Hide file tree
Showing 20 changed files with 337 additions and 21 deletions.
20 changes: 17 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
__pycache__/
# Dev
*.pyc
django_conversate.egg-info
__pycache__
node_modules

# Test
.coverage*
htmlcov
test_media

# Example
docker-compose.dev.yml
example/db.sqlite3
node_modules/

# Build
*.egg-info
build
dist
docs/_build
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
os: linux
dist: xenial
language: python
install:
- pip install --upgrade pip wheel setuptools
- pip install --upgrade virtualenv tox
script:
- tox

jobs:
include:

- python: '3.7'
env: TOXENV=py37-django2.2
- python: '3.7'
env: TOXENV=py37-django3.0
- python: '3.7'
env: TOXENV=py37-django3.1

- python: '3.8'
env: TOXENV=py38-django2.2
- python: '3.8'
env: TOXENV=py38-django3.0
- python: '3.8'
env: TOXENV=py38-django3.1

4 changes: 3 additions & 1 deletion conversate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import os
import time

from commonmark import commonmark
from django.contrib.auth import get_user_model
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.urls import reverse
from django.utils import html, timezone

from commonmark import commonmark
from emoji import emojize

from . import settings


User = get_user_model()


Expand Down
1 change: 1 addition & 0 deletions conversate/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings


# Number of lines to show on a page
PAGE_SIZE = getattr(settings, "CONVERSATE_PAGE_SIZE", 100)

Expand Down
1 change: 1 addition & 0 deletions conversate/templatetags/conversate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django import template


register = template.Library()


Expand Down
16 changes: 0 additions & 16 deletions conversate/tests.py

This file was deleted.

1 change: 1 addition & 0 deletions conversate/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from . import views


app_name = "conversate"

urlpatterns = [
Expand Down
1 change: 0 additions & 1 deletion conversate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import time

from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse
from django.urls import reverse

from . import settings
Expand Down
1 change: 1 addition & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os


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


Expand Down
1 change: 1 addition & 0 deletions example/example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.conf.urls import include, url
from django.contrib import admin


urlpatterns = [
url(r"^admin/", include(admin.site.urls)),
url(r"^conversate/", include("conversate.urls", namespace="conversate")),
Expand Down
1 change: 1 addition & 0 deletions example/example/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from django.core.wsgi import get_wsgi_application


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

application = get_wsgi_application()
1 change: 1 addition & 0 deletions example/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys


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

Expand Down
28 changes: 28 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Developer requirements
#

# Dev tools
black
flake8
isort
pip-tools

# Testing
model_bakery
pytest
pytest-black
pytest-cov
pytest-django
pytest-flake8
pytest-isort
tox

# Docs
sphinx
sphinx-autobuild

# Project (setup.cfg)
django-yaa-settings
commonmark
emoji
75 changes: 75 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile
#
alabaster==0.7.12 # via sphinx
appdirs==1.4.4 # via black, virtualenv
asgiref==3.2.10 # via django
attrs==20.2.0 # via pytest
babel==2.8.0 # via sphinx
black==20.8b1 # via -r requirements.in, pytest-black
certifi==2020.6.20 # via requests
chardet==3.0.4 # via requests
click==7.1.2 # via black, pip-tools
commonmark==0.9.1 # via -r requirements.in
coverage==5.2.1 # via pytest-cov
distlib==0.3.1 # via virtualenv
django-yaa-settings==1.1.0 # via -r requirements.in
#django==3.1.1 # via model-bakery
docutils==0.16 # via sphinx
emoji==0.6.0 # via -r requirements.in
filelock==3.0.12 # via tox, virtualenv
flake8==3.8.3 # via -r requirements.in, pytest-flake8
idna==2.10 # via requests
imagesize==1.2.0 # via sphinx
iniconfig==1.0.1 # via pytest
isort==5.5.2 # via -r requirements.in, pytest-isort
jinja2==2.11.2 # via sphinx
livereload==2.6.3 # via sphinx-autobuild
markupsafe==1.1.1 # via jinja2
mccabe==0.6.1 # via flake8
model-bakery==1.1.1 # via -r requirements.in
more-itertools==8.5.0 # via pytest
mypy-extensions==0.4.3 # via black
packaging==20.4 # via pytest, sphinx, tox
pathspec==0.8.0 # via black
pip-tools==5.3.1 # via -r requirements.in
pluggy==0.13.1 # via pytest, tox
py==1.9.0 # via pytest, tox
pycodestyle==2.6.0 # via flake8
pyflakes==2.2.0 # via flake8
pygments==2.7.0 # via sphinx
pyparsing==2.4.7 # via packaging
pytest-black==0.3.11 # via -r requirements.in
pytest-cov==2.10.1 # via -r requirements.in
pytest-django==3.9.0 # via -r requirements.in
pytest-flake8==1.0.6 # via -r requirements.in
pytest-isort==1.2.0 # via -r requirements.in
pytest==6.0.2 # via -r requirements.in, pytest-black, pytest-cov, pytest-django, pytest-flake8
pytz==2020.1 # via babel, django
regex==2020.7.14 # via black
requests==2.24.0 # via sphinx
six==1.15.0 # via livereload, packaging, pip-tools, tox, virtualenv
snowballstemmer==2.0.0 # via sphinx
sphinx-autobuild==2020.9.1 # via -r requirements.in
sphinx==3.2.1 # via -r requirements.in, sphinx-autobuild
sphinxcontrib-applehelp==1.0.2 # via sphinx
sphinxcontrib-devhelp==1.0.2 # via sphinx
sphinxcontrib-htmlhelp==1.0.3 # via sphinx
sphinxcontrib-jsmath==1.0.1 # via sphinx
sphinxcontrib-qthelp==1.0.3 # via sphinx
sphinxcontrib-serializinghtml==1.1.4 # via sphinx
sqlparse==0.3.1 # via django
toml==0.10.1 # via black, pytest, pytest-black, tox
tornado==6.0.4 # via livereload
tox==3.20.0 # via -r requirements.in
typed-ast==1.4.1 # via black
typing-extensions==3.7.4.3 # via black
urllib3==1.25.10 # via requests
virtualenv==20.0.31 # via tox

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
Empty file added tests/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions tests/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ConversateConfig(AppConfig):
name = "conversate"
verbose_name = "Conversate"
106 changes: 106 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""
Django settings for testapp project.
Generated by 'django-admin startproject' using Django 2.2.15.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os


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


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "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",
"conversate",
]

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 = "tests.urls"

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",
"django.contrib.messages.context_processors.messages",
],
},
},
]


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

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


# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = os.path.join(BASE_DIR, "test_media")
MEDIA_URL = "/media/"
9 changes: 9 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from model_bakery import baker

from conversate.models import Message, Room


def test_message_render__emoji_markdown(admin_user):
room = baker.make(Room, users=[admin_user])
msg = Message.objects.create(room=room, user=admin_user, content=":thumbsup: *em*")
assert msg.render() == "<p>\U0001F44D <em>em</em></p>\n"
Loading

0 comments on commit e9fc3d2

Please sign in to comment.