From e820d24cbfed0f8c3a13dff6749ae612cd2422a7 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Wed, 21 Jan 2015 11:13:13 +0100 Subject: [PATCH] Payment/PayPal: Test validate_business --- payment_paypal/tests/util_test.py | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 payment_paypal/tests/util_test.py diff --git a/payment_paypal/tests/util_test.py b/payment_paypal/tests/util_test.py new file mode 100644 index 0000000..e8feede --- /dev/null +++ b/payment_paypal/tests/util_test.py @@ -0,0 +1,39 @@ +# This file is part of Indico. +# Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN). +# +# Indico is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# Indico is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Indico; if not, see . + +import pytest +from mock import MagicMock +from wtforms import ValidationError + +from indico_payment_paypal.util import validate_business + + +@pytest.mark.parametrize(('data', 'valid'), ( + ('foobar', False), + ('foo@bar,com', False), + ('example@example.com', True), + ('X2345A789B12Cx', False), + ('X2345A789B12', False), + ('1234567890123', True), + ('X2345A789B12C', True), +)) +def test_validate_business(data, valid): + field = MagicMock(data=data) + if valid: + validate_business(None, field) + else: + with pytest.raises(ValidationError): + validate_business(None, field)