update invoice CRC checks for Python 3 (#39863)
This commit is contained in:
parent
1a9d1bac28
commit
cc7dbb17d1
|
@ -103,7 +103,7 @@ class Invoice(StorableObject):
|
|||
'f%s' % (self.formdef_id or 'x'),
|
||||
''.join([r.choice(string.digits) for x in range(5)])
|
||||
])
|
||||
crc = '%0.2d' % (ord(hashlib.md5(id).digest()[0]) % 100)
|
||||
crc = '%0.2d' % (hashlib.md5(id.encode('utf-8')).digest()[0] % 100)
|
||||
id = id + '-' + crc
|
||||
if not self.has_key(id):
|
||||
return id
|
||||
|
@ -116,7 +116,7 @@ class Invoice(StorableObject):
|
|||
|
||||
def check_crc(cls, id):
|
||||
try:
|
||||
return int(id[-2:]) == (ord(hashlib.md5(id[:-3]).digest()[0]) % 100)
|
||||
return int(id[-2:]) == (hashlib.md5(id[:-3].encode('utf-8')).digest()[0] % 100)
|
||||
except:
|
||||
return False
|
||||
check_crc = classmethod(check_crc)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import shutil
|
||||
|
||||
from quixote import cleanup
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
from auquotidien.modules import payments
|
||||
|
||||
from utilities import get_app, login, create_temporary_pub
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
|
||||
global pub
|
||||
|
||||
pub = create_temporary_pub()
|
||||
|
||||
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
|
||||
pub.set_app_dir(req)
|
||||
pub.cfg['identification'] = {'methods': ['password']}
|
||||
pub.write_cfg()
|
||||
|
||||
|
||||
def teardown_module(module):
|
||||
shutil.rmtree(pub.APP_DIR)
|
||||
|
||||
|
||||
def test_invoice_crc():
|
||||
invoice = payments.Invoice()
|
||||
for i in range(20):
|
||||
new_id = invoice.get_new_id()
|
||||
assert payments.Invoice.check_crc(new_id)
|
Reference in New Issue