Esempio n. 1
0
def get_goals_by_user(id):
    """Show all public goals for a given user"""
    user = User.pull_by_id(id)
    if (not user):
        raise NotFoundError()

    validate_sort(request.args, ["id", "created", "name", "frequency"])
    goals = Goal.pull_by_user(id, request.args, True)

    return jsonify({"goals": [x.to_dict() for x in goals]}), HTTP_200_OK
Esempio n. 2
0
def get_goals_by_user(id):
    """Show all public goals for a given user"""
    user = User.pull_by_id(id)
    if (not user): 
        raise NotFoundError()

    validate_sort(request.args, ["id", "created", "name", "frequency"])
    goals = Goal.pull_by_user(id, request.args, True)

    return jsonify({"goals": [x.to_dict() for x in goals]}), HTTP_200_OK
Esempio n. 3
0
    def test_update(self):
        self.assertFalse(self.new_user.exists())
        self.new_user.update({"not-a-real-key": "anything"}) ## This whould actually run but not do anything.
        self.assertFalse(self.new_user.exists())

        self.new_user.update({"first_name": "new-first-name"})
        self.assertEqual(self.new_user.first_name, "new-first-name")
        self.assertFalse(self.new_user.exists())

        self.new_user.persist()
        user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(user.first_name, "new-first-name")
        self.new_user.update({"first_name": "first"})
        user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(user.first_name, "first")
        
        self.new_user.update({"email": "this-shouldnt-work"})
        self.assertIsNone(User.pull_by_email("this-shouldnt-work"))
        self.assertEqual(self.new_user.email, "*****@*****.**")
Esempio n. 4
0
    def test_update(self):
        self.assertFalse(self.new_user.exists())
        self.new_user.update(
            {"not-a-real-key":
             "anything"})  ## This whould actually run but not do anything.
        self.assertFalse(self.new_user.exists())

        self.new_user.update({"first_name": "new-first-name"})
        self.assertEqual(self.new_user.first_name, "new-first-name")
        self.assertFalse(self.new_user.exists())

        self.new_user.persist()
        user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(user.first_name, "new-first-name")
        self.new_user.update({"first_name": "first"})
        user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(user.first_name, "first")

        self.new_user.update({"email": "this-shouldnt-work"})
        self.assertIsNone(User.pull_by_email("this-shouldnt-work"))
        self.assertEqual(self.new_user.email, "*****@*****.**")
Esempio n. 5
0
    def test_persist_and_destroy(self):
        self.assertFalse(self.new_user.exists())
        self.new_user.persist()
        self.assertTrue(self.new_user.exists())

        test_user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(test_user, self.new_user)

        test_user = User.pull_by_email(self.new_user.email)
        self.assertEqual(test_user, self.new_user)

        self.new_user.destroy()
        self.assertFalse(self.new_user.exists())
Esempio n. 6
0
    def test_persist_and_destroy(self):
        self.assertFalse(self.new_user.exists())
        self.new_user.persist()
        self.assertTrue(self.new_user.exists())

        test_user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(test_user, self.new_user)

        test_user = User.pull_by_email(self.new_user.email)
        self.assertEqual(test_user, self.new_user)

        self.new_user.destroy()
        self.assertFalse(self.new_user.exists())
Esempio n. 7
0
    def test_update_password(self):
        self.new_user.update_password("test-pass", "new-test-pass")
        self.assertTrue(self.new_user.check_password("new-test-pass"))
        self.new_user.update_password("new-test-pass", "test-pass")
        with self.assertRaises(goly.errors.UnauthorizedError):
            self.new_user.update_password("not-my-password", "new-test-pass")

        self.new_user.persist()
        self.new_user.update_password("test-pass", "new-test-pass")
        self.assertFalse(self.new_user.check_password("test-pass"))
        self.assertTrue(self.new_user.check_password("new-test-pass"))
        self.assertTrue(self.new_user.exists())

        user = User.pull_by_id(self.new_user.get_id())
        self.assertTrue(user.check_password("new-test-pass"))
Esempio n. 8
0
    def test_update_password(self):
        self.new_user.update_password("test-pass", "new-test-pass")
        self.assertTrue(self.new_user.check_password("new-test-pass"))
        self.new_user.update_password("new-test-pass", "test-pass")
        with self.assertRaises(goly.errors.UnauthorizedError):
            self.new_user.update_password("not-my-password", "new-test-pass")

        self.new_user.persist()
        self.new_user.update_password("test-pass", "new-test-pass")
        self.assertFalse(self.new_user.check_password("test-pass"))
        self.assertTrue(self.new_user.check_password("new-test-pass"))
        self.assertTrue(self.new_user.exists())

        user = User.pull_by_id(self.new_user.get_id())
        self.assertTrue(user.check_password("new-test-pass"))
Esempio n. 9
0
    def test_update_email(self):
        with self.assertRaises(goly.errors.UnauthorizedError):
            self.new_user.update_email("*****@*****.**", "not-my-password")

        self.new_user.update_email("*****@*****.**", "test-pass")
        self.assertEqual(self.new_user.email, "*****@*****.**")
        self.assertFalse(self.new_user.exists())

        self.new_user.persist()
        self.new_user.update_email("*****@*****.**", "test-pass")
        self.assertTrue(self.new_user.exists())
        self.assertEqual(self.new_user.email, "*****@*****.**")
        self.assertIsNotNone(User.pull_by_email("*****@*****.**"))

        user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(user.email, "*****@*****.**")
Esempio n. 10
0
    def test_update_email(self):
        with self.assertRaises(goly.errors.UnauthorizedError):
            self.new_user.update_email("*****@*****.**",
                                       "not-my-password")

        self.new_user.update_email("*****@*****.**", "test-pass")
        self.assertEqual(self.new_user.email, "*****@*****.**")
        self.assertFalse(self.new_user.exists())

        self.new_user.persist()
        self.new_user.update_email("*****@*****.**", "test-pass")
        self.assertTrue(self.new_user.exists())
        self.assertEqual(self.new_user.email, "*****@*****.**")
        self.assertIsNotNone(User.pull_by_email("*****@*****.**"))

        user = User.pull_by_id(self.new_user.get_id())
        self.assertEqual(user.email, "*****@*****.**")
Esempio n. 11
0
def get_user(id):
    user = User.pull_by_id(id)
    if (not user):
        raise NotFoundError()

    return user.to_json(), HTTP_200_OK