def test_remove_item(self, yesno): yesno.return_value = gtk.RESPONSE_OK list_slave = _ModelListSlave(store=self.store) item_to_remove = self.store.find(_TestModel, unicode_var=u'XXX').one() self.assertNotSensitive(list_slave.listcontainer, ['remove_button']) list_slave.listcontainer.list.select(item_to_remove) self.assertSensitive(list_slave.listcontainer, ['remove_button']) original_dm = list_slave.delete_model with mock.patch.object(list_slave, 'delete_model') as dm: dm.side_effect = original_dm self.click(list_slave.listcontainer.remove_button) args, kwargs = dm.call_args model, store = args self.assertTrue(isinstance(model, _TestModel)) self.assertEqual(self.store.fetch(model), item_to_remove) self.assertTrue(isinstance(store, StoqlibStore)) self.assertNotEqual(store, self.store) models = self.models - set([item_to_remove]) self.assertEqual(set(list_slave.listcontainer.list), models) self.assertEqual(set(list_slave.populate()), models) self.assertEqual(StoqlibStore.of(list_slave.populate()[0]), self.store)
def test_populate(self): list_slave = _ModelListSlave(store=self.store) # Make sure the list was populated right self.assertEqual(set(list_slave.listcontainer.list), self.models) # Make sure populate method is returning all models self.assertEqual(set(list_slave.populate()), self.models) self.assertEqual(StoqlibStore.of(list_slave.populate()[0]), self.store)
def test_rollback_nested_savepoints_with_new_objects(self): outside = WillBeCommitted(store=self.store, test_var=u'outside') self.store.savepoint('first_savepoint') inside = WillBeCommitted(store=self.store, test_var=u'inside_savepoint') self.store.savepoint('second_savepoint') inside_inside = WillBeCommitted(store=self.store, test_var=u'inside_inside_savepoint') # All objects are on the same store, but two of them are inside savepoints. self.assertEquals(StoqlibStore.of(outside), self.store) self.assertEquals(StoqlibStore.of(inside), self.store) self.assertEquals(StoqlibStore.of(inside_inside), self.store) # Now rollback to the second savepoint self.store.rollback_to_savepoint('second_savepoint') # The event inside_inside object should not be in the store self.assertIsNone(StoqlibStore.of(inside_inside)) # ... but the other two should still be. self.assertEquals(StoqlibStore.of(inside), self.store) self.assertEquals(StoqlibStore.of(outside), self.store) self.store.rollback_to_savepoint('first_savepoint') # The outer inside object should not be in the store self.assertIsNone(StoqlibStore.of(inside))
def test_rollback_double_savepoint_with_new_objects(self): outside = WillBeCommitted(store=self.store, test_var=u'outside') self.store.savepoint('first_savepoint') inside = WillBeCommitted(store=self.store, test_var=u'inside_savepoint') self.store.savepoint('second_savepoint') inside_inside = WillBeCommitted(store=self.store, test_var=u'inside_inside_savepoint') # All objects are on the same store, but tho of them are in savepoints self.assertEqual(StoqlibStore.of(outside), self.store) self.assertEqual(StoqlibStore.of(inside), self.store) self.assertEqual(StoqlibStore.of(inside_inside), self.store) # Now rollback to the first savepoint self.store.rollback_to_savepoint('first_savepoint') # ... the two inner objects should not be in the store. self.assertIsNone(StoqlibStore.of(inside)) self.assertIsNone(StoqlibStore.of(inside_inside)) # ... but the ouside one should still be in the store. self.assertEqual(StoqlibStore.of(outside), self.store) # It should not be possible to rollback to the second_savepoint, since that was # already done when we rolled back to the first with self.assertRaises(ValueError): self.store.rollback_to_savepoint('second_savepoint')
def test_rollback_nested_savepoints_with_new_objects(self): outside = WillBeCommitted(store=self.store, test_var=u'outside') self.store.savepoint('first_savepoint') inside = WillBeCommitted(store=self.store, test_var=u'inside_savepoint') self.store.savepoint('second_savepoint') inside_inside = WillBeCommitted(store=self.store, test_var=u'inside_inside_savepoint') # All objects are on the same store, but two of them are inside savepoints. self.assertEqual(StoqlibStore.of(outside), self.store) self.assertEqual(StoqlibStore.of(inside), self.store) self.assertEqual(StoqlibStore.of(inside_inside), self.store) # Now rollback to the second savepoint self.store.rollback_to_savepoint('second_savepoint') # The event inside_inside object should not be in the store self.assertIsNone(StoqlibStore.of(inside_inside)) # ... but the other two should still be. self.assertEqual(StoqlibStore.of(inside), self.store) self.assertEqual(StoqlibStore.of(outside), self.store) self.store.rollback_to_savepoint('first_savepoint') # The outer inside object should not be in the store self.assertIsNone(StoqlibStore.of(inside))