def handle(self, *args, **kwargs): """ Main Execution func """ print("Being sending reports") send_weather_report() print("Finished sending reports")
def test_weather_report_success_errors_handled_gracefully( self, mock_twilio): """ Assert an error with the twilio client is handled gracefully """ # Twilio Specific Exception mock_twilio.create.side_effect = TwilioException result = send_weather_report() self.assertEquals(result, 0) mock_twilio.create.side_effect = None mock_twilio.create.return_value = "Hi there, the weather will be great today!" result = send_weather_report() self.assertEquals(result, 1)
def test_weather_report_success(self, mock_twilio): """ Assert that an SMS is successfully sent to one recipient """ mock_twilio.create.return_value = "Hi there, the weather will be great today!" result = send_weather_report() self.assertEquals(result, 1)
def test_weather_report_success_no_recipients(self, mock_twilio): """ Assert no SMSes are sent if there are no recipients """ Recipient.objects.all().delete() mock_twilio.create.return_value = "Hi there, the weather will be great today!" result = send_weather_report() self.assertEquals(result, 0)
def test_weather_report_success_unsubscribed_recipients(self, mock_twilio): """ Assert multiples SMSes are successfully sent if there are two ore more recipients """ self.second_recipient = RecipientFactory(subscribed=True) mock_twilio.create.return_value = "Hi there, the weather will be great today!" result = send_weather_report() self.assertEquals(result, 1)
def test_weather_report_success_multiple_recipients(self, mock_twilio): """ Assert multiples SMSes are successfully sent if there are two ore more recipients """ self.second_recipient = RecipientFactory( phone_number=phonenumbers.parse("+61421951234", "AU"), subscribed=True) mock_twilio.create.return_value = "Hi there, the weather will be great today!" result = send_weather_report() self.assertEquals(result, 2)
def test_minimum_number_connections_weather_report(self, mock_twilio): """ Assert the number of minimum no. db connections are made for an Weather report. """ for i in range(5): postal_code = PostalCodeFactory() for j in range(10): phone_number = f"+614219555{i}{j}" RecipientFactory(postal_code=postal_code, phone_number=phonenumbers.parse( phone_number, "AU")) settings.DEBUG = True reset_queries() self.assertEqual(len(connection.queries), 0) mock_twilio.create.side_effect = None mock_twilio.create.return_value = "Hi there, the weather will be great today!" send_weather_report() self.assertEqual(len(connection.queries), 11) settings.DEBUG = False