예제 #1
0
def purge_functional_test_data(user_email_prefix):
    """
    Remove non-seeded functional test data

    users, services, etc. Give an email prefix. Probably "notify-tests-preview".
    """
    users = User.query.filter(
        User.email_address.like("{}%".format(user_email_prefix))).all()
    for usr in users:
        # Make sure the full email includes a uuid in it
        # Just in case someone decides to use a similar email address.
        try:
            uuid.UUID(usr.email_address.split("@")[0].split('+')[1])
        except ValueError:
            print(
                "Skipping {} as the user email doesn't contain a UUID.".format(
                    usr.email_address))
        else:
            services = dao_fetch_all_services_by_user(usr.id)
            if services:
                for service in services:
                    delete_service_and_all_associated_db_objects(service)
            else:
                delete_user_verify_codes(usr)
                delete_model_user(usr)
예제 #2
0
def update_user(user_id):
    try:
        user = get_model_users(user_id=user_id)
    except DataError:
        return jsonify(result="error", message="Invalid user id"), 400
    except NoResultFound:
        return jsonify(result="error", message="User not found"), 404
    if request.method == 'DELETE':
        status_code = 202
        delete_model_user(user)
    else:
        # TODO removed some validation checking by using load
        # which will need to be done in another way
        status_code = 200
        db.session.rollback()
        save_model_user(user, update_dict=request.get_json())
    return jsonify(data=user_schema.dump(user).data), status_code
예제 #3
0
def update_user(user_id):
    try:
        user = get_model_users(user_id=user_id)
    except DataError:
        return jsonify(result="error", message="Invalid user id"), 400
    except NoResultFound:
        return jsonify(result="error", message="User not found"), 404
    if request.method == 'DELETE':
        status_code = 202
        delete_model_user(user)
    else:
        # TODO removed some validation checking by using load
        # which will need to be done in another way
        status_code = 200
        db.session.rollback()
        save_model_user(user, update_dict=request.get_json())
    return jsonify(data=user_schema.dump(user).data), status_code
예제 #4
0
 def run(self, service_name_prefix=None, user_email_prefix=None):
     if user_email_prefix:
         users = User.query.filter(User.email_address.like("{}%".format(user_email_prefix))).all()
         for usr in users:
             # Make sure the full email includes a uuid in it
             # Just in case someone decides to use a similar email address.
             try:
                 uuid.UUID(usr.email_address.split("@")[0].split('+')[1])
             except ValueError:
                 print("Skipping {} as the user email doesn't contain a UUID.".format(usr.email_address))
             else:
                 services = dao_fetch_all_services_by_user(usr.id)
                 if services:
                     for service in services:
                         delete_service_and_all_associated_db_objects(service)
                 else:
                     delete_user_verify_codes(usr)
                     delete_model_user(usr)
예제 #5
0
def purge_functional_test_data(user_email_prefix):
    """
    Remove non-seeded functional test data

    users, services, etc. Give an email prefix. Probably "notify-tests-preview".
    """
    users = User.query.filter(
        User.email_address.like("{}%".format(user_email_prefix))).all()
    for usr in users:
        # Make sure the full email includes a uuid in it
        # Just in case someone decides to use a similar email address.
        try:
            uuid.UUID(usr.email_address.split("@")[0].split('+')[1])
        except ValueError:
            print(
                "Skipping {} as the user email doesn't contain a UUID.".format(
                    usr.email_address))
        else:
            services = dao_fetch_all_services_by_user(usr.id)
            if services:
                print(f"Deleting user {usr.id} which is part of services")
                for service in services:
                    delete_service_and_all_associated_db_objects(service)
            else:
                services_created_by_this_user = dao_fetch_all_services_created_by_user(
                    usr.id)
                if services_created_by_this_user:
                    # user is not part of any services but may still have been the one to create the service
                    # sometimes things get in this state if the tests fail half way through
                    # Remove the service they created (but are not a part of) so we can then remove the user
                    print(f"Deleting services created by {usr.id}")
                    for service in services_created_by_this_user:
                        delete_service_and_all_associated_db_objects(service)

                print(
                    f"Deleting user {usr.id} which is not part of any services"
                )
                delete_user_verify_codes(usr)
                delete_model_user(usr)
예제 #6
0
def test_delete_users(sample_user):
    assert User.query.count() == 1
    delete_model_user(sample_user)
    assert User.query.count() == 0
예제 #7
0
def test_delete_users(notify_api, notify_db, notify_db_session, sample_user):
    assert User.query.count() == 1
    delete_model_user(sample_user)
    assert User.query.count() == 0
예제 #8
0
def test_delete_users(notify_api, notify_db, notify_db_session, sample_user):
    assert User.query.count() == 1
    delete_model_user(sample_user)
    assert User.query.count() == 0