python - django testing wrapped function view with mock -
i working through learning mock , cannot figure out why not working...
@validate_captcha def sendemail(request): ... email.send() return httpresponse('your email has been sent. thank contacting us')
i have wrapper validates google recaptcha , need test view cannot figure out how around wrapper.
i tried this....
@patch('main.views.sendemail') def test_sendmail_captcha_pass(self, mock_sendemail): """testing view after captcha passing""" mock_sendemail.return_value = true things = things() data = { 'subject': 'test subject', 'name': 'john appleseed', 'email': 'john@apple.com', 'content': 'content of message'} post_url = reverse("main:contact_email") result = things.client.post(post_url, {}) self.asserttrue(result.status_code == 401)
since sendemail function wrapped, using sendemail function @patch
instead of validate_captcha function cannot see next.
i have tried making mock object in shell , verified indeed give a wrapped version of sendemail function
Comments
Post a Comment