def test_subclassing(self):
     model_class = MutableModelSubclass.for_tenant(self.tenant)
     self.assertEqual(
         get_remote_field_model(model_class._meta.get_field('non_mutable_fk')),
         self.tenant.specificmodels.model
     )
     specific_model = self.tenant.specificmodels.create()
     mutable = model_class.objects.create(
         field=True, non_mutable_fk=specific_model
     )
     # Make sure the reverse descriptor is accessible before mutation
     self.assertEqual(specific_model.mutables.get(), mutable)
     # Add a field to the parent class
     NullBooleanFieldDefinition.objects.create(
         model_def=MutableModel.for_tenant(self.tenant).definition(),
         name='is_cool',
     )
     # Make sure the reverse descriptor is accessible after mutation
     self.assertEqual(specific_model.mutables.get(), mutable)
     self.assertEqual(
         1,
         model_class.objects.filter(
             field=True, is_cool=None, non_mutable_fk=specific_model
         ).count()
     )
Beispiel #2
0
 def test_valid_nontenant_parent_inlineformset(self):
     formset = tenant_inlineformset_factory(self.tenant, NonTenantInlineFormSet)
     tenant_specific_model = SpecificModel.for_tenant(self.tenant)
     self.assertEqual(formset.model, tenant_specific_model)
     self.assertEqual(get_remote_field_model(formset.fk), NonTenantModel)
     self.assertTrue(issubclass(formset, NonTenantInlineFormSet))
     form = formset.form
     self.assertTrue(issubclass(form, SpecificModelForm))
     self.assertEqual(tenant_specific_model, form._meta.model)
 def test_subclassing(self):
     model_class = MutableModelSubclass.for_tenant(self.tenant)
     self.assertEqual(
         get_remote_field_model(
             model_class._meta.get_field('non_mutable_fk')),
         self.tenant.specificmodels.model)
     specific_model = self.tenant.specificmodels.create()
     mutable = model_class.objects.create(field=True,
                                          non_mutable_fk=specific_model)
     # Make sure the reverse descriptor is accessible before mutation
     self.assertEqual(specific_model.mutables.get(), mutable)
     # Add a field to the parent class
     NullBooleanFieldDefinition.objects.create(
         model_def=MutableModel.for_tenant(self.tenant).definition(),
         name='is_cool',
     )
     # Make sure the reverse descriptor is accessible after mutation
     self.assertEqual(specific_model.mutables.get(), mutable)
     self.assertEqual(
         1,
         model_class.objects.filter(field=True,
                                    is_cool=None,
                                    non_mutable_fk=specific_model).count())