def request_availability_about_apartments(search, search_specific_email_message_request, _email_service=email_service): #only get results that have not gotten a response back yet. This is in case we re-email our contacts because we # haven't gotten enough responses. We don't want to re-contact those who've already responded. results_to_request_notification = ( Result .objects .find_results_from_search(search) .filter(availability_last_response_date=None) ) email_builder = AvailabilityEmailBuilder() for r in results_to_request_notification: try: message = email_builder.get_availability_email_message(r, search_specific_email_message_request) except: logger.exception("Error creating email message") else: try: _email_service.send_email( message.from_address, message.from_name, message.to_address, message.subject, message.body, r ) except: logger.exception("Error sending email message")
def test_email_service_creates_contact_name(input_contact_name, expected_contact_name): mock_listing = MagicMock(spec=Listing) mock_listing.contact_name = input_contact_name builder = AvailabilityEmailBuilder() builder.listing = mock_listing assert expected_contact_name == builder._get_contact_name()