Commit 3aca0bf8 authored by luxcem's avatar luxcem
Browse files

Fresh start for rp

parents
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify
from userprofile.apps import UserprofileConfig
from userprofile.models import Profile
from userprofile.factories import ProfileFactory
def test_init():
assert UserprofileConfig.name == "userprofile"
def test_profile():
profile = ProfileFactory()
assert type(profile.user) == User
assert type(profile) == Profile
assert type(profile.full_name) == str
assert profile.slug == slugify(profile.user.username)
assert type(profile.identity) == str
assert str(profile) == profile.full_name
profile.delete()
from django.shortcuts import render
# Create your views here.
import os
import pytest
import django
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
@pytest.fixture(autouse=True)
def enable_db_access_for_all_tests(db):
"""Adds access to db to all tests"""
def pytest_configure():
settings.DEBUG = False
django.setup()
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
"""
Import settings from all files in settings directory
"""
from .env import * # noqa
from .base import * # noqa
from .apps import * # noqa
from .auth import * # noqa
from .api import * # noqa
from .static import * # noqa
from .i18n import * # noqa
"""
django-rest-framework and api related settings
"""
REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": ("rest_framework.pagination."
"PageNumberPagination"),
"PAGE_SIZE": 20,
}
"""
Django installed apps
"""
from .env import DEBUG
DJANGO_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.contenttypes",
]
CONTRIB_APPS = [
"django_extensions", # http://django-extensions.readthedocs.io/
"rest_framework", # http://www.django-rest-framework.org/
# https://github.com/philipn/django-rest-framework-filters
# "rest_framework_filters",
]
if DEBUG:
CONTRIB_APPS.append(
'debug_toolbar', # https://django-debug-toolbar.readthedocs.io/
)
PROJECT_APPS = [
"userprofile",
"core"
]
INSTALLED_APPS = DJANGO_APPS + CONTRIB_APPS + PROJECT_APPS
"""
User registration and login related settings
"""
AUTH_USER_MODEL = "auth.User"
EXTENDED_USER_MODEL = "userprofile.Profile"
LOGIN_URL = "login"
AUTHENTICATION_BACKENDS = [
# Default
"django.contrib.auth.backends.ModelBackend",
# Email or Username for login
"core.auth_backends.EmailOrUsernameModelBackend",
]
# Password validation
# https://docs.djangoproject.com/en/1.10/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"),
},
]
"""
Django settings for rp_new project.
"""
import os
import sys
from .env import DEBUG
BASE_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
# Adds apps to path
APPS_DIR = os.path.realpath(os.path.join(BASE_DIR, "apps"))
sys.path.append(APPS_DIR)
ALLOWED_HOSTS = []
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",
]
if DEBUG:
MIDDLEWARE.append(
"debug_toolbar.middleware.DebugToolbarMiddleware"
)
ROOT_URLCONF = "project.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",
],
"builtins": [
# Provide {% static %}
"django.contrib.staticfiles.templatetags.staticfiles",
# Provide {% trans %}
"django.templatetags.i18n",
# Provide {% permission %}
"permission.templatetags.permissionif"
]
},
},
]
WSGI_APPLICATION = "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"),
}
}
"""
Internationalization and localization settings
See https://docs.djangoproject.com/en/1.10/topics/i18n/ for refs
"""
import os
from .base import BASE_DIR
# TODO : use en in backend and user lc in frontend
LANGUAGE_CODE = "en-US"
# TODO : use UTC in backend and use user tz in frontend
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Adds languages here
LANGUAGES = (
("en", "English"),
("fr", "French"),
)
LOCALE_PATHS = [os.path.join(BASE_DIR, "locale")]
"""
Static files related settings
See https://docs.djangoproject.com/en/1.10/howto/static-files/ for refs
"""
import os
from .base import BASE_DIR
# Url to get static files
STATIC_URL = "/static/"
# Directory of static files (used by collectstatic)
STATIC_ROOT = os.path.join(BASE_DIR, "static", "static_root")
# Additionaly to apps/static dirs, files in staticfiles_dirs will be copied
# by collectstatic
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static", "build"),
)
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "static", "media")
"""
rp_new URL Configuration
"""
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r"^admin/", admin.site.urls),
]
"""
WSGI config for rp_new project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
[pytest]
DJANGO_SETTINGS_MODULE = project.settings
python_files = tests.py test_*.py *_tests.py
\ No newline at end of file
django-debug-toolbar
tox
pytest
pytest-cov
pytest-django
# Fixture
factory-boy
django-factory-boy
# Code style
jedi
importmagic
autopep8
flake8
pep8
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment