# HG changeset patch # User cmlenz # Date 1122805349 0 # Node ID 88869d08ea2a5fbf0456d876153c4cb6a4451684 # Parent de5b6e69fc7e4d44278b32a0d6c8fc0031bf936d More unit tests for the model objects. diff --git a/bitten/tests/model.py b/bitten/tests/model.py --- a/bitten/tests/model.py +++ b/bitten/tests/model.py @@ -35,7 +35,7 @@ cursor.execute(stmt) db.commit() - def test_new_config(self): + def test_new(self): config = BuildConfig(self.env, name='test') assert not config.exists @@ -51,7 +51,19 @@ self.assertEqual('Test', config.label) self.assertEqual(False, config.active) - def test_insert_config(self): + def test_fetch_none(self): + config = BuildConfig.fetch(self.env, name='test') + self.assertEqual(None, config) + + def test_select_none(self): + configs = BuildConfig.select(self.env) + self.assertRaises(StopIteration, configs.next) + + def test_select_none(self): + configs = BuildConfig.select(self.env) + self.assertRaises(StopIteration, configs.next) + + def test_insert(self): config = BuildConfig(self.env, name='test', path='trunk', label='Test') config.insert() @@ -61,10 +73,58 @@ "FROM bitten_config") self.assertEqual(('test', 'trunk', 'Test', 0, ''), cursor.fetchone()) - def test_insert_config_no_name(self): + def test_insert_no_name(self): config = BuildConfig(self.env) self.assertRaises(AssertionError, config.insert) + def test_update(self): + db = self.env.get_db_cnx() + cursor = db.cursor() + cursor.execute("INSERT INTO bitten_config (name,path,label,active) " + "VALUES (%s,%s,%s,%s)", ('test', 'trunk', 'Test', 0)) + + config = BuildConfig.fetch(self.env, 'test') + config.path = 'some_branch' + config.label = 'Updated' + config.active = True + config.description = 'Bla bla bla' + config.update() + + db = self.env.get_db_cnx() + cursor = db.cursor() + cursor.execute("SELECT name,path,label,active,description " + "FROM bitten_config") + self.assertEqual(('test', 'some_branch', 'Updated', 1, 'Bla bla bla'), + cursor.fetchone()) + self.assertEqual(None, cursor.fetchone()) + + def test_config_update_name(self): + db = self.env.get_db_cnx() + cursor = db.cursor() + cursor.execute("INSERT INTO bitten_config (name,path,label,active) " + "VALUES (%s,%s,%s,%s)", ('test', 'trunk', 'Test', 0)) + + config = BuildConfig.fetch(self.env, 'test') + config.name = 'foobar' + config.update() + + db = self.env.get_db_cnx() + cursor = db.cursor() + cursor.execute("SELECT name,path,label,active,description " + "FROM bitten_config") + self.assertEqual(('foobar', 'trunk', 'Test', 0, ''), cursor.fetchone()) + self.assertEqual(None, cursor.fetchone()) + + def test_update_no_name(self): + db = self.env.get_db_cnx() + cursor = db.cursor() + cursor.execute("INSERT INTO bitten_config (name,path,label,active) " + "VALUES (%s,%s,%s,%s)", ('test', 'trunk', 'Test', 0)) + + config = BuildConfig.fetch(self.env, 'test') + config.name = None + self.assertRaises(AssertionError, config.update) + class TargetPlatformTestCase(unittest.TestCase):