|
3 | 3 | import sys
|
4 | 4 |
|
5 | 5 | import pytest
|
6 |
| -from django.urls.base import set_urlconf, get_urlconf |
7 | 6 | from django.test import TestCase
|
8 | 7 | from django.test.utils import override_settings
|
| 8 | +from django.urls.base import get_urlconf, set_urlconf |
9 | 9 | from django_dynamic_fixture import get
|
10 | 10 |
|
| 11 | +from readthedocs.builds.models import Version |
| 12 | +from readthedocs.projects.constants import PUBLIC |
11 | 13 | from readthedocs.projects.models import Domain, Project, ProjectRelationship
|
12 | 14 | from readthedocs.proxito.middleware import ProxitoMiddleware
|
13 | 15 | from readthedocs.rtd_tests.base import RequestFactoryTestMixin
|
@@ -159,16 +161,23 @@ def setUp(self):
|
159 | 161 | Project,
|
160 | 162 | slug='pip',
|
161 | 163 | users=[self.owner],
|
162 |
| - privacy_level='public', |
| 164 | + privacy_level=PUBLIC, |
163 | 165 | urlconf='subpath/to/$version/$language/$filename' # Flipped
|
164 | 166 | )
|
| 167 | + self.testing_version = get( |
| 168 | + Version, |
| 169 | + slug='testing', |
| 170 | + project=self.pip, |
| 171 | + built=True, |
| 172 | + active=True, |
| 173 | + ) |
| 174 | + self.pip.versions.update(privacy_level=PUBLIC) |
165 | 175 |
|
166 |
| - self.old_urlconf = get_urlconf() |
167 | 176 | sys.modules['fake_urlconf'] = self.pip.proxito_urlconf
|
168 | 177 | set_urlconf('fake_urlconf')
|
169 | 178 |
|
170 | 179 | def tearDown(self):
|
171 |
| - set_urlconf(self.old_urlconf) |
| 180 | + set_urlconf(None) |
172 | 181 |
|
173 | 182 | def test_proxied_api_methods(self):
|
174 | 183 | # This is mostly a unit test, but useful to make sure the below tests work
|
@@ -221,29 +230,38 @@ def setUp(self):
|
221 | 230 | name='pip',
|
222 | 231 | slug='pip',
|
223 | 232 | users=[self.owner],
|
224 |
| - privacy_level='public', |
| 233 | + privacy_level=PUBLIC, |
225 | 234 | urlconf='subpath/$subproject/$version/$language/$filename' # Flipped
|
226 | 235 | )
|
| 236 | + self.pip.versions.update(privacy_level=PUBLIC) |
227 | 237 | self.subproject = get(
|
228 | 238 | Project,
|
229 | 239 | name='subproject',
|
230 | 240 | slug='subproject',
|
231 | 241 | users=[self.owner],
|
232 |
| - privacy_level='public', |
| 242 | + privacy_level=PUBLIC, |
233 | 243 | main_language_project=None,
|
234 | 244 | )
|
| 245 | + self.testing_version = get( |
| 246 | + Version, |
| 247 | + slug='testing', |
| 248 | + project=self.subproject, |
| 249 | + built=True, |
| 250 | + active=True, |
| 251 | + ) |
| 252 | + self.subproject.versions.update(privacy_level=PUBLIC) |
235 | 253 | self.relationship = get(
|
236 | 254 | ProjectRelationship,
|
237 | 255 | parent=self.pip,
|
238 | 256 | child=self.subproject,
|
239 | 257 | )
|
240 | 258 |
|
241 |
| - self.old_urlconf = get_urlconf() |
242 | 259 | sys.modules['fake_urlconf'] = self.pip.proxito_urlconf
|
243 | 260 | set_urlconf('fake_urlconf')
|
244 | 261 |
|
245 |
| - # TODO: Figure out why this is failing in travis |
246 |
| - @pytest.mark.xfail(strict=True) |
| 262 | + def tearDown(self): |
| 263 | + set_urlconf(None) |
| 264 | + |
247 | 265 | def test_middleware_urlconf_subproject(self):
|
248 | 266 | resp = self.client.get('/subpath/subproject/testing/en/foodex.html', HTTP_HOST=self.domain)
|
249 | 267 | self.assertEqual(resp.status_code, 200)
|
|
0 commit comments