Skip to content

Commit

Permalink
Fix misspecified twilio tests
Browse files Browse the repository at this point in the history
Prior implementation ran `assert ...MagicMock.called_with(...)`

`called_with` is not a real test method on MagicMock, so it returns a
MagicMock instance by default, which is truthy and evaluates to true
by assert. This test wasn't checking for anything and would pass no
matter what actually happened in the code.

These new tests check for the intended methods being called.
  • Loading branch information
austinweisgrau committed Jun 3, 2024
1 parent bb3dee3 commit b5de776
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions test/test_twilio/test_twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ def test_get_messages(self):
def test_get_account_usage(self):

# Make sure that it is calling the correct Twilio methods
self.twilio.client.usage.records.today.list.assert_not_called()
self.twilio.get_account_usage(time_period="today")
assert self.twilio.client.usage.records.today.list.called_with(time_period="today")
self.twilio.client.usage.records.today.list.assert_called()

self.twilio.client.usage.records.last_month.list.assert_not_called()
self.twilio.get_account_usage(time_period="last_month")
assert self.twilio.client.usage.records.last_month.list.called_with(
time_period="last_month"
)
self.twilio.client.usage.records.last_month.list.assert_called()

self.twilio.client.usage.records.this_month.list.assert_not_called()
self.twilio.get_account_usage(time_period="this_month")
assert self.twilio.client.usage.records.this_month.list.called_with(
time_period="this_month"
)
self.twilio.client.usage.records.this_month.list.assert_called()

self.twilio.client.usage.records.yesterday.list.assert_not_called()
self.twilio.get_account_usage(time_period="yesterday")
assert self.twilio.client.usage.records.today.list.called_with(time_period="yesterday")
self.twilio.client.usage.records.yesterday.list.assert_called()

# Make sure that it is calling the correct Twilio methods
self.twilio.get_account_usage(time_period="daily", start_date="10-19-2019")
Expand Down

0 comments on commit b5de776

Please sign in to comment.