summaryrefslogtreecommitdiffstats
path: root/tests/test_tipi.py
blob: 31a6792347fd59cc5343e7f8d26ed4b79c09984f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import datetime
from decimal import Decimal
from six.moves.urllib.parse import urlparse, parse_qs

import eopayment
import eopayment.tipi
import pytest


def test_tipi():
    p = eopayment.Payment('tipi', {'numcli': '12345'})
    payment_id, kind, url = p.request(
        amount=Decimal('123.12'),
        exer=9999,
        refdet=999900000000999999,
        objet='tout a fait',
        email='info@entrouvert.com',
        urlcl='http://example.com/tipi/test',
        saisie='T')
    assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None
    parsed_qs = parse_qs(urlparse(url).query)
    assert parsed_qs['objet'][0].startswith('tout a fait')
    assert parsed_qs['montant'] == ['12312']
    assert parsed_qs['saisie'] == ['T']
    assert parsed_qs['mel'] == ['info@entrouvert.com']
    assert parsed_qs['numcli'] == ['12345']
    assert parsed_qs['exer'] == ['9999']
    assert parsed_qs['refdet'] == ['999900000000999999']

    response = p.response(
        'objet=tout+a+fait&montant=12312&saisie=T&mel=info%40entrouvert.com'
        '&numcli=12345&exer=9999&refdet=999900000000999999&resultrans=P')
    assert response.signed  # ...
    assert response.result == eopayment.PAID

    with pytest.raises(eopayment.ResponseError, match='missing refdet or resultrans'):
        p.response('foo=bar')


def test_tipi_no_orderid_no_refdet():
    p = eopayment.Payment('tipi', {'numcli': '12345'})
    payment_id, kind, url = p.request(
        amount=Decimal('123.12'),
        exer=9999,
        email='info@entrouvert.com',
        saisie='T')
    assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None
    parsed_qs = parse_qs(urlparse(url).query)
    assert 'objet' not in parsed_qs
    assert parsed_qs['montant'] == ['12312']
    assert parsed_qs['saisie'] == ['T']
    assert parsed_qs['mel'] == ['info@entrouvert.com']
    assert parsed_qs['numcli'] == ['12345']
    assert parsed_qs['exer'] == ['9999']
    assert parsed_qs['refdet'][0].startswith(datetime.datetime.now().strftime('%Y%m%d'))


def test_tipi_orderid_refdef_compatible():
    p = eopayment.Payment('tipi', {'numcli': '12345', 'saisie': 'A'})
    payment_id, kind, url = p.request(
        amount=Decimal('123.12'),
        email='info@entrouvert.com',
        orderid='F121212')
    assert eopayment.tipi.Payment.REFDET_RE.match(payment_id)
    expected_url = urlparse(eopayment.tipi.TIPI_URL)
    parsed_url = urlparse(url)
    assert parsed_url[:3] == expected_url[:3]
    parsed_qs = parse_qs(parsed_url.query)
    assert 'objet' not in parsed_qs
    assert 'exer' not in parsed_qs
    assert parsed_qs['montant'] == ['12312']
    assert parsed_qs['saisie'] == ['A']
    assert parsed_qs['mel'] == ['info@entrouvert.com']
    assert parsed_qs['numcli'] == ['12345']
    assert parsed_qs['refdet'] == ['F121212']


def test_tipi_orderid_not_refdef_compatible():
    p = eopayment.Payment('tipi', {'numcli': '12345', 'saisie': 'A'})
    payment_id, kind, url = p.request(
        amount=Decimal('123.12'),
        email='info@entrouvert.com',
        objet='coucou',
        orderid='F12-12-12')
    assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None
    expected_url = urlparse(eopayment.tipi.TIPI_URL)
    parsed_url = urlparse(url)
    assert parsed_url[:3] == expected_url[:3]
    parsed_qs = parse_qs(parsed_url.query)
    assert 'exer' not in parsed_qs
    assert parsed_qs['montant'] == ['12312']
    assert parsed_qs['saisie'] == ['A']
    assert parsed_qs['mel'] == ['info@entrouvert.com']
    assert parsed_qs['numcli'] == ['12345']
    assert parsed_qs['refdet'][0].startswith(datetime.datetime.now().strftime('%Y%m%d'))
    assert 'coucou' in parsed_qs['objet'][0]
    assert 'F12-12-12' in parsed_qs['objet'][0]