예제 #1
0
def register():
    validate_form(request.form,
                  ['email', 'password', 'first_name', 'last_name'])
    user = User(request.form['email'], request.form['password'],
                request.form['first_name'], request.form['last_name'])
    user.persist()
    return_val = user.to_json()

    return return_val, 201
예제 #2
0
    def test_destroy(self):
        user = User(self.new_user['email'], self.new_user['password'], self.new_user['first_name'], self.new_user['last_name'])
        user.persist()
        self.assertTrue(user.exists()) ## I don't understand why but this is necessary or else line 45 fails

        tc = self.test_client
        res = tc.post("/users/delete/", data={"email": "fake email"})
        setup.assertInvalid(self, res, 'password')

        res = tc.post("/users/delete/", data={"email": "fake email", "password": "******"})
        data = json.loads(res.data)
        setup.assertInvalidCredentials(self, res)
        self.assertTrue(user.exists())

        tc = self.test_client
        res = tc.post("/users/delete/", data={"email": user.email, "password": "******"})
        data = json.loads(res.data)
        setup.assertInvalidCredentials(self, res)
        self.assertTrue(user.exists())

        res = tc.post("/users/delete/", data={"email": user.email, "password": "******"})
        setup.assertOk(self, res, 204)
        self.assertFalse(user.exists())