|
1 | 1 | import pytest
|
2 |
| -from django.contrib import admin |
3 | 2 | from django.contrib.auth.models import User
|
4 |
| -from django.core import checks |
5 | 3 | from django.core.exceptions import ImproperlyConfigured
|
6 |
| -from django.db import connection, models |
7 |
| -from django.test.utils import CaptureQueriesContext, isolate_apps |
| 4 | +from django.db import connection |
| 5 | +from django.test.utils import CaptureQueriesContext |
8 | 6 | from django.urls import reverse
|
9 | 7 | from pytest_django.asserts import assertContains
|
10 | 8 |
|
11 |
| -from content_editor.admin import ContentEditor, ContentEditorInline |
12 | 9 | from content_editor.contents import contents_for_item
|
13 | 10 | from content_editor.models import Region
|
14 | 11 | from testapp.models import Article, Download, RichText
|
@@ -93,80 +90,6 @@ def test_admin(client):
|
93 | 90 | assertContains(response, 'value="Test"', 1)
|
94 | 91 |
|
95 | 92 |
|
96 |
| -@isolate_apps() |
97 |
| -def test_model_checks(): |
98 |
| - class Model(models.Model): |
99 |
| - name = models.CharField() |
100 |
| - |
101 |
| - def __str__(self): |
102 |
| - return self.name |
103 |
| - |
104 |
| - class ModelAdmin(ContentEditor): |
105 |
| - model = Model |
106 |
| - inlines = [] |
107 |
| - |
108 |
| - assert ModelAdmin(Model, admin.AdminSite()).check() == [ |
109 |
| - checks.Error( |
110 |
| - "ContentEditor models require a non-empty 'regions' attribute or property.", |
111 |
| - obj=ModelAdmin, |
112 |
| - id="content_editor.E002", |
113 |
| - ) |
114 |
| - ] |
115 |
| - |
116 |
| - |
117 |
| -def test_inline_checks(): |
118 |
| - assert admin.ModelAdmin(Article, admin.AdminSite()).check() == [] |
119 |
| - |
120 |
| - class RichTextInline(ContentEditorInline): |
121 |
| - model = RichText |
122 |
| - # Purposefully construct an inline with missing region |
123 |
| - # and ordering fields |
124 |
| - fieldsets = [(None, {"fields": ("text",)})] |
125 |
| - |
126 |
| - class InvalidRegionsStringInline(ContentEditorInline): |
127 |
| - model = RichText |
128 |
| - regions = "main" |
129 |
| - |
130 |
| - class InvalidRegionsCallableInline(ContentEditorInline): |
131 |
| - model = RichText |
132 |
| - |
133 |
| - def regions(self, all_regions): |
134 |
| - return "main" |
135 |
| - |
136 |
| - class ValidRegionsGeneratorInline(ContentEditorInline): |
137 |
| - model = RichText |
138 |
| - |
139 |
| - def regions(self, all_regions): |
140 |
| - yield "main" |
141 |
| - |
142 |
| - class ArticleAdmin(ContentEditor): |
143 |
| - model = Article |
144 |
| - inlines = [ |
145 |
| - RichTextInline, |
146 |
| - InvalidRegionsStringInline, |
147 |
| - InvalidRegionsCallableInline, |
148 |
| - ValidRegionsGeneratorInline, |
149 |
| - ] |
150 |
| - |
151 |
| - assert ArticleAdmin(Article, admin.AdminSite()).check() == [ |
152 |
| - checks.Error( |
153 |
| - "fieldsets must contain both 'region' and 'ordering'.", |
154 |
| - obj=RichTextInline, |
155 |
| - id="content_editor.E001", |
156 |
| - ), |
157 |
| - checks.Error( |
158 |
| - "regions must be 'None' or an iterable. Current value is 'main'.", |
159 |
| - obj=InvalidRegionsStringInline, |
160 |
| - id="content_editor.E003", |
161 |
| - ), |
162 |
| - checks.Error( |
163 |
| - "regions must be 'None' or an iterable. Current value is 'main'.", |
164 |
| - obj=InvalidRegionsCallableInline, |
165 |
| - id="content_editor.E003", |
166 |
| - ), |
167 |
| - ] |
168 |
| - |
169 |
| - |
170 | 93 | def test_invalid_region_objects():
|
171 | 94 | with pytest.raises(ImproperlyConfigured):
|
172 | 95 | Region(key="regions", title="regions")
|
|
0 commit comments