python - Testing page content after redirect not working -
i writing simple unit test method tests view redirecting after receiving post. can test expected url matches response object not content.
current shoddy code:
def test_example_view_redirects_to_home_after_post(self): client = client() response = client.post('/example/') # test location self.assertequal(response.get('location'), "http://testserver/") # test page content expected_template = render_to_string('home.html') self.assertequal(response.content, expected_template) the test failing:
assertionerror: b'' != '<html> etc etc... the view code can ultra simple @ stage:
def example(request): if request.method == "post": return httpresponseredirect('/') else: return render(request, 'example.html') i new tdd , wondering why isn't working might expect to.
thanks.
you can use
follow=trueinclient.postemulate browser following redirect next page. see here in docs. allow test second page's contentassertcontains.you can use
assertredirectstest redirect happens properly. check out here in docs.
Comments
Post a Comment