Esempio n. 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
Esempio n. 2
0
def create_test_users():
    for x in range(ord('a'), ord('a') + 26):
        x = chr(x)
        email = "test_" + str(x) + "@example.com"
        new_user = User(email, "test-pass", x + "_first", x + "_last")
        new_user.registered = new_user.registered_on - datetime.timedelta(hours=30-(ord(x)-ord('a')))
        db.session.add(new_user)

    db.session.flush()
    db.session.commit()
Esempio n. 3
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())
Esempio n. 4
0
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
import datetime
from goly import app, db
from goly.models.user import User
from goly.models.goal import Goal
import copy
import json


test_client = app.test_client()
test_user_pass = "******"
test_user_name = "*****@*****.**"
test_user = User(test_user_name, test_user_pass, "first", "last")

other_user_name = "*****@*****.**"
other_user_pass = "******"
other_user = User(other_user_name, other_user_pass, "other", "user")

def login_test_user():
    create_test_user()
    res = test_client.post("/login/", data={"email": test_user_name, "password": test_user_pass})
    return res 

def logout():
    res = test_client.post("/logout/")
    return res

def login_other_user():
    create_other_user()
Esempio n. 5
0
    def test_init(self):
        ## Test that all of the validators work!
        fake_user = User("notreal", "notreal", "notreal", "notreal")
        with self.assertRaisesRegexp(AssertionError, "user does not exist"):
            goal = Goal(fake_user, "test name", "test prompt", "weekly", 10,
                        "binary", "daily")

        with self.assertRaisesRegexp(AssertionError, "user must be a User"):
            goal = Goal("Jimmy", "test", "test prompt", "weekly", 10, "binary",
                        "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "Name must be between 0 and 50"):
            goal = Goal(self.test_user, " ", "test prompt", "weekly", 10,
                        "binary", "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "Name must be between 0 and 50"):
            goal = Goal(self.test_user, "a" * 51, "test prompt", "weekly", 10,
                        "binary", "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "Prompt must be between 0 and 255"):
            goal = Goal(self.test_user, "test", " ", "weekly", 10, "binary",
                        "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "Prompt must be between 0 and 255"):
            goal = Goal(self.test_user, "test", "a" * 256, "weekly", 10,
                        "binary", "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "frequency must be one of "):
            goal = Goal(self.test_user, "test", "test prompt", "not-an-option",
                        10, "binary", "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "Target must be an integer"):
            goal = Goal(self.test_user, "test", "test prompt", "weekly",
                        "banana", "binary", "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "Input type must be binary or numeric"):
            goal = Goal(self.test_user, "test", "test prompt", "weekly", 10,
                        "banana", "daily")

        with self.assertRaisesRegexp(AssertionError,
                                     "check_in_frequency must be one of"):
            goal = Goal(self.test_user, "test", "test prompt", "weekly", 10,
                        "numeric", "only on fudge sundaes")

        with self.assertRaisesRegexp(
                AssertionError,
                "Check-in frequency must conform to frequency"):
            goal = Goal(self.test_user, "test", "test prompt", "weekly", 10,
                        "numeric", "monthly")

        goal = Goal(self.test_user, "test", "test prompt", "weekly", "10",
                    "binary", "daily")
        self.assertIsInstance(goal, Goal)
        self.assertTrue(goal.active)
        self.assertFalse(goal.public)

        with self.assertRaisesRegexp(AssertionError,
                                     "Active must be a boolean"):
            goal.active = "fish"

        with self.assertRaisesRegexp(AssertionError,
                                     "Public must be a boolean"):
            goal.public = "filet"