def test_turn_on_syncing_all_handlers_true( self, post_bulk_operation_mock, m2m_changed_mock, post_delete_mock, post_save_mock): turn_on_syncing(for_post_save=True, for_post_delete=True, for_m2m_changed=True, for_post_bulk_operation=True) self.assertTrue(post_save_mock.connect.called) self.assertTrue(post_delete_mock.connect.called) self.assertTrue(m2m_changed_mock.connect.called) self.assertTrue(post_bulk_operation_mock.connect.called)
def tearDown(self): """ Make sure syncing is turned back to its original state. """ super(EntityTestCase, self).tearDown() turn_off_syncing() turn_on_syncing()
def setUp(self): """ Ensure entity syncing is in default state when tests start. """ super(EntityTestCase, self).setUp() turn_off_syncing() turn_on_syncing()
def test_turn_on_bulk(self): """ Tests turning on syncing for bulk operations. """ turn_off_syncing() turn_on_syncing(for_post_bulk_operation=True) with patch('entity.models.sync_entities') as mock_handler: Account.objects.bulk_create([Account() for i in range(5)]) self.assertTrue(mock_handler.called)
def test_turn_on_save(self): """ Tests turning on syncing for the save signal. """ turn_off_syncing() turn_on_syncing() with patch('entity.models.sync_entities') as mock_handler: Account.objects.create() self.assertTrue(mock_handler.called)
def test_turn_on_delete(self): """ Tests turning on syncing for the delete signal. """ turn_off_syncing() turn_on_syncing() with patch('entity.models.Entity.objects.delete_for_obj') as mock_handler: a = Account.objects.create() a.delete() self.assertEquals(mock_handler.call_count, 1)
def test_save_model_with_m2m(self): """ Verifies that the m2m test entity is synced properly upon save. """ turn_off_syncing() m = G(M2mEntity) m.teams.add(G(Team)) turn_on_syncing() m.save() self.assertEquals(Entity.objects.count(), 2) self.assertEquals(EntityRelationship.objects.count(), 1)
def test_cascade_sync_super_entities(self): """ Tests that super entities will be synced when a sub entity is synced (even if the super entities werent synced before) """ turn_off_syncing() team = G(Team) turn_on_syncing() self.assertFalse(Entity.objects.exists()) G(Account, team=team) self.assertEquals(Entity.objects.count(), 2) self.assertEquals(EntityRelationship.objects.count(), 1)
def test_async_sync_entities_management_command(self): """ Tests that the sync_entities command works with the asynchronous option. """ # Create five test accounts without syncing on turn_off_syncing() for i in range(5): Account.objects.create() turn_on_syncing() # Test that the management command syncs all five entities self.assertEquals(Entity.objects.all().count(), 0) call_command('sync_entities', async=True) self.assertEquals(Entity.objects.all().count(), 5)
def test_sync_entities_management_command(self): """ Tests that the management command for syncing entities works properly. """ # Create five test accounts turn_off_syncing() for i in range(5): Account.objects.create() turn_on_syncing() # Test that the management command syncs all five entities self.assertEquals(Entity.objects.all().count(), 0) call_command('sync_entities') self.assertEquals(Entity.objects.all().count(), 5)
def test_sync_all_account_no_teams(self): """ Tests syncing all accounts with no super entities. """ turn_off_syncing() # Create five test accounts accounts = [Account.objects.create() for i in range(5)] turn_on_syncing() # Sync all of the entities and verify that five Entity models were created for the Account model self.assertEquals(Entity.objects.all().count(), 0) sync_entities() self.assertEquals(Entity.objects.all().count(), 5) # Delete an account. When all entities are synced again, # there should only be four accounts turn_off_syncing() accounts[0].delete() turn_on_syncing() self.assertEquals(Entity.objects.all().count(), 5) sync_entities() self.assertEquals(Entity.objects.all().count(), 4)
def setUp(self): super(TestEntityBulkSignalSync, self).setUp() turn_on_syncing(for_post_bulk_operation=True)