mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 18:52:30 -05:00
Add server_commands and update readme.md
Update command to search for services from the user.
This commit is contained in:
@@ -3,7 +3,10 @@ from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from flask.ext.script import Command, Manager, Option
|
||||
from app.models import (PROVIDERS, Service, User)
|
||||
from app.dao.services_dao import delete_service_and_all_associated_db_objects
|
||||
from app.dao.services_dao import (
|
||||
delete_service_and_all_associated_db_objects,
|
||||
dao_fetch_all_services_by_user
|
||||
)
|
||||
from app.dao.provider_rates_dao import create_provider_rates
|
||||
from app.dao.users_dao import (delete_model_user, delete_user_verify_codes)
|
||||
|
||||
@@ -36,22 +39,10 @@ class CreateProviderRateCommand(Command):
|
||||
class PurgeFunctionalTestDataCommand(Command):
|
||||
|
||||
option_list = (
|
||||
Option('-n', '-service-name-prefix', dest="service_name_prefix", help='Functional service name prefix.'),
|
||||
Option('-u', '-user-email-prefix', dest='user_email_prefix', help="Functional test user email prefix.")
|
||||
Option('-u', '-user-email-prefix', dest='user_email_prefix', help="Functional test user email prefix."),
|
||||
)
|
||||
|
||||
def run(self, service_name_prefix=None, user_email_prefix=None):
|
||||
if service_name_prefix:
|
||||
services = Service.query.filter(Service.name.like("{}%".format(service_name_prefix))).all()
|
||||
for service in services:
|
||||
# Make sure the second part of the service name is a uuid.
|
||||
# Just in case someone decides to create a service with that name included in it.
|
||||
try:
|
||||
uuid.UUID(service.name.split(service_name_prefix)[1])
|
||||
except ValueError:
|
||||
print("Skipping {} as the service name doesn't contain a UUID.".format(service.name))
|
||||
else:
|
||||
delete_service_and_all_associated_db_objects(service)
|
||||
if user_email_prefix:
|
||||
users = User.query.filter(User.email_address.like("{}%".format(user_email_prefix))).all()
|
||||
for usr in users:
|
||||
@@ -62,5 +53,10 @@ class PurgeFunctionalTestDataCommand(Command):
|
||||
except ValueError:
|
||||
print("Skipping {} as the user email doesn't contain a UUID.".format(usr.email_address))
|
||||
else:
|
||||
delete_user_verify_codes(usr)
|
||||
delete_model_user(usr)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user