-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check for matching alias before subproject slug #2787
Changes from 2 commits
9130f38
e07be83
c3d2ddc
a4bb8e3
9bb0f28
6a66934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,3 +385,32 @@ def test_resolver_public_domain_overrides(self): | |
self.assertEqual(url, 'http://docs.foobar.com/en/latest/') | ||
url = resolve(project=self.pip, private=False) | ||
self.assertEqual(url, 'http://docs.foobar.com/en/latest/') | ||
|
||
|
||
class ResolverAltSetUp(object): | ||
|
||
def setUp(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does save 8s (out of ~20 for the module 👍), but it also seems to change the results:
I'm not really sure what's going on to cause that, unfortunately. Any clues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is That method can be cause of the test failure. Adding setUp = None to There is also the following warning in
And we indeed do modify objects created in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Are you happy to leave this optimisation for now? Reworking all the modifications seems like overkill for 8s savings (maybe should be a separate PR in any case)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, let's leave it to a separate PR. |
||
with mock.patch('readthedocs.projects.models.broadcast'): | ||
self.owner = create_user(username='owner', password='test') | ||
self.tester = create_user(username='tester', password='test') | ||
self.pip = get(Project, slug='pip', users=[self.owner], main_language_project=None) | ||
self.seed = get(Project, slug='sub', users=[self.owner], main_language_project=None) | ||
self.subproject = get(Project, slug='subproject', language='ja', users=[self.owner], main_language_project=None) | ||
self.translation = get(Project, slug='trans', language='ja', users=[self.owner], main_language_project=None) | ||
self.pip.add_subproject(self.subproject, alias='sub') | ||
self.pip.translations.add(self.translation) | ||
|
||
|
||
@override_settings(PUBLIC_DOMAIN='readthedocs.org') | ||
class ResolverDomainTestsAlt(ResolverAltSetUp, ResolverDomainTests): | ||
pass | ||
|
||
|
||
@override_settings(PUBLIC_DOMAIN='readthedocs.org') | ||
class SmartResolverPathTestsAlt(ResolverAltSetUp, SmartResolverPathTests): | ||
pass | ||
|
||
|
||
@override_settings(PUBLIC_DOMAIN='readthedocs.org') | ||
class ResolverTestsAlt(ResolverAltSetUp, ResolverTests): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,24 +152,34 @@ def setUp(self): | |
self.owner = create_user(username='owner', password='test') | ||
self.tester = create_user(username='tester', password='test') | ||
self.pip = fixture.get(Project, slug='pip', users=[self.owner], main_language_project=None) | ||
self.subproject = fixture.get(Project, slug='sub', language='ja', | ||
users=[ self.owner], | ||
main_language_project=None) | ||
self.translation = fixture.get(Project, slug='trans', language='ja', | ||
users=[ self.owner], | ||
main_language_project=None) | ||
self.subproject = fixture.get(Project, slug='sub', language='ja', users=[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd revert these style changes if the linting tool is happy with the old style. |
||
self.owner], main_language_project=None) | ||
self.translation = fixture.get(Project, slug='trans', language='ja', users=[ | ||
self.owner], main_language_project=None) | ||
self.pip.add_subproject(self.subproject) | ||
self.pip.translations.add(self.translation) | ||
|
||
@override_settings(PRODUCTION_DOMAIN='readthedocs.org') | ||
def test_resolver_subproject_alias(self): | ||
relation = self.pip.subprojects.first() | ||
relation.alias = 'sub_alias' | ||
relation.save() | ||
fixture.get(Project, slug='sub_alias', language='ya') | ||
|
||
|
||
@override_settings(PRODUCTION_DOMAIN='readthedocs.org') | ||
def test_resolver_subproject_alias(self): | ||
with override_settings(USE_SUBDOMAIN=False): | ||
resp = self.client.get('/docs/pip/projects/sub_alias/') | ||
self.assertEqual(resp.status_code, 302) | ||
self.assertEqual( | ||
resp._headers['location'][1], | ||
'http://readthedocs.org/docs/pip/projects/sub_alias/ja/latest/' | ||
) | ||
|
||
def test_resolver_subproject_subdomain_alias(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test causes |
||
with override_settings(USE_SUBDOMAIN=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done :) |
||
resp = self.client.get('/projects/sub_alias/', HTTP_HOST='pip.readthedocs.org') | ||
self.assertEqual(resp.status_code, 302) | ||
self.assertEqual( | ||
resp._headers['location'][1], | ||
'http://pip.readthedocs.org/projects/sub_alias/ja/latest/' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could replace the whole
try...except...raise
block withget_object_or_404()
: https://docs.djangoproject.com/en/1.9/topics/http/shortcuts/#get-object-or-404