Debian Codegraph @

modeltranslation/tests/test_third_party.py

raw symbols SCIP
1 # pyright: reportGeneralTypeIssues=warning, reportOptionalMemberAccess=warning, reportOptionalOperand=warning
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 # 'model' attribute cannot be assigned to class in its definition,
21 # because ``models`` module will be reloaded and hence class would use old model classes.
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