Ejemplo n.º 1
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"