| 1 |
|
| 2 |
|
| 3 |
from django import forms |
| 4 |
from django.test import TestCase |
| 5 |
|
| 6 |
from modeltranslation.tests import models |
| 7 |
|
| 8 |
|
| 9 |
class ThirdPartyAppIntegrationTest(TestCase): |
| 10 |
""" |
| 11 |
This test case and a test case below have identical tests. The models they test have the same |
| 12 |
definition - but in this case the model is not registered for translation and in the other |
| 13 |
case it is. |
| 14 |
""" |
| 15 |
|
| 16 |
registered = False |
| 17 |
|
| 18 |
@classmethod |
| 19 |
def setUpClass(cls): |
| 20 |
|
| 21 |
|
| 22 |
super().setUpClass() |
| 23 |
cls.model = models.ThirdPartyModel |
| 24 |
|
| 25 |
def test_form(self): |
| 26 |
class CreationForm(forms.ModelForm): |
| 27 |
class Meta: |
| 28 |
model = self.model |
| 29 |
fields = "__all__" |
| 30 |
|
| 31 |
creation_form = CreationForm({"name": "abc"}) |
| 32 |
inst = creation_form.save() |
| 33 |
assert "abc" == inst.name |
| 34 |
assert 1 == self.model.objects.count() |
| 35 |
|
| 36 |
|
| 37 |
class ThirdPartyAppIntegrationRegisteredTest(ThirdPartyAppIntegrationTest): |
| 38 |
registered = True |
| 39 |
|
| 40 |
@classmethod |
| 41 |
def setUpClass(cls): |
| 42 |
super().setUpClass() |
| 43 |
cls.model = models.ThirdPartyRegisteredModel |