Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way we name triggers #69

Merged
merged 5 commits into from
Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/django_aggtrigg_demo/dummy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Tree(models.Model):
class Leave(models.Model):
name = models.CharField(max_length=300)
tree = ForeignKeyTriggerField(Tree)
private = models.BooleanField()
private = models.BooleanField(default=False)
tree.aggregate_trigger = [
{"count": [
{"private_leaves": [{"field": "private", "value": True}]},
Expand Down
2 changes: 2 additions & 0 deletions demo/django_aggtrigg_demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
}
}

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

try:
from settings_local import * # noqa
except ImportError:
Expand Down
7 changes: 7 additions & 0 deletions demo/django_aggtrigg_demo/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ def test_commands(self):
call_command('aggtrigg_check', verbosity=0)
call_command('aggtrigg_drop', verbosity=0)

out = StringIO()
call_command('aggtrigg_check', stdout=out)
for report in out.getvalue().split("\n"):
self.assertFalse(
report.startswith("KO")
)


class Utils(object):

Expand Down
9 changes: 2 additions & 7 deletions django_aggtrigg/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,15 @@ def function_name(table, column, action, key=None):


def trigger_name(table, column, function, action):

function = function.split("_")[-2][:-2]

tname = "{0}_{1}_{2}_{3}_trigger".format(table, column, function, action)
tname = "{0}_trigger".format(function[:-2])
return tname


def triggers_name(table, column, functions):
tgs = []

for function, action in functions.iteritems():
function = function.split("_")[-1][:-2]
tgs.append("{0}_{1}_{2}_{3}_trigger".format(table, column,
function, action))
tgs.append("{0}_trigger".format(function[:-2]))
return tgs


Expand Down
4 changes: 2 additions & 2 deletions django_aggtrigg/util_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_function_name(self):
util.function_name('foo', 'colfoo', 'insert'))

def test_trigger_name(self):
self.assertEqual("foo_id__insert_trigger",
self.assertEqual("foo_id_insert_trigger",
util.trigger_name('foo', 'id',
'foo_id_insert()', 'insert'))

Expand All @@ -57,7 +57,7 @@ def test_sql_create_triggers(self):

tgnames = [tgn[0] for tgn in res]
sqls = [tgn[1] for tgn in res]
self.assertIn("foota_foocol_fooc_insert_trigger", tgnames)
self.assertIn("foota_foocol_insert_trigger", tgnames)
self.assertEqual(sqls[0][:6], "CREATE")

# def test_sql_create_function(self):
Expand Down