Beispiel #1
0
    def test_name_is_required(self):
        # does not raise
        ContentType(name=self.VALID_NAME).full_clean()

        with pytest.raises(ValidationError) as excinfo:
            ContentType().full_clean()

        assert str(
            excinfo.value) == ("{'name': [u'This field cannot be blank.']}")
        assert str(excinfo.value) == str(
            {"name": [u"This field cannot be blank."]})
    def test_name_is_required(self):
        # does not raise
        ContentType(name=self.VALID_NAME).full_clean()

        with pytest.raises(ValidationError) as excinfo:
            ContentType().full_clean()

        assert excinfo.value.message_dict == {
            'name': ['This field cannot be blank.']
        }
        assert excinfo.value.message_dict == {
            "name": ["This field cannot be blank."]
        }
    def test_classmethod_get(self):
        # this is a shortener for model.objects.get() for enums
        content_type = ContentType.objects.create(name=self.VALID_NAME)

        assert ContentType.get(self.VALID_NAME_ENUM).id == content_type.id
        assert ContentType.get(self.VALID_NAME_ENUM.value).id == \
            content_type.id

        with pytest.raises(ContentType.DoesNotExist) as excinfo:
            assert ContentType.get(self.VALID_NAME_OTHER)

        assert str(
            excinfo.value) == str("ContentType matching query does not exist.")
Beispiel #4
0
    def test_name_is_limited_to_choices(self):
        # does not raise
        ContentType(name=self.VALID_NAME).full_clean()
        invald_name = 'INVALID NAME'

        assert invald_name not in constants.ContentType.choices()

        with pytest.raises(ValidationError) as excinfo:
            ContentType(name=invald_name).full_clean()

        assert str(excinfo.value) == str({
            "name": [(u"Value \'{given}\' is not a valid choice.").format(
                given=invald_name)]
        })
Beispiel #5
0
    def test_description_length_is_limited(self):
        # does not raise
        ContentType(name=self.VALID_NAME,
                    description='a' *
                    self.DESCRIPTION_MAX_LENGTH).full_clean()

        with pytest.raises(ValidationError) as excinfo:
            ContentType(name=self.VALID_NAME_OTHER,
                        description='a' *
                        (self.DESCRIPTION_MAX_LENGTH + 1)).full_clean()

        assert str(excinfo.value) == str({
            "description":
            [(u"Ensure this value has at most {valid} characters "
              "(it has {given}).").format(valid=self.DESCRIPTION_MAX_LENGTH,
                                          given=self.DESCRIPTION_MAX_LENGTH +
                                          1)]
        })
    def test_repr(self):
        # __str__ returns name, but it did not affected __repr__
        content_type = ContentType(name=self.VALID_NAME)

        assert repr(content_type) == ('<ContentType: {name}>').format(
            name=self.VALID_NAME)
    def test_convert_to_string(self):
        # __str__ will return name
        content_type = ContentType(name=self.VALID_NAME)

        assert str(content_type) == self.VALID_NAME
 def test_description_is_not_required(self):
     # does not raise
     ContentType(name=self.VALID_NAME).full_clean()