Exemple #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)
 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)
Exemple #3
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)