コード例 #1
0
ファイル: test_unique.py プロジェクト: 101studio/django
    def test_unique_for_date_with_nullable_date(self):
        p1 = FlexibleDatePost.objects.create(title="Django 1.0 is released",
            slug="Django 1.0", subtitle="Finally", posted=datetime.date(2008, 9, 3))

        p = FlexibleDatePost(title="Django 1.0 is released")
        try:
            p.full_clean()
        except ValidationError, e:
            self.fail("unique_for_date checks shouldn't trigger when the associated DateField is None.")
コード例 #2
0
    def test_unique_for_date_with_nullable_date(self):
        p1 = FlexibleDatePost.objects.create(title="Django 1.0 is released",
            slug="Django 1.0", subtitle="Finally", posted=datetime.date(2008, 9, 3))

        p = FlexibleDatePost(title="Django 1.0 is released")
        try:
            p.full_clean()
        except ValidationError, e:
            self.fail("unique_for_date checks shouldn't trigger when the associated DateField is None.")
コード例 #3
0
ファイル: test_unique.py プロジェクト: 101studio/django
        p = FlexibleDatePost(title="Django 1.0 is released")
        try:
            p.full_clean()
        except ValidationError, e:
            self.fail("unique_for_date checks shouldn't trigger when the associated DateField is None.")

        p = FlexibleDatePost(slug="Django 1.0")
        try:
            p.full_clean()
        except ValidationError, e:
            self.fail("unique_for_year checks shouldn't trigger when the associated DateField is None.")

        p = FlexibleDatePost(subtitle="Finally")
        try:
            p.full_clean()
        except ValidationError, e:
            self.fail("unique_for_month checks shouldn't trigger when the associated DateField is None.")

    def test_unique_errors(self):
        m1 = UniqueErrorsModel.objects.create(name='Some Name', number=10)
        m = UniqueErrorsModel(name='Some Name', number=11)
        with self.assertRaises(ValidationError) as cm:
            m.full_clean()
        self.assertEqual(cm.exception.message_dict, {'name': [u'Custom unique name message.']})

        m = UniqueErrorsModel(name='Some Other Name', number=10)
        with self.assertRaises(ValidationError) as cm:
            m.full_clean()
        self.assertEqual(cm.exception.message_dict, {'number': [u'Custom unique number message.']})
コード例 #4
0
ファイル: test_unique.py プロジェクト: lemuelf/django-1
        except ValidationError, e:
            self.fail(
                "unique_for_date checks shouldn't trigger when the associated DateField is None."
            )

        p = FlexibleDatePost(slug="Django 1.0")
        try:
            p.full_clean()
        except ValidationError, e:
            self.fail(
                "unique_for_year checks shouldn't trigger when the associated DateField is None."
            )

        p = FlexibleDatePost(subtitle="Finally")
        try:
            p.full_clean()
        except ValidationError, e:
            self.fail(
                "unique_for_month checks shouldn't trigger when the associated DateField is None."
            )

    def test_unique_errors(self):
        m1 = UniqueErrorsModel.objects.create(name='Some Name', number=10)
        m = UniqueErrorsModel(name='Some Name', number=11)
        with self.assertRaises(ValidationError) as cm:
            m.full_clean()
        self.assertEqual(cm.exception.message_dict,
                         {'name': [u'Custom unique name message.']})

        m = UniqueErrorsModel(name='Some Other Name', number=10)
        with self.assertRaises(ValidationError) as cm: