Skip to content

Commit

Permalink
fixes sporadic postgres error
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Oct 5, 2013
1 parent a14138f commit 7c0d91a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 40 deletions.
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DJANGO_14=django==1.4.8
DJANGO_15=django==1.5.4
DJANGO_16=https://www.djangoproject.com/m/releases/1.6/Django-1.6b4.tar.gz
DJANGO_DEV=git+git://github.com/django/django.git
$DBENGINE=sqlite
DBENGINE=sqlite

mkbuilddir:
mkdir -p ${BUILDDIR}
Expand All @@ -30,10 +30,12 @@ test:


init-db:
@sh -c "if [ '${DBENGINE}' = 'mysql' ]; then mysql -e 'DROP DATABASE IF EXISTS test_concurrency;'; fi"
@sh -c "if [ '${DBENGINE}' = 'pg' ]; then psql -c 'DROP DATABASE IF EXISTS test_concurrency;' -U postgres; fi"

@sh -c "if [ '${DBENGINE}' = 'mysql' ]; then mysql -e 'DROP DATABASE IF EXISTS concurrency;'; fi"
@sh -c "if [ '${DBENGINE}' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS concurrency;'; fi"
@sh -c "if [ '${DBENGINE}' = 'mysql' ]; then pip install MySQL-python; fi"

@sh -c "if [ '${DBENGINE}' = 'pg' ]; then psql -c 'DROP DATABASE IF EXISTS concurrency;' -U postgres; fi"
@sh -c "if [ '${DBENGINE}' = 'pg' ]; then psql -c 'CREATE DATABASE concurrency;' -U postgres; fi"
@sh -c "if [ '${DBENGINE}' = 'pg' ]; then pip install -q psycopg2; fi"

ci:
Expand All @@ -45,10 +47,11 @@ ci:
@python -c "from __future__ import print_function;import django;print('Django version:', django.get_version())"
@echo "Database:" ${DBENGINE}

coverage run demo/manage.py test concurrency --settings=${DJANGO_SETTINGS_MODULE}
coverage report
coverage run demo/manage.py test concurrency --noinput --settings=${DJANGO_SETTINGS_MODULE} --failfast

cov-html: coverage mkbuilddir

coverage: mkbuilddir
coverage report
coverage html

clean:
Expand Down
28 changes: 16 additions & 12 deletions concurrency/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from django.test import TransactionTestCase
import django.core.management
from django.contrib.admin.options import ModelAdmin
from django.contrib.admin.sites import NotRegistered
import django.core.management
from django.contrib import admin
from django.conf import global_settings
from django.contrib.auth.models import User
from django.forms.models import modelform_factory
from django.test import TestCase
from django_webtest import WebTest

from django_webtest import WebTestMixin
from concurrency import forms
from concurrency.admin import ConcurrentModelAdmin
from concurrency.forms import ConcurrentForm, VersionWidget
Expand Down Expand Up @@ -76,7 +77,7 @@ def dummy_action(self, request, queryset):
el.save()


class AdminTestCase(WebTest):
class AdminTestCase(WebTestMixin, TransactionTestCase):
urls = 'concurrency.tests.urls'

def setUp(self):
Expand All @@ -95,22 +96,25 @@ def setUp(self):
admin_register(TestModel1, TestModel1Admin)
admin_register(TestModel0, ModelAdmin)

def tearDown(self):
super(AdminTestCase, self).tearDown()


class DjangoAdminTestCase(TestCase):
class DjangoAdminTestCase(TransactionTestCase):
urls = 'concurrency.tests.urls'
MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES
AUTHENTICATION_BACKENDS = global_settings.AUTHENTICATION_BACKENDS

def setUp(self):
super(DjangoAdminTestCase, self).setUp()
self.sett = self.settings(
#INSTALLED_APPS=INSTALLED_APPS,
MIDDLEWARE_CLASSES=self.MIDDLEWARE_CLASSES,
AUTHENTICATION_BACKENDS=self.AUTHENTICATION_BACKENDS,
PASSWORD_HASHERS=('django.contrib.auth.hashers.MD5PasswordHasher',), # fastest hasher
STATIC_URL='/static/',
SOUTH_TESTS_MIGRATE=False,
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),))
#INSTALLED_APPS=INSTALLED_APPS,
MIDDLEWARE_CLASSES=self.MIDDLEWARE_CLASSES,
AUTHENTICATION_BACKENDS=self.AUTHENTICATION_BACKENDS,
PASSWORD_HASHERS=('django.contrib.auth.hashers.MD5PasswordHasher',), # fastest hasher
STATIC_URL='/static/',
SOUTH_TESTS_MIGRATE=False,
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),))
self.sett.enable()
django.core.management._commands = None # reset commands cache
django.core.management.call_command('syncdb', verbosity=0)
Expand Down
1 change: 0 additions & 1 deletion concurrency/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_get_object_version(self):
o1 = TestModel0.objects.create()
self.assertEqual(get_object_with_version(TestModel0.objects, o1.pk, o1.version), o1)


def test_patched_get_version(self):
o1 = TestModel0.objects.create()
self.assertEqual(o1.get_concurrency_version(o1.version), o1)
Expand Down
2 changes: 0 additions & 2 deletions concurrency/tests/test_concurrencymetainfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_meta_inheritance(self):
assert concurrency_enabled1.pk is not None # sanity check
self.assertRaises(RecordModifiedError, concurrency_enabled2.save)


concurrency_disabled1 = ConcurrentModel.objects.get_or_create(**{'dummy_char': 'test'})[0]
concurrency_disabled2 = ConcurrentModel.objects.get_or_create(**{'dummy_char': 'test'})[0]
v1 = api.get_revision_of_object(concurrency_disabled1)
Expand All @@ -49,4 +48,3 @@ def test_meta_inheritance(self):
v1 = api.get_revision_of_object(concurrency_disabled1)
v2 = api.get_revision_of_object(concurrency_disabled2)
assert v1 != v2

10 changes: 0 additions & 10 deletions concurrency/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import warnings
from django.core.exceptions import SuspiciousOperation
from django.forms.models import modelform_factory
from django.forms.widgets import HiddenInput, TextInput
Expand Down Expand Up @@ -32,15 +31,6 @@ def test(self):


class FormFieldTest(SimpleTestCase):
def setUp(self):
if hasattr(self, 'save_warnings_state'):
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.core.validators')

def tearDown(self):
if hasattr(self, 'restore_warnings_state'):
self.restore_warnings_state()

def test_with_dummy_signer(self):
f = VersionField(signer=DummySigner())
Expand Down
2 changes: 0 additions & 2 deletions concurrency/tests/test_south.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ def test_south_can_introspect_autoincversionfield(self):
except ImportError:
class SouthTestCase(object):
pass


5 changes: 4 additions & 1 deletion demo/demoproject/settings_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
'HOST': '127.0.0.1',
'PORT': '',
'USER': 'postgres',
'PASSWORD': ''}}
'PASSWORD': '',
'OPTIONS': {
'autocommit': True, # same value for all versions of django (is the default in 1.6)
}}}
11 changes: 6 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[tox]
envlist =
d14,d15,d16,trunk,p3d15,p3d16
whitelist_externals = make
/bin/sh
/usr/bin/mysql
/usr/bin/psql
d14,d15,d16,trunk



[pytest]
Expand All @@ -23,6 +20,10 @@ python_files=concurrency/tests/*.py
pep8ignore = * ALL

[testenv]
whitelist_externals = make
/bin/sh
/usr/bin/mysql
/usr/bin/psql
changedir={toxinidir}
setenv =
PYTHONPATH = {toxinidir}/demo
Expand Down

0 comments on commit 7c0d91a

Please sign in to comment.