Re: [Django] #29098: Add SimpleTestCase.assertRedirectsRegex()

2019-02-15 Thread Django
#29098: Add SimpleTestCase.assertRedirectsRegex()
---+
 Reporter:  Dan J Strohl   |Owner:  (none)
 Type:  New feature|   Status:  new
Component:  Testing framework  |  Version:  2.1
 Severity:  Normal |   Resolution:
 Keywords:  unittest redirect  | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+
Changes (by Dan Davis):

 * cc: Dan Davis (added)
 * owner:  Dan Davis => (none)
 * status:  assigned => new


Comment:

 Someone else can work on this issue if they have time.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.d81cfb744069f9663bd11303ac52400c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29098: Add SimpleTestCase.assertRedirectsRegex()

2018-11-06 Thread Django
#29098: Add SimpleTestCase.assertRedirectsRegex()
---+-
 Reporter:  Dan J Strohl   |Owner:  Dan Davis
 Type:  New feature|   Status:  assigned
Component:  Testing framework  |  Version:  2.1
 Severity:  Normal |   Resolution:
 Keywords:  unittest redirect  | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+-

Comment (by Tim Graham):

 The version field simply reflects when the ticket was reported. All new
 features target the development branch of Django.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.e4f9f8d339019ec22bd6e6c09648dd0b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29098: Add SimpleTestCase.assertRedirectsRegex()

2018-11-05 Thread Django
#29098: Add SimpleTestCase.assertRedirectsRegex()
---+-
 Reporter:  Dan J Strohl   |Owner:  Dan Davis
 Type:  New feature|   Status:  assigned
Component:  Testing framework  |  Version:  2.1
 Severity:  Normal |   Resolution:
 Keywords:  unittest redirect  | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+-
Changes (by Dan Davis):

 * owner:  nobody => Dan Davis
 * status:  new => assigned
 * version:  1.11 => 2.1


Comment:

 I'll take this one.   Seems straight-forward enough.Not sure why it
 should be done on 1.11, because it doesn't seem severe enough.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.037bc767b75e865119f584b67bf97ade%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29098: Add SimpleTestCase.assertRedirectsRegex() (was: Allow assertRedirects to handle regex matches.)

2018-02-13 Thread Django
#29098: Add SimpleTestCase.assertRedirectsRegex()
---+
 Reporter:  Dan J Strohl   |Owner:  nobody
 Type:  New feature|   Status:  new
Component:  Testing framework  |  Version:  1.11
 Severity:  Normal |   Resolution:
 Keywords:  unittest redirect  | Triage Stage:  Accepted
Has patch:  0  |  Needs documentation:  0
  Needs tests:  0  |  Patch needs improvement:  0
Easy pickings:  0  |UI/UX:  0
---+
Changes (by Tim Graham):

 * type:  Cleanup/optimization => New feature
 * stage:  Unreviewed => Accepted


Old description:

> or, perhaps, allow it to use the patterns from the url's file.  Either
> way, the issue is that I have a view that gets a request, looks at it,
> and redirects it to a url such as /labs/12345/running, or
> /labs/4567/start.  this is a similar pattern to what is recommended and
> used in the admin, so I don't think I am doing something weird here, but
> I may not know what the redirect url will look like before I send the
> request (if I am sending something like /labs/new, and it returns
> /labs/12345 for example).
>
> as a hack, I did this:
> {{{
> #!div style="font-size: 80%"
> Code highlighting:
>   {{{#!python
> def fix_response_for_test(response, re_pattern, replace, count=0,
> flags=0):
>
> if hasattr(response, 'redirect_chain'):
> url, status_code = response.redirect_chain[-1]
>
> tmp_replaced = re.search(re_pattern, url, flags=flags)
> new_url = re.sub(re_pattern, replace, url, count=count,
> flags=flags)
>
> # print('redirect - new: %s' % new_url)
>
> response.redirect_chain[-1] = (new_url, status_code)
>
> else:
> # Not a followed redirect
> url = response.url
> scheme, netloc, path, query, fragment = urlsplit(url)
>
> # Prepend the request path to handle relative path redirects.
> if not path.startswith('/'):
> url = urljoin(response.request['PATH_INFO'], url)
>
> tmp_replaced = re.search(re_pattern, url, flags=flags)
> new_url = re.sub(re_pattern, replace, url, count=count,
> flags=flags)
>
> # print('no redirected - new: %s' % new_url)
>
> response['Location'] = new_url
>
> return tmp_replaced.group(0)
>   }}}
> }}}
>
> and is run like this:
>
> {{{
> #!div style="font-size: 80%"
> Code highlighting:
>   {{{#!python
>
> session_id = fix_response_for_test(response, UUID_REGEX,
> '')
>
> redirect_url = '/lab//error/'
>
> with self.subTest('%s - response url' % name):
> self.assertRedirects(response, redirect_url,
> fetch_redirect_response=False, msg_prefix=tmp_msg)
> test_session = Sessions.objects.get(session_id=session_id)
> # do more testing on the session object to make sure it was
> created correctly.
>   }}}
> }}}
>
> The returning the pulled content is nice, but probably not required as I
> COULD simply build two tests, one to check the redirect, and another to
> test the actual session object.
>
> If I had my druthers, I would love to see something like:
>
> {{{
> #!div style="font-size: 80%"
> Code highlighting:
>   {{{#!python
>
> args_obj=None
> self.assertRedirects(response, r'/labs/(?P.+)/(.+)',
> get_args=args_obj)
>
> # assuming this passes the assertion, args_obj then would ==
> # args_obj = {
> #'args': ['list of un-named items'],
> #'kwargs': {dict of kwargs}
>   }}}
> }}}
>
> This coudl also be approached by adding the ability to get this kind of
> thing directly from the response object, along the lines of:
> {{{
> #!div style="font-size: 80%"
> Code highlighting:
>   {{{#!python
>
> (assuming the request was '/labs/12344/test_page
> > my_response.seed_url()
> ' '//labs//(?P.+)//(.+)'  # which could then be matched in a
> redirect url match.
> > my_response.url_params(1)
> 'test_page'
> > my_response.url_params('foobar')
> '12344'
>
>   }}}
> }}}

New description:

 or, perhaps, allow it to use the patterns from the url's file.  Either
 way, the issue is that I have a view that gets a request, looks at it, and
 redirects it to a url such as /labs/12345/running, or /labs/4567/start.
 this is a similar pattern to what is recommended and used in the admin, so
 I don't think I am doing something weird here, but I may not know what the
 redirect url will look like before I send the request (if I am sending
 something like /labs/new, and it returns /labs/12345 for example).

 as a hack, I did this:
 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!python
 def fix_response_for_test(response, re_pattern, replace, count=0,
 flags=0):

 if hasattr(response, 'redirect_chain'):
 url, status_code =