-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Provide rest_framework.resolve. #2505
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
Provide rest_framework.resolve. #2505
Conversation
self.field.to_internal_value('/example/3/') | ||
self.field.to_internal_value('/v1/example/3/') | ||
|
||
|
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.
How about if we put this in tests/versioning.py
?
I'd also prefer if we can keep the urlpatterns isolated to the same module as the test.
Coming along nicely. One inline comment there. |
@tomchristie I moved the test to the proper location and reset urls.py. I would appreciate your quick input on two things:
I'm not sure what's going on there. If you have time to take a look that would be great; otherwise, I'll continue on it tomorrow. |
@@ -127,6 +132,17 @@ def reverse(self, viewname, args=None, kwargs=None, request=None, format=None, * | |||
viewname, args, kwargs, request, format, **extra | |||
) | |||
|
|||
def resolve(self, path, urlconf=None, request=None): | |||
match = django_resolve(path, urlconf) | |||
if match.namespace: |
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.
Rather than returning a new match is it possible to just mutate the one we've gotten back?
Eg.
match = django_resolve(path, urlconf)
match.namespaces = match.namespaces[1:]
return match
Issue was due to using SimpleAPITestCase, presumably not using the full urlpatterns/resolvers machinery in that case. I've gone with a slightly simpler implementation, based on your work, where we don't both to go for a full |
Thanks for all your work on this! :) |
@tomchristie Thank-you! The resolve was a nice complement to reverse, but it was too much overhead for the one spot we need it right now. Sorry I wasn't available to finish off my work. :) |
Fixes #2489.
The Django 1.4.x tox tests were failing as
tests.urls
was empty, so I included the necessary urlpatterns from test_relations.py.