-
-
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
check for matching alias before subproject slug #2787
Conversation
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This test causes test_resolver_subproject_alias
to fail if it runs first ("fixed" by creatively renaming so it runs after).
I had a bit of a look around to see if there's a cache I can easily clean but couldn't find anything.
Depends how much of an issue you think this is, but if you're worried & can give me a pointer I'll happily update it to dtrt
f856067
to
e07be83
Compare
Hi all, it's been 6 months since I've seen an update on this PR, and the issue is still affecting readthedocs.org ... any chance we can get this merged/let me know if changes are required? Thanks |
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): | ||
with override_settings(USE_SUBDOMAIN=True): |
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.
Can you use override_settings
as decorator?
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.
done :)
Do you need anything else before this can be merged? Happy to make any required changes |
readthedocs/core/views/serve.py
Outdated
) | ||
subproject = rel.child | ||
except (ProjectRelationship.DoesNotExist, KeyError): | ||
subproject = Project.objects.get(slug=subproject_slug) |
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 with get_object_or_404()
: https://docs.djangoproject.com/en/1.9/topics/http/shortcuts/#get-object-or-404
|
||
class ResolverAltSetUp(object): | ||
|
||
def setUp(self): |
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.
The use of setUpTestData
would make tests faster: https://docs.djangoproject.com/en/1.9/topics/testing/tools/#django.test.TestCase.setUpTestData
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.
It does save 8s (out of ~20 for the module 👍), but it also seems to change the results:
self = <readthedocs.rtd_tests.tests.test_resolver.SmartResolverPathTests testMethod=test_resolver_subproject_subdomain>
def test_resolver_subproject_subdomain(self):
with override_settings(USE_SUBDOMAIN=False):
import pdb; pdb.set_trace()
url = resolve_path(project=self.subproject, filename='index.html')
> self.assertEqual(url, '/docs/pip/projects/sub/ja/latest/')
E AssertionError: u'/docs/pip/projects/sub/' != '/docs/pip/projects/sub/ja/latest/'
rtd_tests/tests/test_resolver.py:105: AssertionError
_______________________________ SmartResolverPathTestsAlt.test_resolver_subproject_subdomain _______________________________
self = <readthedocs.rtd_tests.tests.test_resolver.SmartResolverPathTestsAlt testMethod=test_resolver_subproject_subdomain>
def test_resolver_subproject_subdomain(self):
with override_settings(USE_SUBDOMAIN=False):
import pdb; pdb.set_trace()
> url = resolve_path(project=self.subproject, filename='index.html')
E AssertionError: u'/docs/pip/projects/sub/' != '/docs/pip/projects/sub/ja/latest/'
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is SmartResolverPathTestsAlt.test_resolver_subproject_subdomain
the only failing test? SmartResolverPathTests
is the base class of SmartResolverPathTestsAlt
and ResolverBase
is the base class of SmartResolverPathTests
. There is a setUp
method defined in ResolverBase
:
That method can be cause of the test failure.
Adding
setUp = None
to SmartResolverPathTestsAlt
may help.
There is also the following warning in setUpTestData
documentation:
Be careful not to modify any objects created in setUpTestData() in your test methods. Modifications to in-memory objects from setup work done at the class level will persist between test methods. If you do need to modify them, you could reload them in the setUp() method with refresh_from_db(), for example.
And we indeed do modify objects created in setUpTestData
. For example:
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.
test_resolver_subproject_subdomain
from both SmartResolverPathTests
and SmartResolverPathTestsAlt
(i.e. yes, the one defined test).
These 2 failures are happening with both setUp
methods (i.e. in ResolverBase
and ResolverAltSetUp
) converted to seUpTestData
classmethods.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's leave it to a separate PR.
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 comment
The 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.
701e221
to
9bb0f28
Compare
readthedocs/core/views/serve.py
Outdated
subproject = Project.objects.get(slug=subproject_slug) | ||
except Project.DoesNotExist: | ||
raise Http404 | ||
get_object_or_404(Project, slug=subproject_slug) |
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.
Shouldn't this line be read as
subproject = get_object_or_404(Project, slug=subproject_slug)
?
I just ran into this as well. I would love to see this fixed so we don't need to encode language and version into URLs unnecessarily. |
Can you include a link to something that reproduces this issue currently? There are likely other bugs that are causing this code to be hit. |
Ah, I found #2731 -- will give it a peek. |
Looks good. Thanks for the patch -- sorry it took so long to review! |
fixes #2731