'Tests apps.lazy_model_operation().'

@isolate_apps('apps', kwarg_name='apps')
def test_lazy_model_operation(self, apps):

    model_classes = []
    initial_pending = set(apps._pending_operations)
    def test_func(*models):
        model_classes[:] = models
    class LazyA(models.Model, ):
        pass
    model_keys = [('apps', model_name) for model_name in ['lazya', 'lazyb', 'lazyb', 'lazyc', 'lazya']]
    apps.lazy_model_operation(test_func, *model_keys)
    self.assertEqual((set(apps._pending_operations) - initial_pending), {('apps', 'lazyb')})
    apps.lazy_model_operation(test_func, ('apps', 'lazyb'))
    class LazyB(models.Model, ):
        pass
    self.assertEqual(model_classes, [LazyB])
    self.assertEqual((set(apps._pending_operations) - initial_pending), {('apps', 'lazyc')})
    class LazyC(models.Model, ):
        pass
    self.assertEqual(model_classes, [LazyA, LazyB, LazyB, LazyC, LazyA])
