Projet

Général

Profil

0001-add-minimal-and-maximal-amount-attribute-to-backends.patch

Benjamin Dauvergne, 28 septembre 2021 22:02

Télécharger (4,17 ko)

Voir les différences:

Subject: [PATCH] add minimal and maximal amount attribute to backends (#57367)

 eopayment/__init__.py      |  6 ++++++
 eopayment/payfip_ws.py     |  4 ++++
 eopayment/tipi.py          |  4 ++++
 tests/test_base_payment.py | 10 ++++++++++
 tests/test_payfip_ws.py    |  8 ++++++++
 tests/test_tipi.py         | 13 +++++++++++++
 6 files changed, 45 insertions(+)
eopayment/__init__.py
247 247
    @property
248 248
    def has_payment_status(self):
249 249
        return hasattr(self.backend, 'payment_status')
250

  
251
    def get_minimal_amount(self):
252
        return getattr(self.backend, 'minimal_amount', None)
253

  
254
    def get_maximal_amount(self):
255
        return getattr(self.backend, 'maximal_amount', None)
eopayment/payfip_ws.py
17 17
from __future__ import print_function, unicode_literals
18 18

  
19 19
import copy
20
import decimal
20 21
import datetime
21 22
import functools
22 23
import os
......
201 202

  
202 203
    min_time_between_transactions = 60 * 20  # 20 minutes
203 204

  
205
    minimal_amount = decimal.Decimal('1.0')
206
    maximal_amount = decimal.Decimal('100000.0')
207

  
204 208
    def __init__(self, *args, **kwargs):
205 209
        super(Payment, self).__init__(*args, **kwargs)
206 210
        self.payfip = PayFiP()
eopayment/tipi.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import datetime
18
import decimal
18 19
import re
19 20
import random
20 21

  
......
76 77

  
77 78
    REFDET_RE = re.compile('^[a-zA-Z0-9]{6,30}$')
78 79

  
80
    minimal_amount = decimal.Decimal('1.0')
81
    maximal_amount = decimal.Decimal('100000.0')
82

  
79 83
    def _generate_refdet(self):
80 84
        return '%s%010d' % (datetime.datetime.now(pytz.timezone('Europe/Paris')).strftime('%Y%m%d%H%M%S'),
81 85
                            random.randint(1, 1000000000))
tests/test_base_payment.py
118 118
def test_get_min_time_between_transaction(monkeypatch):
119 119
    _, payment = do_mock_backend(monkeypatch)
120 120
    assert payment.get_min_time_between_transactions() == 0
121

  
122

  
123
def test_get_minimal_amount(monkeypatch):
124
    _, payment = do_mock_backend(monkeypatch)
125
    assert payment.get_minimal_amount() is None
126

  
127

  
128
def test_get_maximal_amount(monkeypatch):
129
    _, payment = do_mock_backend(monkeypatch)
130
    assert payment.get_maximal_amount() is None
tests/test_payfip_ws.py
484 484

  
485 485
def test_get_min_time_between_transactions(backend):
486 486
    assert backend.get_min_time_between_transactions() == 20 * 60
487

  
488

  
489
def test_get_minimal_amount(backend):
490
    assert backend.get_minimal_amount() is not None
491

  
492

  
493
def test_get_maximal_amount(backend):
494
    assert backend.get_maximal_amount() is not None
tests/test_tipi.py
115 115
    assert parsed_qs['refdet'][0].startswith(datetime.datetime.now().strftime('%Y%m%d'))
116 116
    assert 'coucou' in parsed_qs['objet'][0]
117 117
    assert 'F12-12-12' in parsed_qs['objet'][0]
118

  
119

  
120
@pytest.fixture
121
def payment():
122
    return eopayment.Payment('tipi', {'numcli': '12345'})
123

  
124

  
125
def test_get_minimal_amount(payment):
126
    assert payment.get_minimal_amount() is not None
127

  
128

  
129
def test_get_maximal_amount(payment):
130
    assert payment.get_maximal_amount() is not None
118
-