Merge lp:~elachuni/django-pgtools/fix-long-seqs-and-dbcheck into lp:django-pgtools

Proposed by Anthony Lenton
Status: Merged
Approved by: Danny Tamez
Approved revision: 7
Merged at revision: 5
Proposed branch: lp:~elachuni/django-pgtools/fix-long-seqs-and-dbcheck
Merge into: lp:django-pgtools
Diff against target: 121 lines (+64/-6)
4 files modified
debian/changelog (+7/-1)
pgtools/management/commands/grantuser.py (+3/-1)
pgtools/tests.py (+44/-3)
pgtools/utils.py (+10/-1)
To merge this branch: bzr merge lp:~elachuni/django-pgtools/fix-long-seqs-and-dbcheck
Reviewer Review Type Date Requested Status
Danny Tamez (community) Approve
Review via email: mp+101954@code.launchpad.net

Commit message

Support 1.3 style db config; long sequences are handled correctly

Description of the change

This branch includes two fixes:
 - utils.check_database_engine now supports 1.3-style DATABASE settings
 - long sequences (with names over 64 chars long) are handled correctly, via pg_get_serial_sequence

To post a comment you must log in.
Revision history for this message
Danny Tamez (zematynnad) wrote :

OK, I gave up on the tests but the 2 fixes look fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2011-06-02 14:54:18 +0000
+++ debian/changelog 2012-04-13 18:16:24 +0000
@@ -1,8 +1,14 @@
1django-pgtools (0.1-2) lucid; urgency=low
2
3 * Fixed long sequences and DB engine check.
4
5 -- Anthony Lenton <anthony.lenton@canonical.com> Fri, 13 Apr 2012 15:12:15 -0300
6
1django-pgtools (0.1-1) lucid; urgency=low7django-pgtools (0.1-1) lucid; urgency=low
28
3 * Fixed packaging issue (no commands were included in the package)9 * Fixed packaging issue (no commands were included in the package)
410
5 -- Łukasz Czyżykowski <lukasz.czyzykowski@canonical.com> jue, 02 jun 2011 15:54:06 +010011 -- Łukasz Czyżykowski <lukasz.czyzykowski@canonical.com> Thu, 02 jun 2011 15:54:06 +0100
612
7django-pgtools (0.1) lucid; urgency=low13django-pgtools (0.1) lucid; urgency=low
814
915
=== modified file 'pgtools/management/commands/grantuser.py'
--- pgtools/management/commands/grantuser.py 2011-05-30 14:30:10 +0000
+++ pgtools/management/commands/grantuser.py 2012-04-13 18:16:24 +0000
@@ -53,7 +53,9 @@
5353
54 def _grant_many_to_many(self, field):54 def _grant_many_to_many(self, field):
55 table = field.m2m_db_table()55 table = field.m2m_db_table()
56 sequence = "%s_id_seq" % table56 self.cursor.execute("select pg_get_serial_sequence('%s', 'id')" %
57 table)
58 sequence = self.cursor.fetchone()[0]
57 self._grant_one(table)59 self._grant_one(table)
58 self._grant_one(sequence)60 self._grant_one(sequence)
5961
6062
=== modified file 'pgtools/tests.py'
--- pgtools/tests.py 2011-05-30 14:30:10 +0000
+++ pgtools/tests.py 2012-04-13 18:16:24 +0000
@@ -441,13 +441,37 @@
441 self.assertEqual(str(err),441 self.assertEqual(str(err),
442 "User cannot be deleted: %s" % TEST_USER_NAME1)442 "User cannot be deleted: %s" % TEST_USER_NAME1)
443443
444 def test_utils_check_database_engine(self):444 def test_utils_check_database_engine_11_style(self):
445 # Test default: 'postgresql_psycopg2' (hopefully)445 # Test default: 'postgresql_psycopg2' (hopefully)
446 check_database_engine()446 settings_to_patch = {}
447 if hasattr(settings, 'DATABASES'):
448 settings_to_patch['DATABASES'] = None
449 for engine in [
450 'postgresql_psycopg2',
451 'django.db.backends.postgresql_psycopg2']:
452 settings_to_patch['DATABASE_ENGINE'] = engine
453 with patch_settings(**settings_to_patch):
454 check_database_engine()
455
447 # Test an unsupported engine456 # Test an unsupported engine
448 with patch_settings(DATABASE_ENGINE='sqlite3'):457 settings_to_patch['DATABASE_ENGINE'] = 'sqlite3'
458 with patch_settings(**settings_to_patch):
449 self.assertRaises(CommandError, check_database_engine)459 self.assertRaises(CommandError, check_database_engine)
450460
461 @patch('pgtools.utils.settings')
462 def test_utils_check_database_engine_13_style(self, mock_settings):
463 dbconfig = {'default': {'NAME': 'mydatabase'}}
464 mock_settings.DATABASES = dbconfig
465 for engine in ['postgresql_psycopg2',
466 'django.db.backends.postgresql_psycopg2']:
467 dbconfig['default']['ENGINE'] = engine
468 mock_settings.DATABASE_ENGINE = 'sqlite3'
469 check_database_engine()
470 # Test an unsupported engine
471 dbconfig['default']['ENGINE'] = 'sqlite3'
472 mock_settings.DATABASE_ENGINE = 'postgresql_psycopg2'
473 self.assertRaises(CommandError, check_database_engine)
474
451 def test_utils_get_rolename_from_settings(self):475 def test_utils_get_rolename_from_settings(self):
452 # Test with default (nothing set)476 # Test with default (nothing set)
453 self.assertRaises(CommandError, get_rolename_from_settings)477 self.assertRaises(CommandError, get_rolename_from_settings)
@@ -517,3 +541,20 @@
517 # sequences541 # sequences
518 self.assertEqual(mock_grant_one.call_args_list[1],542 self.assertEqual(mock_grant_one.call_args_list[1],
519 (('django_admin_log_id_seq',), {}))543 (('django_admin_log_id_seq',), {}))
544
545 @patch('pgtools.management.commands.grantuser.get_models')
546 @patch('pgtools.management.commands.grantuser.connection')
547 def test__grant_many_to_many(self, mock_connection, mock_get_models):
548 mock_connection.cursor.return_value.fetchone.return_value = ['foo']
549 from django.contrib.auth import models as auth_models
550 mock_get_models.return_value = get_models(auth_models)
551
552 call_command('grantuser', 'payments')
553
554 args_list = mock_connection.cursor.return_value.execute.call_args_list
555 calls = [x[0][0] for x in args_list]
556 for expected in [
557 "select pg_get_serial_sequence('auth_user_groups', 'id')",
558 'GRANT ALL ON foo TO payments;'
559 ]:
560 self.assertTrue(expected in calls)
520561
=== modified file 'pgtools/utils.py'
--- pgtools/utils.py 2011-05-30 14:30:10 +0000
+++ pgtools/utils.py 2012-04-13 18:16:24 +0000
@@ -7,7 +7,16 @@
77
88
9def check_database_engine():9def check_database_engine():
10 if settings.DATABASE_ENGINE != 'postgresql_psycopg2':10 all_psql = True
11 if getattr(settings, 'DATABASES', None):
12 # Django 1.2+ style
13 for db in settings.DATABASES.values():
14 if not db['ENGINE'].endswith('postgresql_psycopg2'):
15 all_psql = False
16 else:
17 # Django -1.1 style
18 all_psql = settings.DATABASE_ENGINE.endswith('postgresql_psycopg2')
19 if not all_psql:
11 raise CommandError(20 raise CommandError(
12 'Only the postgresql_psycopg2 database engine is supported.')21 'Only the postgresql_psycopg2 database engine is supported.')
1322

Subscribers

People subscribed via source and target branches