From ff49d5cba24aa57ed36538425beb3973a5302315 Mon Sep 17 00:00:00 2001 From: Scot Hacker Date: Thu, 29 Mar 2018 23:05:49 -0700 Subject: [PATCH] Just enough infrastructure to get tests to pass as standalone app --- .travis.yml | 30 +++- Pipfile | 24 +++ Pipfile.lock | 171 ++++++++++++++++++++++ base_urls.py | 15 ++ pytest.ini | 4 + test_settings.py | 64 ++++++++ todo/migrations/0006_rename_item_model.py | 2 +- todo/templates/base.html | 1 + todo/tests/conftest.py | 1 + 9 files changed, 307 insertions(+), 5 deletions(-) create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 base_urls.py create mode 100644 pytest.ini create mode 100644 test_settings.py create mode 100644 todo/templates/base.html diff --git a/.travis.yml b/.travis.yml index 0e6a36b..f5a25f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,27 @@ -language: python +sudo: true + +before_install: + - sudo apt-get update -qq + - sudo apt-get install -qq build-essential gettext python-dev zlib1g-dev libpq-dev xvfb libjpeg8-dev + - sudo apt-get install -qq python-setuptools python3-dev python-virtualenv python-pip + +addons: + postgresql: "9.6" + install: - - pip install virtualenv -script: - - python setup.py test + - "pip3 install -e . --upgrade" + - "pip3 install git+https://github.com/pypa/pipenv.git" + - "pipenv install --dev" + +language: python +python: + - "3.6" + +# Attempt to use cached versions of python deps +cache: pip + +cache: + directories: + - $HOME/.cache/pip + +script: pipenv run pytest -x -v diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..215d884 --- /dev/null +++ b/Pipfile @@ -0,0 +1,24 @@ +[[source]] + +url = "https://pypi.python.org/simple" +verify_ssl = true +name = "pypi" + + +[packages] + +django = "*" +django-extensions = "*" +"psycopg2-binary" = "*" +pytest = "*" +pytest-django = "*" +"flake8" = "*" + + +[dev-packages] + + + +[requires] + +python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..4a380a7 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,171 @@ +{ + "_meta": { + "hash": { + "sha256": "5a7237884b6690e23782690ae05e2d2ffd38a04d142f9fccc926860494073e9b" + }, + "host-environment-markers": { + "implementation_name": "cpython", + "implementation_version": "3.6.3", + "os_name": "posix", + "platform_machine": "x86_64", + "platform_python_implementation": "CPython", + "platform_release": "17.4.0", + "platform_system": "Darwin", + "platform_version": "Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64", + "python_full_version": "3.6.3", + "python_version": "3.6", + "sys_platform": "darwin" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.6" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.python.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "attrs": { + "hashes": [ + "sha256:a17a9573a6f475c99b551c0e0a812707ddda1ec9653bed04c13841404ed6f450", + "sha256:1c7960ccfd6a005cd9f7ba884e6316b5e430a3f1a6c37c5f87d8b43f83b54ec9" + ], + "version": "==17.4.0" + }, + "django": { + "hashes": [ + "sha256:3d9916515599f757043c690ae2b5ea28666afa09779636351da505396cbb2f19", + "sha256:769f212ffd5762f72c764fa648fca3b7f7dd4ec27407198b68e7c4abf4609fd0" + ], + "version": "==2.0.3" + }, + "django-extensions": { + "hashes": [ + "sha256:37a543af370ee3b0721ff50442d33c357dd083e6ea06c5b94a199283b6f9e361", + "sha256:bc9f2946c117bb2f49e5e0633eba783787790ae810ea112fe7fd82fa64de2ff1" + ], + "version": "==2.0.6" + }, + "flake8": { + "hashes": [ + "sha256:c7841163e2b576d435799169b78703ad6ac1bbb0f199994fc05f700b2a90ea37", + "sha256:7253265f7abd8b313e3892944044a365e3f4ac3fcdcfb4298f55ee9ddf188ba0" + ], + "version": "==3.5.0" + }, + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + ], + "version": "==0.6.1" + }, + "more-itertools": { + "hashes": [ + "sha256:11a625025954c20145b37ff6309cd54e39ca94f72f6bb9576d1195db6fa2442e", + "sha256:0dd8f72eeab0d2c3bd489025bb2f6a1b8342f9b198f6fc37b52d15cfa4531fea", + "sha256:c9ce7eccdcb901a2c75d326ea134e0886abfbea5f93e91cc95de9507c0816c44" + ], + "version": "==4.1.0" + }, + "pluggy": { + "hashes": [ + "sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff" + ], + "version": "==0.6.0" + }, + "psycopg2-binary": { + "hashes": [ + "sha256:b287ddf4cafcfb632974907d1e7862119e36bb758228bdb07dd247553e4cdfc0", + "sha256:d1dd3eb8edd354083f5d27b968c5a17854c41347ba5a480b520be85ec1a8495c", + "sha256:cf3911fba0c47fc1313b5783183cda301032b14637a0b7a336766ae46998c7ee", + "sha256:b039f51bca1ddd70234cc3f84f94f42ad43861b931bdfb497f887c60c39a6565", + "sha256:83af04029bcb4b56c852e5876fef71340dcb465fa44fc99f80bac72e10fb0b74", + "sha256:3a14baeabcebd4662f12f4bff03e0574a2369a2e41baf829e6fb4a24c95cf88b", + "sha256:cb07184a4bfad304831f0a88b1c13fbd8cf9fcdf1f11e71c477dd6d7b1b078a0", + "sha256:d0972f062c73956332e9681dfdb133168618f0abfecc96e89f0205ac89cd454b", + "sha256:ab1db8f3e96570d9f7ebc45133ce2574804b2280499baade178e163d022107b5", + "sha256:d51c7ed810fce1e50464088c37cc8da05534de8afb12a732500827ebcc480081", + "sha256:b6b2b26590304d97ef2af28d153ee99ace6fe0806934f4618edfc87216c77f91", + "sha256:9b5ddbed85ec73293695d7116589d956ef0dd3fcf7bf3b2a3bc1e8e54c1d543a", + "sha256:02eb674e3d5810e19b4d5d00720b17130e182da1ba259dda608aaf33d787347d", + "sha256:436a503eda41f6adb08f292f40a3784fce0a5f351b6ae7b19a911904db53af93", + "sha256:8014c06a9ed7b78ba81beff3ae71acd78c212390f8ed839e9ce22735880bd5b4", + "sha256:c4c6004d410c77bfa5389ae9485498ce32805447a67afbfe8db0d247a5c88fa1", + "sha256:d8940b5104588d6313315e037f0f5ed68d2e5f62ccc1c429d3cff11d2ba6de3f", + "sha256:c606bff0978ee4858d86d40f6b6ab0c4cac4474f627bd054683dc03a4fc1a366", + "sha256:9305d7cbc802aaefac5c75a3df725f2654797369f32b18d4d0adb382dfab6c09", + "sha256:4a1a5ea2fa4b53191637b162873a82822d92a85a08beefe28296b8eb5cf2fea5", + "sha256:a3d2cc0cb0b988dbfd0d11f7fac34058b25a6ce533ed5b8e88d6cb315e77d54a", + "sha256:86c0d2587f56776f25d52cca8e275adf495c8e01933fbfc2ca23b124610ab761", + "sha256:77a2fc622a1f2d08a707673c9be5769d521f03d867d305f172bb417fa7882754", + "sha256:4a4f23a08fbccbe40ecdb5384d807bcb469ea71dd87e6be2e80b036b8e6d47df", + "sha256:c8220c521a408b41c4f14036004a621ed0d965941286b978cd2ea2623fabd755", + "sha256:465ff1d427ed42c31e456dbbd9edab3552be18a0edaef7450c5b3e6fee745052", + "sha256:de4f88f823037a71ea5ef3c1041d96b8a68d73343133edda684fd42f575bd9d7" + ], + "version": "==2.7.4" + }, + "py": { + "hashes": [ + "sha256:983f77f3331356039fdd792e9220b7b8ee1aa6bd2b25f567a963ff1de5a64f6a", + "sha256:29c9fab495d7528e80ba1e343b958684f4ace687327e6f789a94bf3d1915f881" + ], + "version": "==1.5.3" + }, + "pycodestyle": { + "hashes": [ + "sha256:6c4245ade1edfad79c3446fadfc96b0de2759662dc29d07d80a6f27ad1ca6ba9", + "sha256:682256a5b318149ca0d2a9185d365d8864a768a28db66a84a2ea946bcc426766" + ], + "version": "==2.3.1" + }, + "pyflakes": { + "hashes": [ + "sha256:08bd6a50edf8cffa9fa09a463063c425ecaaf10d1eb0335a7e8b1401aef89e6f", + "sha256:8d616a382f243dbf19b54743f280b80198be0bca3a5396f1d2e1fca6223e8805" + ], + "version": "==1.6.0" + }, + "pytest": { + "hashes": [ + "sha256:6266f87ab64692112e5477eba395cfedda53b1933ccd29478e671e73b420c19c", + "sha256:fae491d1874f199537fd5872b5e1f0e74a009b979df9d53d1553fd03da1703e1" + ], + "version": "==3.5.0" + }, + "pytest-django": { + "hashes": [ + "sha256:00995c2999b884a38ae9cd30a8c00ed32b3d38c1041250ea84caf18085589662", + "sha256:038ccc5a9daa1b1b0eb739ab7dce54e495811eca5ea3af4815a2a3ac45152309" + ], + "version": "==3.1.2" + }, + "pytz": { + "hashes": [ + "sha256:ed6509d9af298b7995d69a440e2822288f2eca1681b8cce37673dbb10091e5fe", + "sha256:f93ddcdd6342f94cea379c73cddb5724e0d6d0a1c91c9bdef364dc0368ba4fda", + "sha256:61242a9abc626379574a166dc0e96a66cd7c3b27fc10868003fa210be4bff1c9", + "sha256:ba18e6a243b3625513d85239b3e49055a2f0318466e0b8a92b8fb8ca7ccdf55f", + "sha256:07edfc3d4d2705a20a6e99d97f0c4b61c800b8232dc1c04d87e8554f130148dd", + "sha256:3a47ff71597f821cd84a162e71593004286e5be07a340fd462f0d33a760782b5", + "sha256:5bd55c744e6feaa4d599a6cbd8228b4f8f9ba96de2c38d56f08e534b3c9edf0d", + "sha256:887ab5e5b32e4d0c86efddd3d055c1f363cbaa583beb8da5e22d2fa2f64d51ef", + "sha256:410bcd1d6409026fbaa65d9ed33bf6dd8b1e94a499e32168acfc7b332e4095c0" + ], + "version": "==2018.3" + }, + "six": { + "hashes": [ + "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb", + "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9" + ], + "version": "==1.11.0" + } + }, + "develop": {} +} diff --git a/base_urls.py b/base_urls.py new file mode 100644 index 0000000..24c9f32 --- /dev/null +++ b/base_urls.py @@ -0,0 +1,15 @@ +from django.urls import include, path + +""" +This urlconf exists so we can run tests without an actual Django project +(Django expects ROOT_URLCONF to exist.) This helps the tests remain isolated. +For your project, ignore this file and add + +`path('lists/', include('todo.urls')),` + +to your site's urlconf. +""" + +urlpatterns = [ + path('lists/', include('todo.urls')), +] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..401389d --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +DJANGO_SETTINGS_MODULE = test_settings +# -- recommended but optional: +python_files = tests.py test_*.py *_tests.py \ No newline at end of file diff --git a/test_settings.py b/test_settings.py new file mode 100644 index 0000000..e1daff6 --- /dev/null +++ b/test_settings.py @@ -0,0 +1,64 @@ +import os + +DEBUG = True, +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +print("bd ", BASE_DIR) +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + } +} + +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + +# Document +TODO_STAFF_ONLY = False +TODO_DEFAULT_LIST_ID = None +TODO_DEFAULT_ASSIGNEE = None +TODO_PUBLIC_SUBMIT_REDIRECT = '/' + +SECRET_KEY = "LKFSD8sdl.,8&sdf--" + +SITE_ID = 1 + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.messages', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.staticfiles', + 'todo', +) + +ROOT_URLCONF = 'base_urls' + +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', +] + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'todo', 'templates'), ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.template.context_processors.media', + 'django.template.context_processors.static', + 'django.contrib.messages.context_processors.messages', + # Your stuff: custom template context processors go here + ], + }, + }, +] \ No newline at end of file diff --git a/todo/migrations/0006_rename_item_model.py b/todo/migrations/0006_rename_item_model.py index 3147460..cd9830d 100644 --- a/todo/migrations/0006_rename_item_model.py +++ b/todo/migrations/0006_rename_item_model.py @@ -5,7 +5,7 @@ from django.db import migrations class Migration(migrations.Migration): - + atomic = False dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('todo', '0005_auto_20180212_2325'), diff --git a/todo/templates/base.html b/todo/templates/base.html new file mode 100644 index 0000000..079d860 --- /dev/null +++ b/todo/templates/base.html @@ -0,0 +1 @@ +This file not actually used by django-todo - here to satisfy the test runner. \ No newline at end of file diff --git a/todo/tests/conftest.py b/todo/tests/conftest.py index e76698d..a2514f4 100644 --- a/todo/tests/conftest.py +++ b/todo/tests/conftest.py @@ -5,6 +5,7 @@ from django.contrib.auth.models import Group from todo.models import Task, TaskList + @pytest.fixture def todo_setup(django_user_model): # Two groups with different users, two sets of tasks.