14 |
14 |
# You should have received a copy of the GNU Affero General Public License
|
15 |
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 |
16 |
|
|
17 |
from six.moves.urllib.parse import urlparse, parse_qs
|
|
18 |
import datetime
|
17 |
19 |
|
18 |
20 |
import eopayment
|
19 |
21 |
import pytest
|
20 |
22 |
|
21 |
23 |
|
22 |
|
def test_dummy():
|
|
24 |
@pytest.fixture
|
|
25 |
def backend():
|
23 |
26 |
options = {
|
24 |
27 |
'direct_notification_url': 'http://example.com/direct_notification_url',
|
25 |
28 |
'siret': '1234',
|
26 |
29 |
'origin': 'Mairie de Perpette-les-oies'
|
27 |
30 |
}
|
28 |
|
p = eopayment.Payment('dummy', options)
|
|
31 |
return eopayment.Payment('dummy', options)
|
|
32 |
|
|
33 |
|
|
34 |
def test_request(backend, freezer):
|
|
35 |
freezer.move_to('2020-01-01 00:00:00+01:00')
|
|
36 |
transaction_id, method, raw_url = backend.request('10.10', capture_date=datetime.date(2020, 1, 7))
|
|
37 |
assert transaction_id
|
|
38 |
assert method == 1
|
|
39 |
url = urlparse(raw_url)
|
|
40 |
assert url.scheme == 'http'
|
|
41 |
assert url.netloc == 'dummy-payment.demo.entrouvert.com'
|
|
42 |
assert url.path == '/'
|
|
43 |
assert url.fragment == ''
|
|
44 |
qs = {k: v[0] for k, v in parse_qs(url.query).items()}
|
|
45 |
assert qs['transaction_id'] == transaction_id
|
|
46 |
assert qs['siret'] == '1234'
|
|
47 |
assert qs['amount'] == '10.10'
|
|
48 |
assert qs['origin'] == 'Mairie de Perpette-les-oies'
|
|
49 |
assert qs['capture_day'] == '6'
|
|
50 |
|
|
51 |
|
|
52 |
def test_response(backend):
|
29 |
53 |
retour = (
|
30 |
54 |
'http://example.com/retour?amount=10.0'
|
31 |
55 |
'&direct_notification_url=http%3A%2F%2Fexample.com%2Fdirect_notification_url'
|
... | ... | |
34 |
58 |
'&return_url=http%3A%2F%2Fexample.com%2Fretour'
|
35 |
59 |
'&nok=1'
|
36 |
60 |
)
|
37 |
|
r = p.response(retour.split('?', 1)[1])
|
|
61 |
r = backend.response(retour.split('?', 1)[1])
|
38 |
62 |
assert not r.signed
|
39 |
63 |
assert r.transaction_id == '6Tfw2e1bPyYnz7CedZqvdHt7T9XX6T'
|
40 |
64 |
assert r.return_content is None
|
... | ... | |
47 |
71 |
'&return_url=http%3A%2F%2Fexample.com%2Fretour'
|
48 |
72 |
'&ok=1&signed=1'
|
49 |
73 |
)
|
50 |
|
r = p.response(retour.split('?', 1)[1])
|
|
74 |
r = backend.response(retour.split('?', 1)[1])
|
51 |
75 |
assert r.signed
|
52 |
76 |
assert r.transaction_id == '6Tfw2e1bPyYnz7CedZqvdHt7T9XX6T'
|
53 |
77 |
assert r.return_content == 'signature ok'
|
54 |
78 |
|
55 |
79 |
with pytest.raises(eopayment.ResponseError, match='missing transaction_id'):
|
56 |
|
p.response('foo=bar')
|
|
80 |
backend.response('foo=bar')
|
57 |
|
-
|