Skip to content

Commit bdc554f

Browse files
authored
Merge pull request #82 from thenewguy/vagrant-demo
configured vagrant guest to run interactive demo
2 parents 7c2e5c2 + 7434600 commit bdc554f

File tree

11 files changed

+201
-17
lines changed

11 files changed

+201
-17
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,6 @@ Now you can run tests as shown below:
212212
```sh
213213
python runtests.py
214214
```
215+
216+
Alternately, you can skip local configuration and use the provided vagrant environment for testing.
217+
[Reference its README for further details.](vagrant/README)

manage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from __future__ import unicode_literals, absolute_import
4+
5+
import os
6+
import sys
7+
8+
if __name__ == "__main__":
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wagtailmedia.tests.settings")
10+
from django.core.management import execute_from_command_line
11+
12+
execute_from_command_line(sys.argv)

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
# For coverage and PEP8 linting
1919
'coverage>=3.7.0',
2020
'flake8>=2.2.0',
21+
'isort',
2122

2223
# Required for matrix build on Travis
2324
'tox==3.9.0',
25+
26+
# Required for interactive testing via tox
27+
'psycopg2-binary',
28+
'django-redis-cache',
2429
]
2530

2631
with io.open('README.md', encoding='utf-8') as readme_file:

tox.ini

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
[tox]
2+
requires = tox-docker
23
skipsdist = True
4+
toxworkdir = /home/vagrant/.tox
35
usedevelop = True
46

5-
envlist = py{35,36,37}-dj{20,21,22}-wag{22,23,24,25,26,27},
7+
envlist =
8+
py{35,36,37}-dj{20,21,22}-wag{22,23,24,25,26,27}
9+
interactive
10+
flake
11+
isort
12+
613

714
[testenv]
815
install_command = pip install -e ".[testing]" -U {opts} {packages}
16+
917
commands =
1018
{posargs:python runtests.py}
1119

1220
basepython =
1321
py35: python3.5
1422
py36: python3.6
1523
py37: python3.7
24+
{interactive,flake,isort}: python3.6
1625

1726
deps =
1827
dj111: Django>=1.11.20,<2.0
@@ -25,3 +34,50 @@ deps =
2534
wag25: wagtail>=2.5,<2.6
2635
wag26: wagtail>=2.6,<2.7
2736
wag27: wagtail>=2.7,<2.8
37+
{interactive,flake,isort}: wagtail
38+
39+
40+
[testenv:flake]
41+
commands = {posargs:flake8 wagtailmedia}
42+
43+
44+
[testenv:isort]
45+
commands = {posargs:isort --check-only --diff --recursive wagtailmedia}
46+
47+
48+
[testenv:interactive]
49+
commands_pre =
50+
python {toxinidir}/manage.py makemigrations
51+
python {toxinidir}/manage.py migrate
52+
python {toxinidir}/manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_superuser('super', '[email protected]', 'super')"
53+
54+
commands =
55+
{posargs:python manage.py runserver 0.0.0.0:8020}
56+
57+
docker =
58+
postgres:12.0
59+
redis:5.0
60+
61+
dockerenv =
62+
POSTGRES_PASSWORD=pgpass
63+
POSTGRES_USER=pguser
64+
POSTGRES_DB=pgdb
65+
66+
setenv =
67+
INTERACTIVE = 1
68+
69+
70+
[docker:redis:5.0]
71+
healthcheck_cmd = redis-cli ping | grep -q PONG
72+
healthcheck_interval = 3
73+
healthcheck_timeout = 3
74+
healthcheck_retries = 30
75+
healthcheck_start_period = 5
76+
77+
78+
[docker:postgres:12.0]
79+
healthcheck_cmd = pg_isready
80+
healthcheck_interval = 3
81+
healthcheck_timeout = 3
82+
healthcheck_retries = 30
83+
healthcheck_start_period = 5

vagrant/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vagrant/

vagrant/README

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
CREATES A VAGRANT ENVIRONMENT TO FACILITATE LOCAL TESTING
2+
3+
** VAGRANT MUST BE INSTALLED FOR THIS TO WORK! **
4+
IF YOU ARE NOT FAMILIAR WITH VAGRANT, [FOLLOW THE INSTALLATION INSTRUCTIONS BEFORE CONTINUING](https://www.vagrantup.com/docs/installation/).
5+
6+
========
7+
USAGE:
8+
========
9+
To run tests:
10+
cd to this directory on the host machine and issue the following commands:
11+
vagrant up
12+
vagrant ssh
13+
14+
then:
15+
bash /vagrant/vagrant/runtox.sh -e py35-dj20-wag22
16+
17+
To run interactive demo inside the vagrant guest:
18+
** note: you might need to manually pull the docker images in tox.ini manually on the first run! it hangs for me occasionally **
19+
docker pull redis:5.0
20+
docker pull postgres:12.0
21+
22+
bash /vagrant/vagrant/runtox.sh -e interactive
23+
24+
then:
25+
open your browser on the host and navigate to http://localhost:8020/admin/
26+
27+
log in credentials:
28+
username: super
29+
password: super
30+
31+
To run flake8 inside the vagrant guest:
32+
bash /vagrant/vagrant/runtox.sh -e flake
33+
34+
To run isort inside the vagrant guest:
35+
bash /vagrant/vagrant/runtox.sh -e isort

vagrant/Vagrantfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.box = "hashicorp/bionic64"
3+
4+
config.vm.provider "virtualbox" do |v|
5+
v.name = "wagtailmedia"
6+
end
7+
8+
config.vm.network "forwarded_port", guest: 8020, host: 8020
9+
config.vm.provision :shell, path: "provision.sh"
10+
config.vm.synced_folder ".", "/vagrant", disabled: true
11+
config.vm.synced_folder "../", "/vagrant"
12+
end

vagrant/provision.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set -o errexit
2+
set -o pipefail
3+
set -o nounset
4+
shopt -s failglob
5+
set -o xtrace
6+
7+
export DEBIAN_FRONTEND=noninteractive
8+
9+
add-apt-repository -y ppa:deadsnakes/ppa
10+
apt-get update
11+
apt-get install -y python3-distutils build-essential libssl-dev python-dev python3.5 python3.5-dev python3.6 python3.6-dev python3.7 python3.7-dev
12+
13+
curl -sSL https://get.docker.com/ | sh
14+
adduser vagrant docker
15+
16+
curl https://bootstrap.pypa.io/get-pip.py | python3
17+
pip3 install tox tox-docker

vagrant/runtox.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tox -c /vagrant/tox.ini -vv "$@"
2+
3+
docker stop $(docker ps -q)
4+
docker system prune --force --volumes

wagtailmedia/tests/settings.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
import os
22

3+
DEBUG = 'INTERACTIVE' in os.environ
4+
35
WAGTAILMEDIA_ROOT = os.path.dirname(__file__)
46
STATIC_ROOT = os.path.join(WAGTAILMEDIA_ROOT, 'test-static')
57
MEDIA_ROOT = os.path.join(WAGTAILMEDIA_ROOT, 'test-media')
68
MEDIA_URL = '/media/'
79

8-
DATABASES = {
9-
'default': {
10-
'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
11-
'NAME': os.environ.get('DATABASE_NAME', 'wagtailmedia'),
12-
'USER': os.environ.get('DATABASE_USER', None),
13-
'PASSWORD': os.environ.get('DATABASE_PASS', None),
14-
'HOST': os.environ.get('DATABASE_HOST', None),
15-
16-
'TEST': {
17-
'NAME': os.environ.get('DATABASE_NAME', None),
10+
POSTGRES_PORT = os.getenv('POSTGRES_5432_TCP_PORT', '')
11+
if POSTGRES_PORT:
12+
DATABASES = {
13+
'default': {
14+
'ENGINE': 'django.db.backends.postgresql',
15+
'NAME': 'pgdb',
16+
'USER': 'pguser',
17+
'PASSWORD': 'pgpass',
18+
'HOST': 'localhost',
19+
'PORT': POSTGRES_PORT,
20+
}
21+
}
22+
else:
23+
DATABASES = {
24+
'default': {
25+
'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
26+
'NAME': os.environ.get('DATABASE_NAME', 'wagtailmedia'),
27+
'USER': os.environ.get('DATABASE_USER', None),
28+
'PASSWORD': os.environ.get('DATABASE_PASS', None),
29+
'HOST': os.environ.get('DATABASE_HOST', None),
30+
31+
'TEST': {
32+
'NAME': os.environ.get('DATABASE_NAME', None),
33+
}
1834
}
1935
}
20-
}
2136

2237

2338
SECRET_KEY = 'not needed'
@@ -89,12 +104,23 @@
89104
# Using DatabaseCache to make sure THAT the cache is cleared between tests.
90105
# This prevents false-positives in some wagtail core tests where we are
91106
# changing the 'wagtail_root_paths' key which may cause future tests to fail.
92-
CACHES = {
93-
'default': {
94-
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
95-
'LOCATION': 'cache',
107+
108+
REDIS_PORT = os.getenv('REDIS_6379_TCP_PORT', '')
109+
110+
if REDIS_PORT:
111+
CACHES = {
112+
"default": {
113+
'BACKEND': 'redis_cache.RedisCache',
114+
'LOCATION': 'localhost:%s' % REDIS_PORT,
115+
},
116+
}
117+
else:
118+
CACHES = {
119+
'default': {
120+
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
121+
'LOCATION': 'cache',
122+
}
96123
}
97-
}
98124

99125
PASSWORD_HASHERS = (
100126
'django.contrib.auth.hashers.MD5PasswordHasher', # don't use the intentionally slow default password hasher
@@ -107,5 +133,8 @@
107133
}
108134
}
109135

136+
# must be set for interactive demo, copied per
137+
# https://github.com/django/django/commit/adb96617897690b3a01e39e8297ae7d67825d2bc
138+
ALLOWED_HOSTS = ['.localhost', '127.0.0.1', '[::1]']
110139

111140
WAGTAIL_SITE_NAME = "Test Site"

0 commit comments

Comments
 (0)