test_request.py
1.67 KB
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
from pyramid import testing
def test_create_va():
import os
from datetime import timedelta
from base64 import b64encode
from pyramid_snap.structure import (
RC_OK,
SERVICE_VA_CREATE,
)
from pyramid_snap.view import (
create_now,
time_to_str,
create_rc,
)
from winpay.signature import generator
from snap_server.views import API
private_file = os.path.join('..', 'private.pem')
with open(private_file, 'rb') as f:
private_key = f.read()
timestamp = create_now()
expired_timestamp = timestamp + timedelta(1)
timestamp_str = time_to_str(timestamp)
expired_str = time_to_str(expired_timestamp)
trx_id = '122005'
channel = 'MANDIRI'
data = {
'customerNo': '08123456789',
'virtualAccountName': 'Iwan Gunawan',
'trxId': trx_id,
'totalAmount': {
'value': 10000,
'currency': 'IDR'},
'virtualAccountTrxType': 'c',
'expiredDate': expired_str,
'additionalInfo': {'channel': channel}}
signature = generator(private_key, data, timestamp)
signature_b64 = b64encode(signature)
signature_b64 = signature_b64.decode('utf-8')
headers = {
'X-Timestamp': timestamp_str,
'X-Signature': signature_b64,
'X-Partner-Id': '1234',
'X-External-Id': trx_id,
'Channel-Id': channel}
request = testing.DummyRequest(
client_addr='127.0.0.1', method='POST', json_body=data,
headers=headers)
api = API(request)
resp = api.create_va()
assert resp.status_code == RC_OK[0]
assert resp.json_body['responseCode'] == create_rc(
RC_OK, SERVICE_VA_CREATE)