Changeset - 98a062541871
[Not reviewed]
0 2 0
Lance Edgar (lance) - 11 years ago 2013-08-29 17:03:37
lance@edbob.org
Added some `CustomerEmailAddress` tests, removed some unused tests.
2 files changed with 51 insertions and 89 deletions:
0 comments (0 inline, 0 general)
tests/db/test_changes.py
Show inline comments
 
@@ -134,92 +134,3 @@ class TestChangeRecorder(TestCase):
 
        recorder.ensure_uuid(instance)
 
        get_uuid.assert_called_once_with()
 
        self.assertEqual(instance.uuid, 'fallback_uuid')
 

	
 
    #     # uuid fetched from foreign key object
 
    #     product = Product(uuid='latest_uuid')
 
    #     product_ext = ProductExtTest(product=product)
 
    #     self.assertIsNone(product_ext.uuid)
 
    #     get_uuid.reset_mock()
 
    #     changes.ensure_uuid(product_ext)
 
    #     self.assertFalse(get_uuid.called)
 
    #     self.assertEqual(product_ext.uuid, 'latest_uuid')
 

	
 
    # @patch('rattail.db.changes.get_uuid')
 
    # def test_ensure_uuid(self, get_uuid):
 

	
 
    #     # fallback scenario.  "extended product" is expected to be associated
 
    #     # with a product, but if it isn't, a UUID must still be generated
 
    #     product_ext = ProductExtTest()
 
    #     self.assertIsNone(product_ext.uuid)
 
    #     changes.ensure_uuid(product_ext)
 
    #     get_uuid.assert_called_once_with()
 
    #     self.assertEqual(product_ext.uuid, 'some_uuid')
 

	
 

	
 
# class ProductExtTest(Base):
 
#     __tablename__ = 'products_extended_test'
 
#     uuid = uuid_column(ForeignKey('products.uuid'), default=None)
 
#     some_attr = Column(String(length=10))
 
#     product = relationship(Product)
 

	
 

	
 
# class TestChanges(DataTestCase):
 

	
 
#     def setUp(self):
 
#         Base.metadata.tables['products_extended_test'].create(bind=engine)
 
#         super(TestChanges, self).setUp()
 

	
 
#     def tearDown(self):
 
#         super(TestChanges, self).tearDown()
 
#         Base.metadata.tables['products_extended_test'].drop(bind=engine)
 

	
 
#     @patch('rattail.db.changes.listen')
 
#     def test_record_changes(self, listen):
 
#         session = Mock()
 

	
 
#         changes.record_changes(session)
 

	
 
#         # # changes not being recorded yet
 
#         # self.session.add(Product())
 
#         # self.session.commit()
 
#         # self.assertEqual(self.session.query(Change).count(), 0)
 

	
 
#         # # okay, record them and confirm
 
#         # changes.record_changes(self.session)
 
#         # self.session.add(Product())
 
#         # self.session.commit()
 
#         # self.assertEqual(self.session.query(Change).count(), 1)
 

	
 
#     @patch('rattail.db.changes.get_uuid')
 
#     def test_ensure_uuid(self, get_uuid):
 

	
 
#         # uuid already present
 
#         product = Product(uuid='whatever')
 
#         changes.ensure_uuid(product)
 
#         self.assertEqual(product.uuid, 'whatever')
 
#         self.assertFalse(get_uuid.called)
 

	
 
#         # no uuid yet, auto-generate
 
#         get_uuid.return_value = 'some_uuid'
 
#         product = Product()
 
#         self.assertIsNone(product.uuid)
 
#         changes.ensure_uuid(product)
 
#         get_uuid.assert_called_once_with()
 
#         self.assertEqual(product.uuid, 'some_uuid')
 

	
 
#         # uuid fetched from foreign key object
 
#         product = Product(uuid='latest_uuid')
 
#         product_ext = ProductExtTest(product=product)
 
#         self.assertIsNone(product_ext.uuid)
 
#         get_uuid.reset_mock()
 
#         changes.ensure_uuid(product_ext)
 
#         self.assertFalse(get_uuid.called)
 
#         self.assertEqual(product_ext.uuid, 'latest_uuid')
 

	
 
#         # fallback scenario.  "extended product" is expected to be associated
 
#         # with a product, but if it isn't, a UUID must still be generated
 
#         product_ext = ProductExtTest()
 
#         self.assertIsNone(product_ext.uuid)
 
#         changes.ensure_uuid(product_ext)
 
#         get_uuid.assert_called_once_with()
 
#         self.assertEqual(product_ext.uuid, 'some_uuid')
tests/db/test_model.py
Show inline comments
 
@@ -7,6 +7,7 @@ from rattail.db.extension import model
 
from sqlalchemy import String, Boolean, Numeric
 
from rattail.db.types import GPCType
 
from sqlalchemy.exc import IntegrityError
 
from rattail.db import record_changes
 

	
 

	
 
class TestBatch(TestCase):
 
@@ -173,3 +174,53 @@ class TestCustomerGroupAssignment(DataTestCase):
 
        customer._groups.append(assignment)
 
        self.session.commit()
 
        self.assertEqual(assignment.ordinal, 2)
 

	
 

	
 
class TestCustomerEmailAddress(DataTestCase):
 

	
 
    def test_pop(self):
 
        customer = model.Customer()
 
        customer.add_email_address('fred.home@mailinator.com')
 
        customer.add_email_address('fred.work@mailinator.com')
 
        self.session.add(customer)
 
        self.session.commit()
 
        self.assertEqual(self.session.query(model.Customer).count(), 1)
 
        self.assertEqual(self.session.query(model.CustomerEmailAddress).count(), 2)
 

	
 
        while customer.emails:
 
            customer.emails.pop()
 
        self.session.commit()
 
        self.assertEqual(self.session.query(model.Customer).count(), 1)
 
        self.assertEqual(self.session.query(model.CustomerEmailAddress).count(), 0)
 

	
 
        # changes weren't being recorded
 
        self.assertEqual(self.session.query(model.Change).count(), 0)
 

	
 
    def test_pop_with_changes(self):
 
        record_changes(self.session)
 

	
 
        customer = model.Customer()
 
        customer.add_email_address('fred.home@mailinator.com')
 
        customer.add_email_address('fred.work@mailinator.com')
 
        self.session.add(customer)
 
        self.session.commit()
 
        self.assertEqual(self.session.query(model.Customer).count(), 1)
 
        self.assertEqual(self.session.query(model.CustomerEmailAddress).count(), 2)
 

	
 
        while customer.emails:
 
            customer.emails.pop()
 
        self.session.commit()
 
        self.assertEqual(self.session.query(model.Customer).count(), 1)
 
        self.assertEqual(self.session.query(model.CustomerEmailAddress).count(), 0)
 

	
 
        # changes should have been recorded
 
        changes = self.session.query(model.Change)
 
        self.assertEqual(changes.count(), 3)
 

	
 
        customer_change = changes.filter_by(class_name='Customer').one()
 
        self.assertEqual(customer_change.uuid, customer.uuid)
 
        self.assertFalse(customer_change.deleted)
 

	
 
        email_changes = changes.filter_by(class_name='CustomerEmailAddress')
 
        self.assertEqual(email_changes.count(), 2)
 
        self.assertEqual([x.deleted for x in email_changes], [False, False])
0 comments (0 inline, 0 general)