def create_service_guest_list(service, email_address=None, mobile_number=None): if email_address: guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, email_address) elif mobile_number: guest_list_user = ServiceGuestList.from_string(service.id, MOBILE_TYPE, mobile_number) else: guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, '*****@*****.**') db.session.add(guest_list_user) db.session.commit() return guest_list_user
def test_remove_service_guest_list_only_removes_for_my_service( notify_db, notify_db_session): service_1 = create_service(service_name="service 1") service_2 = create_service(service_name="service 2") dao_add_and_commit_guest_list_contacts([ ServiceGuestList.from_string(service_1.id, EMAIL_TYPE, '*****@*****.**'), ServiceGuestList.from_string(service_2.id, EMAIL_TYPE, '*****@*****.**') ]) dao_remove_service_guest_list(service_1.id) assert service_1.guest_list == [] assert len(service_2.guest_list) == 1
def sample_service_guest_list(notify_db, notify_db_session): service = create_service(check_if_service_exists=True) guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, '*****@*****.**') notify_db.session.add(guest_list_user) notify_db.session.commit() return guest_list_user
def test_get_guest_list_separates_emails_and_phones(client, sample_service): dao_add_and_commit_guest_list_contacts([ ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, '*****@*****.**'), ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '07123456789'), ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '+1800-555-555'), ]) response = client.get('service/{}/guest-list'.format(sample_service.id), headers=[create_authorization_header()]) assert response.status_code == 200 json_resp = json.loads(response.get_data(as_text=True)) assert json_resp['email_addresses'] == ['*****@*****.**'] assert sorted(json_resp['phone_numbers']) == sorted( ['+1800-555-555', '07123456789'])
def test_add_and_commit_guest_list_contacts_saves_data(sample_service): guest_list = ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, '*****@*****.**') dao_add_and_commit_guest_list_contacts([guest_list]) db_contents = ServiceGuestList.query.all() assert len(db_contents) == 1 assert db_contents[0].id == guest_list.id
def get_guest_list_objects(service_id, request_json): return [ ServiceGuestList.from_string(service_id, type, recipient) for type, recipient in ( get_recipients_from_request(request_json, 'phone_numbers', MOBILE_TYPE) + get_recipients_from_request(request_json, 'email_addresses', EMAIL_TYPE) ) ]
def test_send_one_off_notification_raises_if_cant_send_to_recipient( notify_db_session, recipient, ): service = create_service(restricted=True) template = create_template(service=service) dao_add_and_commit_guest_list_contacts([ ServiceGuestList.from_string(service.id, MOBILE_TYPE, '07700900123'), ]) post_data = { 'template_id': str(template.id), 'to': recipient, 'created_by': str(service.created_by_id) } with pytest.raises(BadRequestError) as e: send_one_off_notification(service.id, post_data) assert 'service is in trial mode' in e.value.message
def test_should_not_build_service_guest_list_from_invalid_contact(recipient_type, contact): with pytest.raises(ValueError): ServiceGuestList.from_string('service_id', recipient_type, contact)
def test_should_build_service_guest_list_from_email_address(email_address): service_guest_list = ServiceGuestList.from_string('service_id', EMAIL_TYPE, email_address) assert service_guest_list.recipient == email_address
def test_should_build_service_guest_list_from_mobile_number(mobile_number): service_guest_list = ServiceGuestList.from_string('service_id', MOBILE_TYPE, mobile_number) assert service_guest_list.recipient == mobile_number