Purge functional tests command added with passing test.

Code quality fix.
This commit is contained in:
Nicholas Staples
2016-05-06 11:07:11 +01:00
parent e10728ccae
commit d40d9f76d4
9 changed files with 144 additions and 11 deletions

View File

@@ -1,8 +1,11 @@
import uuid
from datetime import datetime
from decimal import Decimal
from flask.ext.script import Command, Manager, Option
from app.models import PROVIDERS
from app.models import (PROVIDERS, Service, User)
from app.dao.services_dao import delete_service_and_all_associated_db_objects
from app.dao.provider_rates_dao import create_provider_rates
from app.dao.users_dao import (delete_model_user, delete_user_verify_codes)
class CreateProviderRateCommand(Command):
@@ -28,3 +31,36 @@ class CreateProviderRateCommand(Command):
raise Exception("Invalid valid_from date. Use the format %Y-%m-%dT%H:%M:%S")
create_provider_rates(provider_name, valid_from, cost)
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.")
)
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:
# 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:
delete_user_verify_codes(usr)
delete_model_user(usr)