Example #1
0
 def test_turn_off_syncing_all_handlers_true(
         self, post_bulk_operation_mock, m2m_changed_mock, post_delete_mock, post_save_mock):
     turn_off_syncing(for_post_save=True, for_post_delete=True, for_m2m_changed=True, for_post_bulk_operation=True)
     self.assertTrue(post_save_mock.disconnect.called)
     self.assertTrue(post_delete_mock.disconnect.called)
     self.assertTrue(m2m_changed_mock.disconnect.called)
     self.assertTrue(post_bulk_operation_mock.disconnect.called)
Example #2
0
 def tearDown(self):
     """
     Make sure syncing is turned back to its original state.
     """
     super(EntityTestCase, self).tearDown()
     turn_off_syncing()
     turn_on_syncing()
Example #3
0
 def setUp(self):
     """
     Ensure entity syncing is in default state when tests start.
     """
     super(EntityTestCase, self).setUp()
     turn_off_syncing()
     turn_on_syncing()
Example #4
0
 def test_turn_off_bulk(self):
     """
     Tests turning off syncing for bulk operations.
     """
     turn_off_syncing()
     with patch('entity.models.sync_entities') as mock_handler:
         Account.objects.bulk_create([Account() for i in range(5)])
         self.assertFalse(mock_handler.called)
Example #5
0
 def test_turn_off_save(self):
     """
     Tests turning off syncing for the save signal.
     """
     turn_off_syncing()
     with patch('entity.models.sync_entities') as mock_handler:
         Account.objects.create()
         self.assertFalse(mock_handler.called)
Example #6
0
    def test_sync_two_accounts_one_team_group(self):
        turn_off_syncing()
        team = G(Team)
        account1 = G(Account, team=team)
        account2 = G(Account, team=team)
        team_group = G(TeamGroup)
        sync_entities(account1, account2, team_group)

        self.assertEquals(Entity.objects.count(), 4)
        self.assertEquals(EntityRelationship.objects.count(), 2)
Example #7
0
 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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    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)