示例#1
0
 def test_should_return_400_when_data_is_invalid(self):
     data = {
         "email": "invalid email",
         "signature": app.sign("*****@*****.**"),
         "work": "ops",
         "country": "Brazil",
         "organization": "organization",
         "why": "compare",
     }
     app.SIGN_KEY = "sig_key"
     resp = self.api.post("/survey", data=data)
     self.assertEqual(400, resp.status_code)
示例#2
0
 def test_should_should_return_400_when_signatures_doesnt_match(self):
     app.SIGN_KEY = "sig_key"
     data = {
         "email": "*****@*****.**",
         "signature": app.sign("*****@*****.**"),
         "work": "ops",
         "country": "Brazil",
         "organization": "organization",
         "why": "compare",
     }
     resp = self.api.post("/survey", data=data)
     self.assertEqual(400, resp.status_code)
     expected = "Signatures don't match. " "You're probably doing something nasty."
     self.assertEqual(expected, resp.data)
示例#3
0
 def test_should_render_confirmation_template_registered(self, render):
     render.return_value = ""
     reload(app)
     app.SIGN_KEY = "sig_key"
     data = {
         "email": "*****@*****.**",
         "signature": app.sign("*****@*****.**"),
         "work": "ops",
         "country": "Brazil",
         "organization": "organization",
         "why": "compare",
     }
     resp = self.api.post("/survey", data=data)
     self.assertEqual(201, resp.status_code)
     render.assert_called_once_with("confirmation.html", registered=True)
示例#4
0
 def test_save(self):
     reload(app)  # this unmocks render_template
     app.SIGN_KEY = "sig_key"
     data = {
         "email": "*****@*****.**",
         "signature": app.sign("*****@*****.**"),
         "work": "student",
         "country": "Brazil",
         "organization": "organization",
         "why": "deploy",
     }
     resp = self.api.post("/survey", data=data)
     self.assertEqual(201, resp.status_code)
     s = self.db.survey.find_one({"email": data["email"]})
     self.assertIsNotNone(s)
示例#5
0
 def test_get_survey_form_should_initialize_signature_field(self, mock):
     app.SIGN_KEY = "test_key"
     email = "*****@*****.**"
     form = app.get_survey_form(email)
     self.assertEqual(app.sign(email), form.signature.data)
     app.SIGN_KEY = None
示例#6
0
 def test_sign(self):
     app.SIGN_KEY = "123456"
     email = "*****@*****.**"
     expected = hashlib.sha1(email + app.SIGN_KEY).hexdigest()
     self.assertEqual(expected, app.sign(email))