Skip to content

Commit

Permalink
updates travis config
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Apr 5, 2015
1 parent 366694a commit 5f6ebd9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 10 deletions.
5 changes: 3 additions & 2 deletions concurrency/db/backends/mysql/base.py
@@ -1,3 +1,4 @@
import _mysql_exceptions
from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper
from concurrency.db.backends.common import TriggerMixin
from concurrency.db.backends.mysql.creation import MySQLCreation
Expand All @@ -13,8 +14,8 @@ def _clone(self):

def list_triggers(self):
cursor = self.cursor()
cursor.execute("SHOW TRIGGERS LIKE 'concurrency_%%';")
return [m[0] for m in cursor.fetchall()]
cursor.execute("SHOW TRIGGERS")
return sorted([m[0] for m in cursor.fetchall()])

def drop_trigger(self, trigger_name):
cursor = self.cursor()
Expand Down
9 changes: 7 additions & 2 deletions concurrency/db/backends/mysql/creation.py
Expand Up @@ -15,13 +15,16 @@ class MySQLCreation(DatabaseCreation):
CREATE TRIGGER {trigger_name}_u BEFORE UPDATE ON {opts.db_table}
FOR EACH ROW SET NEW.{field.column} = OLD.{field.column}+1;
"""
def __init__(self, connection):
super(MySQLCreation, self).__init__(connection)
self._triggers = {}

def _create_trigger(self, field):
import MySQLdb as Database
# import MySQLdb as Database
from warnings import filterwarnings, resetwarnings

filterwarnings('ignore', message='Trigger does not exist',
category=Database.Warning)
category=Warning)

opts = field.model._meta
trigger_name = get_trigger_name(field, opts)
Expand All @@ -31,6 +34,8 @@ def _create_trigger(self, field):
cursor = self.connection._clone().cursor()
try:
cursor.execute(stm)
self._triggers[field] = trigger_name

except (BaseException, _mysql_exceptions.ProgrammingError) as exc:
errno, message = exc.args
if errno != 2014:
Expand Down
2 changes: 1 addition & 1 deletion concurrency/db/backends/postgresql_psycopg2/base.py
Expand Up @@ -18,7 +18,7 @@ def list_triggers(self):
stm = "select * from pg_trigger where tgname LIKE 'concurrency_%%'; "
logger.debug(stm)
cursor.execute(stm)
return [m[1] for m in cursor.fetchall()]
return sorted([m[1] for m in cursor.fetchall()])

def drop_trigger(self, trigger_name):
if trigger_name not in self.list_triggers():
Expand Down
2 changes: 1 addition & 1 deletion concurrency/db/backends/sqlite3/base.py
Expand Up @@ -12,7 +12,7 @@ def __init__(self, *args, **kwargs):
def list_triggers(self):
cursor = self.cursor()
result = cursor.execute("select name from sqlite_master where type='trigger';")
return [m[0] for m in result.fetchall()]
return sorted([m[0] for m in result.fetchall()])

def drop_trigger(self, trigger_name):
cursor = self.cursor()
Expand Down
4 changes: 4 additions & 0 deletions concurrency/db/backends/sqlite3/creation.py
Expand Up @@ -18,6 +18,9 @@ class Sqlite3Creation(DatabaseCreation):
BEGIN UPDATE {opts.db_table} SET {field.column} = 0 WHERE {opts.pk.column} = NEW.{opts.pk.column};
END; ##
"""
def __init__(self, connection):
super(Sqlite3Creation, self).__init__(connection)
self._triggers = {}

def _create_trigger(self, field):
from django.db.utils import DatabaseError
Expand All @@ -33,6 +36,7 @@ def _create_trigger(self, field):
field=field)
try:
cursor.execute(stm)
self._triggers[field] = trigger_name
except BaseException as exc:
raise DatabaseError(exc)

Expand Down
15 changes: 15 additions & 0 deletions manage.py
@@ -0,0 +1,15 @@
#!/usr/bin/env python
import os, sys
here = os.path.abspath(os.path.join(os.path.dirname(__file__)))
rel = lambda *args: os.path.join(here, *args)

sys.path.insert(0, rel(os.pardir))


if __name__ == "__main__":
sys.path.insert(0, 'tests')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
1 change: 1 addition & 0 deletions requirements/tests.pip
Expand Up @@ -4,6 +4,7 @@ mock>=1.0.1
pytest>=2.7
pytest-pythonpath
pytest-cache>=1.0
pytest-ordering
pytest-echo>=1.3
pytest-cov>=1.6
pytest-django>=2.8
Expand Down
2 changes: 1 addition & 1 deletion tests/test_command.py
Expand Up @@ -39,5 +39,5 @@ def test_command_list():
call_command('triggers', 'list', stdout=out)
out.seek(0)
output = out.read()
assert output.find('concurrency_demo_triggerconcurrentmodel_u')
assert output.find('concurrency_demo_triggerconcurrentmodel_i')
assert output.find('concurrency_demo_triggerconcurrentmodel_u')
6 changes: 3 additions & 3 deletions tests/test_triggers.py
Expand Up @@ -9,10 +9,10 @@
@pytest.mark.django_db
def test_list_triggers():
conn = connections['default']
assert conn.list_triggers() == [u'concurrency_demo_triggerconcurrentmodel_u',
u'concurrency_demo_triggerconcurrentmodel_i']

assert conn.list_triggers() == [u'concurrency_demo_triggerconcurrentmodel_i',
u'concurrency_demo_triggerconcurrentmodel_u']

@pytest.mark.last
@pytest.mark.django_db
def test_drop_triggers():
conn = connections['default']
Expand Down

0 comments on commit 5f6ebd9

Please sign in to comment.