Skip to content

Commit

Permalink
Add unit tests and email to to_dict
Browse files Browse the repository at this point in the history
Incorporates PR feedback.
  • Loading branch information
kitsuta committed May 4, 2017
1 parent c9b6de5 commit 7c0d313
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 21 additions & 0 deletions uber/tests/models/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,24 @@ def test_absolute_url_error(base_url):

with pytest.raises(ValueError) as e_info:
convert_to_absolute_url('////')

class TestCharge:
def test_charge_one_email(self):
attendee = Attendee(email='test@example.com')
charge = Charge(targets=[attendee])
assert charge.email == attendee.email

def test_charge_group_leader_email(self):
attendee = Attendee(email='test@example.com')
group = Group(attendees=[attendee])
charge = Charge(targets=[group])
assert charge.email == attendee.email

def test_charge_first_email(self):
attendee = Attendee(email='test@example.com')
charge = Charge(targets=[attendee, Attendee(email='test2@example.com'), Attendee(email='test3@example.com')])
assert charge.email == attendee.email

def test_charge_no_email(self):
charge = Charge(targets=[Group()])
assert charge.email == ''
7 changes: 4 additions & 3 deletions uber/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ def _record_email_sent(email):


class Charge:
def __init__(self, targets=(), amount=None, description=None):
def __init__(self, targets=(), amount=None, description=None, email=''):
self.targets = [self.to_sessionized(m) for m in listify(targets)]

# performance optimization
self._models_cached = [self.from_sessionized(d) for d in self.targets]

self.amount = amount or self.total_cost
self.description = description or self.names
self.email = self.models[0].email if self.targets and self.models[0].email else ''
self.email = self.models[0].email if self.targets and self.models[0].email else email

@staticmethod
def to_sessionized(m):
Expand Down Expand Up @@ -256,7 +256,8 @@ def to_dict(self):
return {
'targets': self.targets,
'amount': self.amount,
'description': self.description
'description': self.description,
'email': self.email
}

@property
Expand Down

0 comments on commit 7c0d313

Please sign in to comment.