Exemplo n.º 1
0
    def test_should_be_accepted_by_django(self):
        """Test that a django field really accept a ``Choices`` instance."""

        from django.db.models import IntegerField
        field = IntegerField(choices=self.MY_CHOICES, default=self.MY_CHOICES.ONE)

        self.assertEqual(field.choices, self.MY_CHOICES)

        # No errors in ``_check_choices_``, Django 1.7+
        if django.VERSION >= (1, 7):
            self.assertEqual(field._check_choices(), [])

        # Test validation
        field.validate(1, None)

        with self.assertRaises(ValidationError) as raise_context:
            field.validate(4, None)

        # Check exception code, only in Django 1.6+
        if django.VERSION >= (1, 6):
            self.assertEqual(raise_context.exception.code, 'invalid_choice')
Exemplo n.º 2
0
    def test_should_be_accepted_by_django(self):
        """Test that a django field really accept a ``Choices`` instance."""

        from django.db.models import IntegerField
        field = IntegerField(choices=self.MY_CHOICES, default=self.MY_CHOICES.ONE)

        self.assertEqual(field.choices, self.MY_CHOICES)

        # No errors in ``_check_choices_``, Django 1.7+
        if django.VERSION >= (1, 7):
            self.assertEqual(field._check_choices(), [])

        # Test validation
        field.validate(1, None)

        with self.assertRaises(ValidationError) as raise_context:
            field.validate(4, None)

        # Check exception code, only in Django 1.6+
        if django.VERSION >= (1, 6):
            self.assertEqual(raise_context.exception.code, 'invalid_choice')