class FlashMsgTests(unittest.TestCase): def setup(self): self.harness = TestHarness("FlashMsgTests.sqlite") self.db = self.harness.db return Flash() def teardown(self): self.db.disconnect() self.harness.clean() def test_can_create_instance(self): a = Assert() i = self.setup() a.not_null(i, "Unable to create instance") self.teardown() def test_can_add_fail(self): a = Assert() i = self.setup() i.fail("That was dumb") a.true(i.any(), "Didn't create a message") value = i.get() a.equals(value.level, FlashTypes.FAILURE, "Added flash message didn't have the right type") a.false(i.any(), "Didn't remove a message") self.teardown() def test_can_add_notice(self): a = Assert() i = self.setup() i.notice("That was a notice") a.true(i.any(), "Didn't create a message") value = i.get() a.equals(value.level, FlashTypes.NOTICE, "Added flash message didn't have the right type") a.false(i.any(), "Didn't remove a message") self.teardown() def test_can_add_success(self): a = Assert() i = self.setup() i.success("That was successful!") a.true(i.any(), "Didn't create a message") value = i.get() a.equals(value.level, FlashTypes.SUCCESS, "Added flash message didn't have the right type") a.false(i.any(), "Didn't remove a message") self.teardown()
class PrefTests(unittest.TestCase): def setup(self): self.harness = TestHarness("PrefTests.sqlite") self.db = self.harness.db return Prefs() def teardown(self): self.db.disconnect() self.harness.clean() def test_can_create_instance(self): a = Assert() i = self.setup() a.not_null(i, "Unable to create instance") self.teardown() def test_can_insert(self): a = Assert() i = self.setup() i.add("Key", "Value") self.teardown() def test_can_get_by_name(self): a = Assert() i = self.setup() i.add("Key", "Value") record = i.get("Key") a.equals(record.value, "Value", "Failed to query db") self.teardown() def test_can_delete_record(self): a = Assert() i = self.setup() i.add("Key", "Value") found = i.has("Key") a.true(found, "Failed to found record") i.delete("Key") found = i.has("Key") a.false(found, "Found missing record") self.teardown() def test_can_update_record(self): a = Assert() i = self.setup() i.add("Key1", "Value") i.add("Key1", "Value2") i.add("Key1", "Value3") p = i.get("Key1") a.equals(p.value, "Value3", "Update didn't work") i.delete("Key1") found = i.has("Key1") a.false(found, "Multiple insert did not do an update") self.teardown()