Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
encoding=1)
data = make_epc_qr_data(**kw)
assert len(data) == 96 # See. EPC069-12 Version 2.1 dtd. 9 February 2012 example 1
encoding = 'utf-8'
d = [x.decode(encoding) for x in data.split(b'\n')]
assert 10 == len(d)
assert 'BCD' == d[0]
assert '002' == d[1]
assert '1' == d[2]
assert 'SCT' == d[3]
assert name == d[5]
assert iban == d[6]
assert 'EUR12.3' == d[7]
assert purpose == d[8]
assert reference == d[9]
qr = make_epc_qr(**kw)
assert qr
assert not qr.is_micro
assert qr.version <= 13
assert 'M' == qr.error
def test_valid_encoding(encoding):
kw = _make_valid_kw()
kw['name'] = 'Simple name'
kw['encoding'] = encoding
d = make_epc_qr_data(**kw).split(b'\n')
assert str(encoding).encode() == d[2]
qr = make_epc_qr(**kw)
assert qr
def test_illegal_purpose(purpose):
kw = _make_valid_kw()
kw['purpose'] = purpose
with pytest.raises(ValueError) as ex:
make_epc_qr_data(**kw)
assert 'purpose' in str(ex.value)
with pytest.raises(ValueError) as ex:
make_epc_qr(**kw)
assert 'purpose' in str(ex.value)
def test_illegal_name(name):
kw = _make_valid_kw()
kw['name'] = name
with pytest.raises(ValueError) as ex:
make_epc_qr_data(**kw)
assert 'name' in str(ex.value)
with pytest.raises(ValueError) as ex:
make_epc_qr(**kw)
assert 'name' in str(ex.value)
def test_no_text_no_reference(text, reference):
kw = _make_valid_kw()
kw['text'] = text
kw['reference'] = reference
with pytest.raises(ValueError) as ex:
make_epc_qr_data(**kw)
assert 'reference' in str(ex.value)
with pytest.raises(ValueError) as ex:
make_epc_qr(**kw)
assert 'reference' in str(ex.value)
def test_invalid_amount(amount):
kw = _make_valid_kw()
kw['amount'] = amount
with pytest.raises(ValueError) as ex:
make_epc_qr_data(**kw)
assert 'amount' in str(ex.value)
with pytest.raises(ValueError) as ex:
make_epc_qr(**kw)
assert 'amount' in str(ex.value)
def test_illegal_iban(iban):
kw = _make_valid_kw()
kw['iban'] = iban
with pytest.raises(ValueError) as ex:
make_epc_qr_data(**kw)
assert 'IBAN' in str(ex.value)
with pytest.raises(ValueError) as ex:
make_epc_qr(**kw)
assert 'IBAN' in str(ex.value)
def test_illegal_encoding(encoding):
kw = _make_valid_kw()
kw['encoding'] = encoding
with pytest.raises(ValueError) as ex:
make_epc_qr_data(**kw)
assert 'encoding' in str(ex.value)
with pytest.raises(ValueError) as ex:
make_epc_qr(**kw)
assert 'encoding' in str(ex.value)
def generate_qr(self):
encoding = self._encoding_cb.get() if self._encoding_cb.current() != 0 else None
return segno.helpers.make_epc_qr(name=self._name_var.get(),
iban=self._iban_var.get(),
amount=self._amount_var.get(),
text=self._text_var.get(),
reference=self._reference_var.get(),
bic=self._bic_var.get(),
purpose=self._purpose_var.get(),
encoding=encoding)