Mercurial > hg > ltpdarepo
changeset 174:445540c83a43
Rename test case to more descriptive name.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Sun, 06 Nov 2011 23:29:49 +0100 |
parents | e2a9b0c3d83e |
children | d17d404d7f16 |
files | src/ltpdarepo/tests/test_schema.py src/ltpdarepo/tests/test_schema_upgrade.py |
diffstat | 2 files changed, 80 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/tests/test_schema.py Sun Nov 06 18:15:10 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -import unittest2 as unittest -import difflib -import sys -import os -import warnings - -from cStringIO import StringIO - -import MySQLdb as mysql - -from ltpdarepo.config import USERNAME, PASSWORD, HOSTNAME -from ltpdarepo.admin import wipe, install, createdb, useradd, grant, upgrade, dump - - -class TestCase(unittest.TestCase): - - def test_repository_schema(self): - warnings.simplefilter('ignore', category=mysql.Warning) - - wipe() - - # load dump obtained with `mysqldump --add-drop-database --skip-comments --databases mysql ltpda db1` - conn = mysql.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD, charset='utf8') - curs = conn.cursor() - pwd = os.path.dirname(__file__) - sql = open(os.path.join(pwd, '..', 'sql', 'dump-v2.4.sql')) - for stmt in [x.strip() for x in sql.read().split(';\n')]: - if stmt: - curs.execute(stmt) - conn.commit() - - # upgrade - upgrade() - - curs = conn.cursor() - - # no user accounts specified for host '127.0.0.1' - curs.execute("""SELECT Host FROM mysql.user WHERE User = 'u1'""") - hosts = sorted([row[0] for row in curs.fetchall()]) - self.assertEqual(hosts, ['localhost']) - curs.execute("""SELECT Host FROM mysql.user WHERE User = 'u2'""") - hosts = sorted([row[0] for row in curs.fetchall()]) - self.assertEqual(hosts, ['%', 'localhost']) - - # check privileges - curs.execute("""SELECT Db FROM mysql.db WHERE User = 'u2'""") - dbs = [row[0] for row in curs.fetchall()] - self.assertEqual(dbs, ['db1']) - - # no explicit privileges on transactions table - curs.execute("""SELECT Table_name FROM mysql.tables_priv WHERE User = 'u2'""") - tables = [row[0] for row in curs.fetchall()] - self.assertEqual(tables, []) - - # dump database structure - upgraded = StringIO() - dump('ltpda', out=upgraded) - dump('db1', out=upgraded) - upgraded.seek(0) - - # install - wipe() - install() - useradd('u1', password='u1', name='One', surname='User', email='u1@example.net') - grant('u1', '%', ['admin', ]) - createdb('db1', description=u'Test database one') - grant('u1', 'db1', ['select', 'insert', 'update', 'delete']) - - # dump database structure - new = StringIO() - dump('ltpda', out=new) - dump('db1', out=new) - new.seek(0) - - # compare - diff = difflib.unified_diff(upgraded.readlines(), new.readlines()) - for line in diff: - sys.stdout.write(line) - - self.assertTrue(upgraded.getvalue() == new.getvalue())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ltpdarepo/tests/test_schema_upgrade.py Sun Nov 06 23:29:49 2011 +0100 @@ -0,0 +1,80 @@ +import unittest2 as unittest +import difflib +import sys +import os +import warnings + +from cStringIO import StringIO + +import MySQLdb as mysql + +from ltpdarepo.config import USERNAME, PASSWORD, HOSTNAME +from ltpdarepo.admin import wipe, install, createdb, useradd, grant, upgrade, dump + + +class TestCase(unittest.TestCase): + + def setUp(self): + wipe() + + def tearDown(self): + wipe() + + def test_schema_upgrade(self): + warnings.simplefilter('ignore', category=mysql.Warning) + + # load dump obtained with `mysqldump --add-drop-database --skip-comments --databases mysql ltpda db1` + conn = mysql.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD, charset='utf8') + curs = conn.cursor() + pwd = os.path.dirname(__file__) + sql = open(os.path.join(pwd, '..', 'sql', 'dump-v2.4.sql')) + for stmt in [x.strip() for x in sql.read().split(';\n')]: + if stmt: + curs.execute(stmt) + conn.commit() + + # upgrade + upgrade() + + curs = conn.cursor() + + # no user accounts specified for host '127.0.0.1' + curs.execute("""SELECT Host FROM mysql.user WHERE User = 'u1'""") + hosts = sorted([row[0] for row in curs.fetchall()]) + self.assertEqual(hosts, ['localhost']) + curs.execute("""SELECT Host FROM mysql.user WHERE User = 'u2'""") + hosts = sorted([row[0] for row in curs.fetchall()]) + self.assertEqual(hosts, ['%', 'localhost']) + + # check privileges + curs.execute("""SELECT Db FROM mysql.db WHERE User = 'u2'""") + dbs = [row[0] for row in curs.fetchall()] + self.assertEqual(dbs, ['db1']) + + # no explicit privileges on transactions table + curs.execute("""SELECT Table_name FROM mysql.tables_priv WHERE User = 'u2'""") + tables = [row[0] for row in curs.fetchall()] + self.assertEqual(tables, []) + + # dump database structure + upgraded = StringIO() + dump('ltpda', out=upgraded) + dump('db1', out=upgraded) + upgraded.seek(0) + + # install + wipe() + install() + useradd('u1', password='u1', name='One', surname='User', email='u1@example.net') + grant('u1', '%', ['admin', ]) + createdb('db1', description=u'Test database one') + grant('u1', 'db1', ['select', 'insert', 'update', 'delete']) + + # dump database structure + new = StringIO() + dump('ltpda', out=new) + dump('db1', out=new) + new.seek(0) + + # compare + self.assertTrue(upgraded.getvalue() == new.getvalue())