Esempio n. 1
0
    def setup(self):
        self.blank_errors = Errors()

        self.errors = Errors()
        self.errors.add('test', "can't be blank")
        self.errors.add('other_field', "can't be blank")
        self.errors.add('test', "must have a proper value")
Esempio n. 2
0
class TestErrors(object):

    def setup(self):
        self.blank_errors = Errors()

        self.errors = Errors()
        self.errors.add('test', "can't be blank")
        self.errors.add('other_field', "can't be blank")
        self.errors.add('test', "must have a proper value")

    def test_get_key_with_single_message(self):
        assert_equals(self.errors['other_field'], ["can't be blank"])

    def test_get_key_with_multiple_messages(self):
        assert_equals(
            self.errors['test'],
            ["can't be blank", "must have a proper value"]
        )

    def test_len(self):
        assert_equals(0, len(self.blank_errors))
        assert_equals(3, len(self.errors))

    def test_bool(self):
        assert_true(bool(self.errors))
        assert_false(bool(self.blank_errors))
        

    def test_messages(self):
        assert_equals(
            self.errors.messages(),
            [
                "Test can't be blank",
                "Other field can't be blank",
                "Test must have a proper value"
            ]
        )
        assert_equals(self.errors.messages('other_field'),
                      ["Other field can't be blank"])
        assert_equals(self.blank_errors.messages(), [])


    def test_api_messages(self):
        assert_equals(
            self.errors.api_messages(),
            [
                "'test' can't be blank",
                "'other_field' can't be blank",
                "'test' must have a proper value"
            ]
        )
        assert_equals(self.errors.api_messages('other_field'),
                      ["'other_field' can't be blank"])
        assert_equals(self.blank_errors.api_messages(), [])