0001-toulouse_axel-handle-timezone-on-transaction_date-41.patch
passerelle/contrib/toulouse_axel/models.py | ||
---|---|---|
996 | 996 | |
997 | 997 |
transaction_amount = invoice['amount'] |
998 | 998 |
transaction_id = data['transaction_id'] |
999 |
transaction_date = utils.encode_datetime(data['transaction_date']) |
|
999 |
transaction_date = utils.parse_datetime(data['transaction_date']) |
|
1000 |
if transaction_date is None: |
|
1001 |
raise APIError('invalid transaction_date') |
|
1002 |
transaction_date = utils.encode_datetime(transaction_date) |
|
1000 | 1003 |
post_data = { |
1001 | 1004 |
'IDFACTURE': int(invoice_id), |
1002 | 1005 |
'IDREGIEENCAISSEMENT': '', |
passerelle/contrib/toulouse_axel/utils.py | ||
---|---|---|
22 | 22 |
import unicodedata |
23 | 23 |
import xml.etree.ElementTree as ET |
24 | 24 | |
25 |
import pytz |
|
26 | ||
25 | 27 |
from django.utils.six import string_types |
26 | 28 | |
27 | 29 | |
... | ... | |
135 | 137 |
return obj |
136 | 138 | |
137 | 139 | |
138 |
def encode_datetime(obj):
|
|
140 |
def parse_datetime(value):
|
|
139 | 141 |
try: |
140 |
return datetime.datetime.strptime(obj, json_datetime_format).strftime(xml_datetime_format)
|
|
142 |
dt = datetime.datetime.strptime(value, json_datetime_format)
|
|
141 | 143 |
except ValueError: |
142 |
return obj |
|
144 |
return None |
|
145 |
return pytz.utc.localize(dt) |
|
146 | ||
147 | ||
148 |
def encode_datetime(dt): |
|
149 |
return dt.astimezone(pytz.timezone('Europe/Paris')).strftime(xml_datetime_format) |
|
143 | 150 | |
144 | 151 | |
145 | 152 |
def upperize(data): |
tests/test_toulouse_axel_utils.py | ||
---|---|---|
18 | 18 |
import pytest |
19 | 19 | |
20 | 20 |
from passerelle.contrib.toulouse_axel.utils import ( |
21 |
parse_datetime, |
|
21 | 22 |
encode_datetime, |
22 | 23 |
get_booking, |
23 | 24 |
get_reference_year_from_date, |
... | ... | |
26 | 27 |
) |
27 | 28 | |
28 | 29 | |
29 |
def test_encode_datetime():
|
|
30 |
def test_parse_datetime():
|
|
30 | 31 |
# wrong format |
31 |
assert encode_datetime('foo') == 'foo'
|
|
32 |
assert encode_datetime('2019-12-12') == '2019-12-12'
|
|
33 |
assert encode_datetime('2019-12-12T12:01:72') == '2019-12-12T12:01:72'
|
|
32 |
assert parse_datetime('foo') is None
|
|
33 |
assert parse_datetime('2019-12-12') is None
|
|
34 |
assert parse_datetime('2019-12-12T12:01:72') is None
|
|
34 | 35 |
# ok |
35 |
assert encode_datetime('2019-12-12T12:01:42') == '12/12/2019 12:01:42' |
|
36 |
assert parse_datetime('2019-12-12T12:01:42').isoformat() == '2019-12-12T12:01:42+00:00' |
|
37 | ||
38 | ||
39 |
def test_encode_datetime(): |
|
40 |
assert encode_datetime(parse_datetime('2019-12-12T23:40:42')) == '13/12/2019 00:40:42' |
|
36 | 41 | |
37 | 42 | |
38 | 43 |
@pytest.mark.parametrize('value, expected', [ |
39 |
- |