Note that there are some explanatory texts on larger screens.

plurals
  1. POFunctional Testing a Flask App: Weird Twill Traceback
    primarykey
    data
    text
    <p>I'm testing my Flask app.</p> <p><strong>In summary, here is my question(s):</strong></p> <p>1) My final url assertion in the block of code below fails. According to Twill, it fails because the actual url is '/auth/login'. In other words, the user was NOT redirected to the protected admin page. Why?</p> <p>2) How can I include the "/?next='admin'" request argument in my url assertion? In other words, is there a way--via Twill or any Pythonic means--to test the 'next' argument resolved correctly?</p> <p>3) In functional testing, is there any other way to show a redirect works beyond just asserting a 301 status code?</p> <p><strong>Here's the Twill related part of my script...</strong></p> <pre> t.browser.go(t.url("/auth/login/?next=%2Fadmin%2F")) url("/auth/login/?next=%2Fadmin%2F") </pre> <p>Here's the resultant traceback:</p> <pre> TwillAssertionError: current url is 'http://127.0.0.1:5000/auth/login/?next=%2Fadmin%2F'; does not match '/auth/login/?next=%2Fadmin%2F' </pre> <p>NOTE: Weirdly, asserting a 200 status code after the 'go' command does not return any kind of error. I'd like to show that, after logging into the above URL, that the final URL is, indeed, the admin page. Like so...</p> <p><strong>The test I'd like to run without any fails, but can't...</strong></p> <pre> def test_redirect_via_url(self): with Twill(self.app, port=8080) as t: #: go to admin page before logging in... t.browser.go(t.url("/admin")) #: assert admin url redirected to login url url('/auth/login') #: The above assertion works, but... #: why can't I assert this URL..a 'next' argument...? #: "/auth/login/?next=%2Fadmin%2F" #: that's what actually appears in the browser's address bar #: In any regard, at the '/auth/login' url, let's login fv("1", "username", "test") fv("1", "password", "welcome1") submit() #: Now I want to show my app actually redirects to the protected admin page... #: which should have a URL of localhost/admin url('/admin') #: The above url assertion fails. The actual url after submit is still '/auth/login' </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload