Esempio n. 1
0
    def test_only_status_eu_verified_false_specified_succeeds(
            self, values_as_data):
        """
        Test that if vat_status = eu, vat_verified = False and vat_number is not specified,
        the validation passes and vat_number is not required when vat_verified is False.

        Test both scenarios:
        - with fields on the instance (values_as_data=False)
        - with fields as values in the data param (values_as_data=True)
        """
        order_fields = {
            'vat_status': VATStatus.EU,
            'vat_number': '',
            'vat_verified': False,
        }

        order = Order(**(order_fields if not values_as_data else {}))
        data = order_fields if values_as_data else {}

        validator = VATSubValidator()

        try:
            validator(data=data, order=order)
        except Exception:
            pytest.fail('Should not raise a validator error.')
Esempio n. 2
0
    def test_only_status_eu_specified_fails(self, values_as_data):
        """
        Test that if only vat_status = eu is specified, it raises a ValidationError
        as vat_verified (true or false) has to be specified as well.

        Test both scenarios:
        - with fields on the instance (values_as_data=False)
        - with fields as values in the data param (values_as_data=True)
        """
        order_fields = {
            'vat_status': VATStatus.EU,
            'vat_number': '',
            'vat_verified': None,
        }

        order = Order(**(order_fields if not values_as_data else {}))
        data = order_fields if values_as_data else {}

        validator = VATSubValidator()

        with pytest.raises(ValidationError) as exc:
            validator(data=data, order=order)
        assert exc.value.detail == {
            'vat_verified': ['This field is required.']
        }
Esempio n. 3
0
def _validate_vat(order):
    """
    Validate that the order has all the VAT fields required.

    :raises ValidationError: if not
    """
    validator = VATSubValidator()
    validator(order=order)
    def test_only_status_non_eu_succeeds(self, values_as_data, vat_status):
        """
        Test that if vat_status != eu, the validation passes even if the other
        fields are empty.

        Test both scenarios:
        - with fields on the instance (values_as_data=False)
        - with fields as values in the data param (values_as_data=True)
        """
        order_fields = {
            'vat_status': vat_status,
            'vat_number': '',
            'vat_verified': None,
        }

        order = Order(**(order_fields if not values_as_data else {}))
        data = order_fields if values_as_data else {}

        validator = VATSubValidator()

        try:
            validator(data=data, order=order)
        except Exception:
            pytest.fail('Should not raise a validator error.')
    def test_complete_verified_eu_vat_succeeds(self, values_as_data):
        """
        Test that if vat_status = eu, vat_verified = True and vat_number is specified,
        the validation passes.

        Test both scenarios:
        - with fields on the instance (values_as_data=False)
        - with fields as values in the data param (values_as_data=True)
        """
        order_fields = {
            'vat_status': VATStatus.eu,
            'vat_number': '0123456789',
            'vat_verified': True,
        }

        order = Order(**(order_fields if not values_as_data else {}))
        data = order_fields if values_as_data else {}

        validator = VATSubValidator()

        try:
            validator(data=data, order=order)
        except Exception:
            pytest.fail('Should not raise a validator error.')