Ejemplo n.º 1
0
def test_cipc_registration_number(faker):
    """Ensure the SouthAfricaCommonProvider can generate valid CIPC registration numbers."""

    faker.add_provider(SouthAfricaCommonProvider)
    cipc_registration_number = faker.cipc_registration_number()

    assert len(cipc_registration_number) == 14
    assert is_valid_cipc_registration_number(cipc_registration_number) is True
Ejemplo n.º 2
0
    def validate(self, value: str) -> None:
        """Validate the field using the is_valid_cipc_registration_number helper function."""

        super().validate(value)  # Will raise an error if not str

        is_valid = is_valid_cipc_registration_number(value)

        if not is_valid:
            raise forms.ValidationError(self.error_messages["invalid_input"])
Ejemplo n.º 3
0
    def to_internal_value(self, value: str) -> str:
        """Validate the format of the given value."""

        value = super().to_internal_value(value)

        try:
            is_valid = is_valid_cipc_registration_number(value)
        except TypeError:
            is_valid = False

        if not is_valid:
            raise serializers.ValidationError(
                self.error_messages["invalid_input"])

        return value
Ejemplo n.º 4
0
def test_is_valid_cipc_registration_number_raises_type_error():
    """Ensure that if given a value not of type string a type error is raised."""

    with pytest.raises(TypeError):
        is_valid_cipc_registration_number(100)
Ejemplo n.º 5
0
def test_is_valid_cipc_registration_number():
    """Test the cipc company registration number validator."""

    assert is_valid_cipc_registration_number("2018/209387/07") is True
Ejemplo n.º 6
0
    def test_invalid_format(self):
        """Ensure false is returned if an invalid format is provided."""

        assert is_valid_cipc_registration_number("testingtesting") is False