Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix currency field. #50

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions passbook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DateField(Field):

def __init__(self, key, value, label='', dateStyle=DateStyle.SHORT,
timeStyle=DateStyle.SHORT, ignoresTimeZone=False):
super(DateField, self).__init__(key, value, label)
super().__init__(key, value, label)
self.dateStyle = dateStyle # Style of date to display
self.timeStyle = timeStyle # Style of time to display
self.isRelative = False # If true, the labels value is displayed as a relative date
Expand All @@ -80,17 +80,17 @@ def json_dict(self):
class NumberField(Field):

def __init__(self, key, value, label=''):
super(NumberField, self).__init__(key, value, label)
super().__init__(key, value, label)
self.numberStyle = NumberStyle.DECIMAL # Style of date to display

def json_dict(self):
return self.__dict__


class CurrencyField(NumberField):
class CurrencyField(Field):

def __init__(self, key, value, label='', currencyCode=''):
super(CurrencyField, self).__init__(key, value, label)
super().__init__(key, value, label)
self.currencyCode = currencyCode # ISO 4217 currency code

def json_dict(self):
Expand Down Expand Up @@ -194,41 +194,41 @@ def json_dict(self):
class BoardingPass(PassInformation):

def __init__(self, transitType=TransitType.AIR):
super(BoardingPass, self).__init__()
super().__init__()
self.transitType = transitType
self.jsonname = 'boardingPass'

def json_dict(self):
d = super(BoardingPass, self).json_dict()
d = super().json_dict()
d.update({'transitType': self.transitType})
return d


class Coupon(PassInformation):

def __init__(self):
super(Coupon, self).__init__()
super().__init__()
self.jsonname = 'coupon'


class EventTicket(PassInformation):

def __init__(self):
super(EventTicket, self).__init__()
super().__init__()
self.jsonname = 'eventTicket'


class Generic(PassInformation):

def __init__(self):
super(Generic, self).__init__()
super().__init__()
self.jsonname = 'generic'


class StoreCard(PassInformation):

def __init__(self):
super(StoreCard, self).__init__()
super().__init__()
self.jsonname = 'storeCard'


Expand Down
18 changes: 17 additions & 1 deletion passbook/test/test_passbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from M2Crypto import X509
from path import Path

from passbook.models import Barcode, BarcodeFormat, Pass, StoreCard
from passbook.models import Barcode, BarcodeFormat, CurrencyField, Pass, StoreCard

cwd = Path(__file__).parent

Expand Down Expand Up @@ -198,3 +198,19 @@ def test_passbook_creation():
passfile = create_shell_pass()
passfile.addFile('icon.png', open(cwd / 'static' / 'white_square.png', 'rb'))
passfile.create(certificate, key, wwdr_certificate, password)


def test_currency_field_has_no_numberstyle():
balance_field = CurrencyField(
'balance',
float(22.00),
'test label',
'USD',
)

passfile = create_shell_pass()
passfile.passInformation.headerFields.append(balance_field)

pass_json = passfile.json_dict()
assert 'currencyCode' in pass_json['storeCard']['headerFields'][0]
assert 'numberStyle' not in pass_json['storeCard']['headerFields'][0]