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 update_guest_list(service_id): # doesn't commit so if there are any errors, we preserve old values in db dao_remove_service_guest_list(service_id) try: guest_list_objects = get_guest_list_objects(service_id, request.get_json()) except ValueError as e: current_app.logger.exception(e) dao_rollback() msg = '{} is not a valid email address or phone number'.format(str(e)) raise InvalidRequest(msg, 400) else: dao_add_and_commit_guest_list_contacts(guest_list_objects) return '', 204
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 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_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