@@ -173,6 +173,47 @@ def test_create_domain_with_single_cname(self, dns_resolve_mock):
173
173
domain = self .project .domains .first ()
174
174
assert domain .domain == "docs.example.com"
175
175
176
+ @override_settings (
177
+ RTD_DEFAULT_FEATURES = dict (
178
+ [RTDProductFeature (type = TYPE_CNAME , value = 1 ).to_item ()]
179
+ ),
180
+ )
181
+ @mock .patch ("readthedocs.projects.forms.dns.resolver.resolve" )
182
+ def test_domains_limit (self , dns_resolve_mock ):
183
+ dns_resolve_mock .side_effect = dns .resolver .NoAnswer
184
+ assert self .project .domains .count () == 0
185
+
186
+ # Create the first domain
187
+ resp = self .client .post (
188
+ reverse ("projects_domains_create" , args = [self .project .slug ]),
189
+ data = {"domain" : "test1.example.com" },
190
+ )
191
+ assert resp .status_code == 302
192
+ assert self .project .domains .count () == 1
193
+
194
+ # Create the second domain
195
+ resp = self .client .post (
196
+ reverse ("projects_domains_create" , args = [self .project .slug ]),
197
+ data = {"domain" : "test2.example.com" },
198
+ )
199
+ assert resp .status_code == 200
200
+ form = resp .context_data ["form" ]
201
+ assert not form .is_valid ()
202
+ assert "has reached the limit" in form .errors ["__all__" ][0 ]
203
+ assert self .project .domains .count () == 1
204
+
205
+ # Edit the existing domain
206
+ domain = self .project .domains .first ()
207
+ assert not domain .canonical
208
+ resp = self .client .post (
209
+ reverse ("projects_domains_edit" , args = [self .project .slug , domain .pk ]),
210
+ data = {"canonical" : True },
211
+ )
212
+ assert resp .status_code == 302
213
+ assert self .project .domains .count () == 1
214
+ domain = self .project .domains .first ()
215
+ assert domain .canonical
216
+
176
217
177
218
@override_settings (RTD_ALLOW_ORGANIZATIONS = True )
178
219
class TestDomainViewsWithOrganizations (TestDomainViews ):
0 commit comments