Changeset - c3461507a792
[Not reviewed]
0 2 0
Lance Edgar - 8 years ago 2016-05-23 14:27:35
ledgar@sacfoodcoop.com
Fix delete behavior for `ToSQLAlchemy` importer, fix tests

No need to expunge the object when deleting, and that was making tests
break in a way that suggested production breakage also..?
2 files changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rattail/importing/sqlalchemy.py
Show inline comments
 
@@ -124,13 +124,12 @@ class ToSQLAlchemy(Importer):
 
        """
 
        Delete the given object from the local system (or not), and return a
 
        boolean indicating whether deletion was successful.  Default logic will
 
        truly delete and expunge the local object from the session.
 
        """
 
        self.session.delete(obj)
 
        self.session.expunge(obj)
 
        return True
 

	
 
    def cache_model(self, model, **kwargs):
 
        """
 
        Convenience method which invokes :func:`rattail.db.cache.cache_model()`
 
        with the given model and keyword arguments.  It will provide the
rattail/tests/importing/test_sqlalchemy.py
Show inline comments
 
@@ -99,23 +99,25 @@ class TestToSQLAlchemy(TestCase):
 
        importer = self.make_importer(key='description', session=self.session)
 
        self.assertRaises(MultipleResultsFound, importer.get_single_local_object, ("Other Widget",))
 

	
 
    def test_create_object(self):
 
        importer = self.make_importer(key='id', session=self.session)
 
        widget = importer.create_object((42,), {'id': 42, 'description': "Latest Widget"})
 
        self.assertFalse(self.session.new or self.session.dirty or self.session.deleted) # i.e. has been flushed
 
        self.assertIn(widget, self.session) # therefore widget has been flushed and would be committed
 
        self.assertIn(widget, self.session)
 
        self.assertIn(widget, self.session.new)
 
        self.assertEqual(widget.id, 42)
 
        self.assertEqual(widget.description, "Latest Widget")
 

	
 
    def test_delete_object(self):
 
        widget = self.session.query(Widget).get(1)
 
        self.assertIn(widget, self.session)
 
        importer = self.make_importer(session=self.session)
 
        self.assertTrue(importer.delete_object(widget))
 
        self.assertNotIn(widget, self.session)
 
        self.assertIn(widget, self.session)
 
        self.assertIn(widget, self.session.deleted)
 
        self.session.flush()
 
        self.assertIsNone(self.session.query(Widget).get(1))
 

	
 
    def test_cache_model(self):
 
        importer = self.make_importer(key='id', session=self.session)
 
        cache = importer.cache_model(Widget, key='id')
 
        self.assertEqual(len(cache), 3)
0 comments (0 inline, 0 general)