Ejemplo n.º 1
0
    def test_get(self):
        tc = self.test_client
        ## Login required
        setup.assertRequiresLogin(self, tc.get("/goals/0/check-ins/0/"))

        ## Goal exists
        self.login()
        setup.assert404(self, tc.get("/goals/0/check-ins/0/"))
        
        ## user is goal owner
        goal = self.create_test_numeric_goal()
        goal_id = str(goal.get_id())
        self.logout()
        self.login_other_user()
        setup.assertInvalidCredentials(self, tc.get("/goals/" + goal_id + "/check-ins/0/"))
        
        ## Check in must exist
        self.logout()
        self.login()
        setup.assert404(self, tc.get("/goals/" + goal_id + "/check-ins/0/"))

        ## Returns correctly
        ci = CheckIn(goal, Timeframe.get_current_timeframe(goal.check_in_frequency_name), 1)
        ci.persist()
        tfid = str(ci.timeframe)
        res = tc.get("/goals/" + goal_id + "/check-ins/" + tfid + "/")
        setup.assertOk(self, res, 200)
        self.assertEqual(json.loads(res.data), ci.to_dict())
Ejemplo n.º 2
0
    def test_get(self):
        tc = self.test_client
        ## Login required
        setup.assertRequiresLogin(self, tc.get("/goals/0/check-ins/0/"))

        ## Goal exists
        self.login()
        setup.assert404(self, tc.get("/goals/0/check-ins/0/"))

        ## user is goal owner
        goal = self.create_test_numeric_goal()
        goal_id = str(goal.get_id())
        self.logout()
        self.login_other_user()
        setup.assertInvalidCredentials(
            self, tc.get("/goals/" + goal_id + "/check-ins/0/"))

        ## Check in must exist
        self.logout()
        self.login()
        setup.assert404(self, tc.get("/goals/" + goal_id + "/check-ins/0/"))

        ## Returns correctly
        ci = CheckIn(
            goal,
            Timeframe.get_current_timeframe(goal.check_in_frequency_name), 1)
        ci.persist()
        tfid = str(ci.timeframe)
        res = tc.get("/goals/" + goal_id + "/check-ins/" + tfid + "/")
        setup.assertOk(self, res, 200)
        self.assertEqual(json.loads(res.data), ci.to_dict())
Ejemplo n.º 3
0
    def test_persist(self): ## also tests exists, really -- and pull_by_id
        ci = self.get_test_check_in()
        self.assertFalse(ci.exists())
        ci.persist()
        self.assertTrue(ci.exists())
        self.assertIsNotNone(ci.get_id())
        self.assertEqual(ci.to_dict(), CheckIn.pull_by_id(ci.get_id()).to_dict())

        ## now if you overwrite that it should still work.
        ci = CheckIn(self.test_numeric_goal, self.test_tf, 60)
        self.assertTrue(ci.exists())
        ci.persist()        
        test_ci = CheckIn.pull_by_id(ci.get_id())
        self.assertEqual(ci.to_dict(), test_ci.to_dict())
        self.assertEqual(test_ci.value, 60)