Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Fix broken tests and run tests in a Docker container on Travis CI.
Browse files Browse the repository at this point in the history
* Add `docker-compose.travis.yml` and `icekit/bin/runtests.sh`.

* Assume database name has been set correctly already in test settings
  module.

* Install missing `fluent_pages.pagetypes.fluentpage` app, which is
  needed by tests.

* Ensure `polymorphic_auth` is near the top of `INSTALLED_APPS` because
  it monkey patches Django's `get_user_model()` and some other Django
  auth code had already imported it before the monkey patch was applied.

* Use `G()` from DDF to create test users to avoid unique constraint
  violations.

* Update reversed URLs for renamed app labels.

* Make authenticated requests when testing admin pages, to avoid errors
  on 302 status code instead of expected 200 status code.

* Add a database dump to bypass migrations and speed up tests.
  • Loading branch information
mrmachine committed Aug 24, 2016
1 parent 87262a7 commit 0e5381a
Show file tree
Hide file tree
Showing 7 changed files with 8,405 additions and 29 deletions.
21 changes: 21 additions & 0 deletions docker-compose.travis.yml
@@ -0,0 +1,21 @@
django:
command: runtests.sh
environment:
BASE_SETTINGS_MODULE: docker
PGHOST: postgres
PGUSER: postgres
TRAVIS:
image: interaction/icekit:latest
links:
- elasticsearch
- postgres
- redis
volumes:
- ./:/opt/django-icekit
elasticsearch:
image: interaction/elasticsearch-icu:1
postgres:
image: onjin/alpine-postgres:9.4
redis:
command: redis-server --appendonly yes
image: redis:3-alpine
17 changes: 17 additions & 0 deletions icekit/bin/runtests.sh
@@ -0,0 +1,17 @@
#!/bin/bash

# Run tests.

cat <<EOF
# `whoami`@`hostname`:$PWD$ runtests.sh $@
EOF

set -e

export BASE_SETTINGS_MODULE=test
export PGDATABASE="${PGDATABASE:-test_icekit}"
export REUSE_DB=1
export FORCE_SETUP_POSTGRES_DATABASE=1
export SRC_PGDATABASE=test_icekit.sql

exec entrypoint.sh bash -c "manage.py collectstatic --noinput --verbosity=0 && manage.py compress --verbosity=0 && manage.py test --noinput --verbosity=2 $@"
10 changes: 5 additions & 5 deletions icekit/project/settings/_test.py
Expand Up @@ -2,18 +2,18 @@

# DJANGO ######################################################################

DATABASE_NAME = 'test_%s' % DATABASES['default']['NAME']

DATABASES['default'].update({
'NAME': DATABASE_NAME,
'TEST': {
'NAME': DATABASE_NAME,
'NAME': DATABASES['default']['NAME'],
# See: https://docs.djangoproject.com/en/1.7/ref/settings/#serialize
'SERIALIZE': False,
},
})

INSTALLED_APPS += ('icekit.tests', )
INSTALLED_APPS += (
'fluent_pages.pagetypes.fluentpage',
'icekit.tests',
)

ROOT_URLCONF = 'icekit.tests.urls'

Expand Down
1 change: 1 addition & 0 deletions icekit/project/settings/calculated.py
Expand Up @@ -45,6 +45,7 @@
'icekit',
'icekit.dashboard',
'icekit.integration.reversion',
'polymorphic_auth',

# Then 3rd party apps.
'fluent_suit',
Expand Down
38 changes: 19 additions & 19 deletions icekit/publishing/tests.py
Expand Up @@ -58,8 +58,8 @@ def setUp(self):
title='Test title',
layout=self.page_layout_1,
)
self.staff_1 = User.objects.create(
username='staff_1',
self.staff_1 = G(
User,
is_staff=True,
is_active=True,
is_superuser=True,
Expand Down Expand Up @@ -566,22 +566,22 @@ def setUp(self):

self.response = Mock()

self.staff_1 = User.objects.create(
username='staff_1',
self.staff_1 = G(
User,
is_staff=True,
is_active=True,
is_superuser=True,
)

self.public_user = User.objects.create(
username='public_user',
self.public_user = G(
User,
is_active=True,
is_staff=False,
is_superuser=False,
)

self.reviewer_user = User.objects.create(
username='reviewer',
self.reviewer_user = G(
User,
is_active=True,
is_staff=False,
is_superuser=False,
Expand Down Expand Up @@ -838,8 +838,8 @@ class TestPublishingAdmin(BaseAdminTest):
"""

def setUp(self):
self.staff_1 = User.objects.create(
username='staff_1',
self.staff_1 = G(
User,
is_staff=True,
is_active=True,
is_superuser=True,
Expand All @@ -856,15 +856,15 @@ def test_publish_slideshow(self):

# Check admin change page includes publish links, not unpublish ones
response = self.app.get(
reverse('admin:slideshow_slideshow_change',
reverse('admin:icekit_plugins_slideshow_slideshow_change',
args=(self.slide_show_1.pk, )),
user=self.staff_1)
self.assertEqual(response.status_code, 200)
self.assertTrue(
reverse('admin:slideshow_slideshow_publish',
reverse('admin:icekit_plugins_slideshow_slideshow_publish',
args=(self.slide_show_1.pk, )) in response.text)
self.assertFalse(
reverse('admin:slideshow_slideshow_unpublish',
reverse('admin:icekit_plugins_slideshow_slideshow_unpublish',
args=(self.slide_show_1.pk, )) in response.text)

# Publish via admin
Expand All @@ -876,15 +876,15 @@ def test_publish_slideshow(self):

# Check admin change page includes unpublish link (published item)
response = self.app.get(
reverse('admin:slideshow_slideshow_change',
reverse('admin:icekit_plugins_slideshow_slideshow_change',
args=(self.slide_show_1.pk, )),
user=self.staff_1)
self.assertEqual(response.status_code, 200)
self.assertFalse(
reverse('admin:slideshow_slideshow_publish',
reverse('admin:icekit_plugins_slideshow_slideshow_publish',
args=(self.slide_show_1.pk, )) in response.text)
self.assertTrue(
reverse('admin:slideshow_slideshow_unpublish',
reverse('admin:icekit_plugins_slideshow_slideshow_unpublish',
args=(self.slide_show_1.pk, )) in response.text)

# Publish again
Expand All @@ -903,15 +903,15 @@ def test_publish_slideshow(self):

# Check admin change page includes publish links, not unpublish ones
response = self.app.get(
reverse('admin:slideshow_slideshow_change',
reverse('admin:icekit_plugins_slideshow_slideshow_change',
args=(self.slide_show_1.pk, )),
user=self.staff_1)
self.assertEqual(response.status_code, 200)
self.assertTrue(
reverse('admin:slideshow_slideshow_publish',
reverse('admin:icekit_plugins_slideshow_slideshow_publish',
args=(self.slide_show_1.pk, )) in response.text)
self.assertFalse(
reverse('admin:slideshow_slideshow_unpublish',
reverse('admin:icekit_plugins_slideshow_slideshow_unpublish',
args=(self.slide_show_1.pk, )) in response.text)


Expand Down
20 changes: 15 additions & 5 deletions icekit/tests/tests.py
Expand Up @@ -470,15 +470,25 @@ def test_admin_pages(self):
('fluent_pages_page', self.layoutpage_1),
)
for admin_app, obj in admin_app_list:
response = self.app.get(reverse('admin:%s_changelist' % admin_app))
response = self.app.get(
reverse('admin:%s_changelist' % admin_app),
user=self.super_user_1)
self.assertEqual(response.status_code, 200)
response = self.app.get(reverse('admin:%s_add' % admin_app))
response = self.app.get(
reverse('admin:%s_add' % admin_app),
user=self.super_user_1)
self.assertEqual(response.status_code, 200)
response = self.app.get(reverse('admin:%s_history' % admin_app, args=(obj.id, )))
response = self.app.get(
reverse('admin:%s_history' % admin_app, args=(obj.id, )),
user=self.super_user_1)
self.assertEqual(response.status_code, 200)
response = self.app.get(reverse('admin:%s_delete' % admin_app, args=(obj.id, )))
response = self.app.get(
reverse('admin:%s_delete' % admin_app, args=(obj.id, )),
user=self.super_user_1)
self.assertEqual(response.status_code, 200)
response = self.app.get(reverse('admin:%s_change' % admin_app, args=(obj.id, )))
response = self.app.get(
reverse('admin:%s_change' % admin_app, args=(obj.id, )),
user=self.super_user_1)
self.assertEqual(response.status_code, 200)

def test_response_pages(self):
Expand Down

0 comments on commit 0e5381a

Please sign in to comment.