def test_save_user_should_pass_form_to_template(self, mock): reload(app) app.SIGN_KEY = "test_key" with patch("app.get_survey_form"): with app.app.test_request_context("/"): app.before_request() app.save_user("First", "Last", "*****@*****.**") app.teardown_request(None) mock.assert_called_with("confirmation.html", form=app.get_survey_form("*****@*****.**")) app.SIGN_KEY = None
def test_save_user_duplicate(self, render): self.db.users.insert({"email": "*****@*****.**", "first_name": "Chico", "last_name": "Souza"}) render.return_value = "another template rendered" reload(app) with app.app.test_request_context("/"): app.before_request() content, status = app.save_user("Francisco", "Souza", "*****@*****.**") app.teardown_request(None) self.assertEqual("another template rendered", content) self.assertEqual(200, status) render.assert_called_with("confirmation.html", registered=True)
def test_save_user(self, render): render.return_value = "template rendered" reload(app) app.SIGN_KEY = "123456" with patch("app.get_survey_form"): with app.app.test_request_context("/"): app.before_request() content, status = app.save_user("Francisco", "Souza", "*****@*****.**", identity="123") app.teardown_request(None) self.assertEqual("template rendered", content) self.assertEqual(200, status) render.assert_called_with("confirmation.html", form=app.get_survey_form("*****@*****.**")) u = self.db.users.find_one( {"email": "*****@*****.**", "first_name": "Francisco", "last_name": "Souza", "identity": "123"} ) self.assertIsNotNone(u)