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
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, "*****@*****.**")
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, "*****@*****.**")
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())
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"))
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, "*****@*****.**")
def get_user(id): user = User.pull_by_id(id) if (not user): raise NotFoundError() return user.to_json(), HTTP_200_OK