diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 57868a070..5b67e3b3c 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -70,7 +70,7 @@ def delete_verify_codes(): def delete_successful_notifications(): try: start = datetime.utcnow() - deleted = delete_notifications_created_more_than_a_week_ago('sent') + deleted = delete_notifications_created_more_than_a_week_ago('sending') current_app.logger.info( "Delete job started {} finished {} deleted {} successful notifications".format( start, @@ -129,12 +129,13 @@ def process_job(job_id): if stats: total_sent = stats.emails_requested + stats.sms_requested - if total_sent + job.notification_count > service.limit: + if total_sent + job.notification_count > service.message_limit: job.status = 'sending limits exceeded' job.processing_finished = datetime.utcnow() dao_update_job(job) current_app.logger.info( - "Job {} size {} error. Sending limits {} exceeded".format(job_id, job.notification_count, service.limit) + "Job {} size {} error. Sending limits {} exceeded".format( + job_id, job.notification_count, service.message_limit) ) return @@ -152,7 +153,7 @@ def process_job(job_id): ).recipients_and_personalisation: encrypted = encryption.encrypt({ - 'template': template.id, + 'template': str(template.id), 'job': str(job.id), 'to': recipient, 'personalisation': personalisation @@ -217,7 +218,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at): to=notification['to'], service_id=service_id, job_id=notification.get('job', None), - status='failed' if restricted else 'sent', + status='failed' if restricted else 'sending', created_at=datetime.strptime(created_at, DATETIME_FORMAT), sent_at=sent_at, sent_by=client.get_name() @@ -277,7 +278,7 @@ def send_email(service_id, notification_id, subject, from_address, encrypted_not to=notification['to'], service_id=service_id, job_id=notification.get('job', None), - status='failed' if restricted else 'sent', + status='failed' if restricted else 'sending', created_at=datetime.strptime(created_at, DATETIME_FORMAT), sent_at=sent_at, sent_by=client.get_name() diff --git a/app/clients/email/aws_ses.py b/app/clients/email/aws_ses.py index ae50a42c1..ce139ceff 100644 --- a/app/clients/email/aws_ses.py +++ b/app/clients/email/aws_ses.py @@ -8,7 +8,7 @@ ses_response_map = { 'Bounce': { "message": 'Bounced', "success": False, - "notification_status": 'bounce', + "notification_status": 'failed', "notification_statistics_status": STATISTICS_FAILURE }, 'Delivery': { @@ -19,9 +19,9 @@ ses_response_map = { }, 'Complaint': { "message": 'Complaint', - "success": False, - "notification_status": 'complaint', - "notification_statistics_status": STATISTICS_FAILURE + "success": True, + "notification_status": 'delivered', + "notification_statistics_status": STATISTICS_DELIVERED } } diff --git a/app/clients/sms/firetext.py b/app/clients/sms/firetext.py index f0cb10c6f..7c49848b4 100644 --- a/app/clients/sms/firetext.py +++ b/app/clients/sms/firetext.py @@ -25,9 +25,9 @@ firetext_responses = { }, '2': { "message": 'Undelivered (Pending with Network)', - "success": False, - "notification_statistics_status": None, - "notification_status": 'sent' + "success": True, + "notification_statistics_status": STATISTICS_DELIVERED, + "notification_status": 'delivered' } } diff --git a/app/clients/sms/twilio.py b/app/clients/sms/twilio.py index 085fe96cd..d030cbdf5 100644 --- a/app/clients/sms/twilio.py +++ b/app/clients/sms/twilio.py @@ -44,8 +44,10 @@ class TwilioClient(SmsClient): def status(self, message_id): try: response = self.client.messages.get(message_id) - if response.status in ('delivered', 'undelivered', 'failed'): + if response.status in ('delivered', 'failed'): return response.status + elif response.status == 'undelivered': + return 'sending' return None except TwilioRestException as e: current_app.logger.exception(e) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index b1c7fface..9fbb8bf3e 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -112,12 +112,12 @@ def update_query(notification_type, status): TEMPLATE_TYPE_SMS: { STATISTICS_REQUESTED: NotificationStatistics.sms_requested, STATISTICS_DELIVERED: NotificationStatistics.sms_delivered, - STATISTICS_FAILURE: NotificationStatistics.sms_error + STATISTICS_FAILURE: NotificationStatistics.sms_failed }, TEMPLATE_TYPE_EMAIL: { STATISTICS_REQUESTED: NotificationStatistics.emails_requested, STATISTICS_DELIVERED: NotificationStatistics.emails_delivered, - STATISTICS_FAILURE: NotificationStatistics.emails_error + STATISTICS_FAILURE: NotificationStatistics.emails_failed } } return { diff --git a/app/models.py b/app/models.py index c41cbac97..583e4c6dc 100644 --- a/app/models.py +++ b/app/models.py @@ -1,7 +1,7 @@ import uuid import datetime -from sqlalchemy import UniqueConstraint, Sequence +from sqlalchemy import UniqueConstraint, Sequence, CheckConstraint from . import db from sqlalchemy.dialects.postgresql import ( @@ -24,7 +24,7 @@ def filter_null_value_fields(obj): class User(db.Model): __tablename__ = 'users' - id = db.Column(db.Integer, primary_key=True) + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) name = db.Column(db.String, nullable=False, index=True, unique=False) email_address = db.Column(db.String(255), nullable=False, index=True, unique=True) created_at = db.Column( @@ -62,7 +62,7 @@ class User(db.Model): user_to_service = db.Table( 'user_to_service', db.Model.metadata, - db.Column('user_id', db.Integer, db.ForeignKey('users.id')), + db.Column('user_id', UUID(as_uuid=True), db.ForeignKey('users.id')), db.Column('service_id', UUID(as_uuid=True), db.ForeignKey('services.id')), UniqueConstraint('user_id', 'service_id', name='uix_user_to_service') @@ -74,7 +74,6 @@ class Service(db.Model): __tablename__ = 'services' id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) - old_id = db.Column(db.Integer, Sequence('services_id_seq'), nullable=False) name = db.Column(db.String(255), nullable=False, unique=True) created_at = db.Column( db.DateTime, @@ -89,7 +88,7 @@ class Service(db.Model): nullable=True, onupdate=datetime.datetime.now) active = db.Column(db.Boolean, index=False, unique=False, nullable=False) - limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False) + message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False) users = db.relationship( 'User', secondary=user_to_service, @@ -99,9 +98,9 @@ class Service(db.Model): class ApiKey(db.Model): - __tablename__ = 'api_key' + __tablename__ = 'api_keys' - id = db.Column(db.Integer, primary_key=True) + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) name = db.Column(db.String(255), nullable=False) secret = db.Column(db.String(255), unique=True, nullable=False) service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False) @@ -116,16 +115,16 @@ class ApiKey(db.Model): class NotificationStatistics(db.Model): __tablename__ = 'notification_statistics' - id = db.Column(db.Integer, primary_key=True) + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) day = db.Column(db.String(255), nullable=False) service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False) service = db.relationship('Service', backref=db.backref('service_notification_stats', lazy='dynamic')) emails_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) emails_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) - emails_error = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) + emails_failed = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) sms_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) sms_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) - sms_error = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) + sms_failed = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0) __table_args__ = ( UniqueConstraint('service_id', 'day', name='uix_service_to_day'), @@ -142,7 +141,7 @@ TEMPLATE_TYPES = [TEMPLATE_TYPE_SMS, TEMPLATE_TYPE_EMAIL, TEMPLATE_TYPE_LETTER] class Template(db.Model): __tablename__ = 'templates' - id = db.Column(db.Integer, primary_key=True) + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) name = db.Column(db.String(255), nullable=False) template_type = db.Column(db.Enum(*TEMPLATE_TYPES, name='template_type'), nullable=False) created_at = db.Column( @@ -173,7 +172,7 @@ class Job(db.Model): original_file_name = db.Column(db.String, nullable=False) service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False, nullable=False) service = db.relationship('Service', backref=db.backref('jobs', lazy='dynamic')) - template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False) + template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, unique=False) template = db.relationship('Template', backref=db.backref('jobs', lazy='dynamic')) created_at = db.Column( db.DateTime, @@ -208,8 +207,8 @@ VERIFY_CODE_TYPES = ['email', 'sms'] class VerifyCode(db.Model): __tablename__ = 'verify_codes' - id = db.Column(db.Integer, primary_key=True) - user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True, nullable=False) + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + user_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False) user = db.relationship('User', backref=db.backref('verify_codes', lazy='dynamic')) _code = db.Column(db.String, nullable=False) code_type = db.Column(db.Enum(*VERIFY_CODE_TYPES, name='verify_code_types'), @@ -235,7 +234,7 @@ class VerifyCode(db.Model): return check_hash(cde, self._code) -NOTIFICATION_STATUS_TYPES = ['sent', 'delivered', 'failed', 'complaint', 'bounce'] +NOTIFICATION_STATUS_TYPES = ['sending', 'delivered', 'failed'] class Notification(db.Model): @@ -248,7 +247,7 @@ class Notification(db.Model): job = db.relationship('Job', backref=db.backref('notifications', lazy='dynamic')) service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False) service = db.relationship('Service') - template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False) + template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, unique=False) template = db.relationship('Template') created_at = db.Column( db.DateTime, @@ -268,7 +267,7 @@ class Notification(db.Model): nullable=True, onupdate=datetime.datetime.utcnow) status = db.Column( - db.Enum(*NOTIFICATION_STATUS_TYPES, name='notification_status_types'), nullable=False, default='sent') + db.Enum(*NOTIFICATION_STATUS_TYPES, name='notification_status_types'), nullable=False, default='sending') reference = db.Column(db.String, nullable=True, index=True) @@ -281,7 +280,7 @@ class InvitedUser(db.Model): id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) email_address = db.Column(db.String(255), nullable=False) - user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True, nullable=False) + user_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False) from_user = db.relationship('User') service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False) service = db.relationship('Service') @@ -332,7 +331,7 @@ class Permission(db.Model): # Service id is optional, if the service is omitted we will assume the permission is not service specific. service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False, nullable=True) service = db.relationship('Service') - user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True, nullable=False) + user_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False) user = db.relationship('User') permission = db.Column( db.Enum(*PERMISSION_LIST, name='permission_types'), @@ -356,7 +355,7 @@ class TemplateStatistics(db.Model): id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False, nullable=False) service = db.relationship('Service', backref=db.backref('template_statistics', lazy='dynamic')) - template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, nullable=False, unique=False) + template_id = db.Column(UUID(as_uuid=True), db.ForeignKey('templates.id'), index=True, nullable=False, unique=False) template = db.relationship('Template') usage_count = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=1) day = db.Column(db.Date, index=True, nullable=False, unique=False, default=datetime.date.today) diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 5c4b3121e..25fca0d78 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -195,6 +195,7 @@ def get_all_notifications(): api_user['client'], filter_dict=data, page=page) + return jsonify( notifications=notification_status_schema.dump(pagination.items, many=True).data, links=pagination_links( @@ -286,8 +287,9 @@ def send_notification(notification_type): total_sms_count = service_stats.sms_requested total_email_count = service_stats.emails_requested - if (total_email_count + total_sms_count >= service.limit) and service.restricted: - return jsonify(result="error", message='Exceeded send limits ({}) for today'.format(service.limit)), 429 + if (total_email_count + total_sms_count >= service.message_limit) and service.restricted: + return jsonify(result="error", message='Exceeded send limits ({}) for today'.format( + service.message_limit)), 429 notification, errors = ( sms_template_notification_schema if notification_type == 'sms' else email_notification_schema diff --git a/app/schemas.py b/app/schemas.py index 0f440a771..fce025b95 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -91,12 +91,23 @@ class NotificationModelSchema(BaseSchema): model = models.Notification -class TemplateSchema(BaseSchema): +class BaseTemplateSchema(BaseSchema): class Meta: model = models.Template exclude = ("updated_at", "created_at", "service_id", "jobs") +class TemplateSchema(BaseTemplateSchema): + + @validates_schema + def validate_type(self, data): + template_type = data.get('template_type') + if template_type and template_type == 'email': + subject = data.get('subject') + if not subject or subject.strip() == '': + raise ValidationError('Invalid template subject', 'subject') + + class NotificationsStatisticsSchema(BaseSchema): class Meta: model = models.NotificationStatistics @@ -140,7 +151,7 @@ class SmsNotificationSchema(NotificationSchema): class EmailNotificationSchema(NotificationSchema): to = fields.Str(required=True) - template = fields.Int(required=True) + template = fields.Str(required=True) @validates('to') def validate_to(self, value): @@ -151,17 +162,17 @@ class EmailNotificationSchema(NotificationSchema): class SmsTemplateNotificationSchema(SmsNotificationSchema): - template = fields.Int(required=True) + template = fields.Str(required=True) job = fields.String() class JobSmsTemplateNotificationSchema(SmsNotificationSchema): - template = fields.Int(required=True) + template = fields.Str(required=True) job = fields.String(required=True) class JobEmailTemplateNotificationSchema(EmailNotificationSchema): - template = fields.Int(required=True) + template = fields.Str(required=True) job = fields.String(required=True) @@ -220,8 +231,8 @@ class EmailDataSchema(ma.Schema): class NotificationsFilterSchema(ma.Schema): - template_type = fields.Nested(TemplateSchema, only='template_type', many=True) - status = fields.Nested(NotificationModelSchema, only='status', many=True) + template_type = fields.Nested(BaseTemplateSchema, only=['template_type'], many=True) + status = fields.Nested(NotificationModelSchema, only=['status'], many=True) page = fields.Int(required=False) @pre_load diff --git a/app/service/rest.py b/app/service/rest.py index b396317d9..ae643ac3f 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -108,7 +108,7 @@ def renew_api_key(service_id=None): return jsonify(data=unsigned_api_key), 201 -@service.route('//api-key/revoke/', methods=['POST']) +@service.route('//api-key/revoke/', methods=['POST']) def revoke_api_key(service_id, api_key_id): service_api_key = get_model_api_keys(service_id=service_id, id=api_key_id) @@ -117,7 +117,7 @@ def revoke_api_key(service_id, api_key_id): @service.route('//api-keys', methods=['GET']) -@service.route('//api-keys/', methods=['GET']) +@service.route('//api-keys/', methods=['GET']) def get_api_keys(service_id, key_id=None): dao_fetch_service_by_id(service_id=service_id) diff --git a/app/template/rest.py b/app/template/rest.py index 5c5f6f271..15a4bcd51 100644 --- a/app/template/rest.py +++ b/app/template/rest.py @@ -47,7 +47,7 @@ def create_template(service_id): return jsonify(data=template_schema.dump(new_template).data), 201 -@template.route('/', methods=['POST']) +@template.route('/', methods=['POST']) def update_template(service_id, template_id): fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id) @@ -70,7 +70,7 @@ def get_all_templates_for_service(service_id): return jsonify(data=data) -@template.route('/', methods=['GET']) +@template.route('/', methods=['GET']) def get_template_by_id_and_service_id(service_id, template_id): fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id) data, errors = template_schema.dump(fetched_template) diff --git a/app/user/rest.py b/app/user/rest.py index fec2ca31b..21440ed5b 100644 --- a/app/user/rest.py +++ b/app/user/rest.py @@ -51,7 +51,7 @@ def create_user(): return jsonify(data=user_schema.dump(user_to_create).data), 201 -@user.route('/', methods=['PUT']) +@user.route('/', methods=['PUT']) def update_user(user_id): user_to_update = get_model_users(user_id=user_id) req_json = request.get_json() @@ -68,7 +68,7 @@ def update_user(user_id): return jsonify(data=user_schema.dump(user_to_update).data), status_code -@user.route('//verify/password', methods=['POST']) +@user.route('//verify/password', methods=['POST']) def verify_user_password(user_id): user_to_verify = get_model_users(user_id=user_id) @@ -89,7 +89,7 @@ def verify_user_password(user_id): return jsonify(result='error', message={'password': ['Incorrect password']}), 400 -@user.route('//verify/code', methods=['POST']) +@user.route('//verify/code', methods=['POST']) def verify_user_code(user_id): user_to_verify = get_model_users(user_id=user_id) @@ -116,7 +116,7 @@ def verify_user_code(user_id): return jsonify({}), 204 -@user.route('//sms-code', methods=['POST']) +@user.route('//sms-code', methods=['POST']) def send_user_sms_code(user_id): user_to_send_to = get_model_users(user_id=user_id) verify_code, errors = request_verify_code_schema.load(request.get_json()) @@ -135,7 +135,7 @@ def send_user_sms_code(user_id): return jsonify({}), 204 -@user.route('//email-code', methods=['POST']) +@user.route('//email-code', methods=['POST']) def send_user_email_code(user_id): user_to_send_to = get_model_users(user_id=user_id) verify_code, errors = request_verify_code_schema.load(request.get_json()) @@ -154,7 +154,7 @@ def send_user_email_code(user_id): return jsonify({}), 204 -@user.route('//email-verification', methods=['POST']) +@user.route('//email-verification', methods=['POST']) def send_user_email_verification(user_id): user_to_send_to = get_model_users(user_id=user_id) verify_code, errors = request_verify_code_schema.load(request.get_json()) @@ -176,7 +176,7 @@ def send_user_email_verification(user_id): return jsonify({}), 204 -@user.route('/', methods=['GET']) +@user.route('/', methods=['GET']) @user.route('', methods=['GET']) def get_user(user_id=None): users = get_model_users(user_id=user_id) @@ -184,7 +184,7 @@ def get_user(user_id=None): return jsonify(data=result.data) -@user.route('//service//permission', methods=['POST']) +@user.route('//service//permission', methods=['POST']) def set_permissions(user_id, service_id): # TODO fix security hole, how do we verify that the user # who is making this request has permission to make the request. @@ -240,7 +240,7 @@ def _create_reset_password_url(email): def _create_verification_url(user, secret_code): from utils.url_safe_token import generate_token import json - data = json.dumps({'user_id': user.id, 'email': user.email_address, 'secret_code': secret_code}) + data = json.dumps({'user_id': str(user.id), 'email': user.email_address, 'secret_code': secret_code}) token = generate_token(data, current_app.config['SECRET_KEY'], current_app.config['DANGEROUS_SALT']) return current_app.config['ADMIN_BASE_URL'] + '/verify-email/' + token diff --git a/migrations/versions/0001_initialise_data.py b/migrations/versions/0001_initialise_data.py deleted file mode 100644 index a1f5ab250..000000000 --- a/migrations/versions/0001_initialise_data.py +++ /dev/null @@ -1,52 +0,0 @@ -"""empty message - -Revision ID: 0001_initialise_data -Revises: None -Create Date: 2016-01-12 09:33:29.249042 - -""" - -# revision identifiers, used by Alembic. -revision = '0001_initialise_data' -down_revision = None - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('services', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.Column('active', sa.Boolean(), nullable=False), - sa.Column('limit', sa.BigInteger(), nullable=False), - sa.Column('restricted', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('users', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('email_address', sa.String(length=255), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_users_email_address'), 'users', ['email_address'], unique=True) - op.create_table('user_to_service', - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('service_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ) - ) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_table('user_to_service') - op.drop_index(op.f('ix_users_email_address'), table_name='users') - op.drop_table('users') - op.drop_table('services') - ### end Alembic commands ### diff --git a/migrations/versions/0001_restart_migrations.py b/migrations/versions/0001_restart_migrations.py new file mode 100644 index 000000000..02da0c524 --- /dev/null +++ b/migrations/versions/0001_restart_migrations.py @@ -0,0 +1,225 @@ +"""empty message + +Revision ID: 0001_restart_migrations +Revises: None +Create Date: 2016-04-07 17:22:12.147542 + +""" + +# revision identifiers, used by Alembic. +revision = '0001_restart_migrations' +down_revision = None + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.create_table('services', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('active', sa.Boolean(), nullable=False), + sa.Column('message_limit', sa.BigInteger(), nullable=False), + sa.Column('restricted', sa.Boolean(), nullable=False), + sa.Column('email_from', sa.Text(), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('email_from'), + sa.UniqueConstraint('name') + ) + op.create_table('users', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('name', sa.String(), nullable=False), + sa.Column('email_address', sa.String(length=255), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('_password', sa.String(), nullable=False), + sa.Column('mobile_number', sa.String(), nullable=False), + sa.Column('password_changed_at', sa.DateTime(), nullable=True), + sa.Column('logged_in_at', sa.DateTime(), nullable=True), + sa.Column('failed_login_count', sa.Integer(), nullable=False), + sa.Column('state', sa.String(), nullable=False), + sa.Column('platform_admin', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_users_email_address'), 'users', ['email_address'], unique=True) + op.create_index(op.f('ix_users_name'), 'users', ['name'], unique=False) + op.create_table('api_keys', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('secret', sa.String(length=255), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('expiry_date', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('secret'), + sa.UniqueConstraint('service_id', 'name', name='uix_service_to_key_name') + ) + op.create_index(op.f('ix_api_keys_service_id'), 'api_keys', ['service_id'], unique=False) + op.create_table('invited_users', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('email_address', sa.String(length=255), nullable=False), + sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('status', sa.Enum('pending', 'accepted', 'cancelled', name='invited_users_status_types'), nullable=False), + sa.Column('permissions', sa.String(), nullable=False), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_invited_users_service_id'), 'invited_users', ['service_id'], unique=False) + op.create_index(op.f('ix_invited_users_user_id'), 'invited_users', ['user_id'], unique=False) + op.create_table('notification_statistics', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('day', sa.String(length=255), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('emails_requested', sa.BigInteger(), nullable=False), + sa.Column('emails_delivered', sa.BigInteger(), nullable=False), + sa.Column('emails_failed', sa.BigInteger(), nullable=False), + sa.Column('sms_requested', sa.BigInteger(), nullable=False), + sa.Column('sms_delivered', sa.BigInteger(), nullable=False), + sa.Column('sms_failed', sa.BigInteger(), nullable=False), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('service_id', 'day', name='uix_service_to_day') + ) + op.create_index(op.f('ix_notification_statistics_service_id'), 'notification_statistics', ['service_id'], unique=False) + op.create_table('permissions', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('permission', sa.Enum('manage_users', 'manage_templates', 'manage_settings', 'send_texts', 'send_emails', 'send_letters', 'manage_api_keys', 'platform_admin', 'view_activity', name='permission_types'), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('service_id', 'user_id', 'permission', name='uix_service_user_permission') + ) + op.create_index(op.f('ix_permissions_service_id'), 'permissions', ['service_id'], unique=False) + op.create_index(op.f('ix_permissions_user_id'), 'permissions', ['user_id'], unique=False) + op.create_table('templates', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('template_type', sa.Enum('sms', 'email', 'letter', name='template_type'), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('content', sa.Text(), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('subject', sa.Text(), nullable=True), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('subject') + ) + op.create_index(op.f('ix_templates_service_id'), 'templates', ['service_id'], unique=False) + op.create_table('user_to_service', + sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.UniqueConstraint('user_id', 'service_id', name='uix_user_to_service') + ) + op.create_table('verify_codes', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('_code', sa.String(), nullable=False), + sa.Column('code_type', sa.Enum('email', 'sms', name='verify_code_types'), nullable=False), + sa.Column('expiry_datetime', sa.DateTime(), nullable=False), + sa.Column('code_used', sa.Boolean(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_verify_codes_user_id'), 'verify_codes', ['user_id'], unique=False) + op.create_table('jobs', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('original_file_name', sa.String(), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('status', sa.Enum('pending', 'in progress', 'finished', 'sending limits exceeded', name='job_status_types'), nullable=False), + sa.Column('notification_count', sa.Integer(), nullable=False), + sa.Column('notifications_sent', sa.Integer(), nullable=False), + sa.Column('processing_started', sa.DateTime(), nullable=True), + sa.Column('processing_finished', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_jobs_service_id'), 'jobs', ['service_id'], unique=False) + op.create_index(op.f('ix_jobs_template_id'), 'jobs', ['template_id'], unique=False) + op.create_table('template_statistics', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('usage_count', sa.BigInteger(), nullable=False), + sa.Column('day', sa.Date(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_template_statistics_day'), 'template_statistics', ['day'], unique=False) + op.create_index(op.f('ix_template_statistics_service_id'), 'template_statistics', ['service_id'], unique=False) + op.create_index(op.f('ix_template_statistics_template_id'), 'template_statistics', ['template_id'], unique=False) + op.create_table('notifications', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('to', sa.String(), nullable=False), + sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('sent_at', sa.DateTime(), nullable=True), + sa.Column('sent_by', sa.String(), nullable=True), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('status', sa.Enum('sending', 'delivered', 'failed', name='notification_status_types'), nullable=False), + sa.Column('reference', sa.String(), nullable=True), + sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ), + sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), + sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_notifications_job_id'), 'notifications', ['job_id'], unique=False) + op.create_index(op.f('ix_notifications_reference'), 'notifications', ['reference'], unique=False) + op.create_index(op.f('ix_notifications_service_id'), 'notifications', ['service_id'], unique=False) + op.create_index(op.f('ix_notifications_template_id'), 'notifications', ['template_id'], unique=False) + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_notifications_template_id'), table_name='notifications') + op.drop_index(op.f('ix_notifications_service_id'), table_name='notifications') + op.drop_index(op.f('ix_notifications_reference'), table_name='notifications') + op.drop_index(op.f('ix_notifications_job_id'), table_name='notifications') + op.drop_table('notifications') + op.drop_index(op.f('ix_template_statistics_template_id'), table_name='template_statistics') + op.drop_index(op.f('ix_template_statistics_service_id'), table_name='template_statistics') + op.drop_index(op.f('ix_template_statistics_day'), table_name='template_statistics') + op.drop_table('template_statistics') + op.drop_index(op.f('ix_jobs_template_id'), table_name='jobs') + op.drop_index(op.f('ix_jobs_service_id'), table_name='jobs') + op.drop_table('jobs') + op.drop_index(op.f('ix_verify_codes_user_id'), table_name='verify_codes') + op.drop_table('verify_codes') + op.drop_table('user_to_service') + op.drop_index(op.f('ix_templates_service_id'), table_name='templates') + op.drop_table('templates') + op.drop_index(op.f('ix_permissions_user_id'), table_name='permissions') + op.drop_index(op.f('ix_permissions_service_id'), table_name='permissions') + op.drop_table('permissions') + op.drop_index(op.f('ix_notification_statistics_service_id'), table_name='notification_statistics') + op.drop_table('notification_statistics') + op.drop_index(op.f('ix_invited_users_user_id'), table_name='invited_users') + op.drop_index(op.f('ix_invited_users_service_id'), table_name='invited_users') + op.drop_table('invited_users') + op.drop_index(op.f('ix_api_keys_service_id'), table_name='api_keys') + op.drop_table('api_keys') + op.drop_index(op.f('ix_users_name'), table_name='users') + op.drop_index(op.f('ix_users_email_address'), table_name='users') + op.drop_table('users') + op.drop_table('services') + ### end Alembic commands ### diff --git a/migrations/versions/0002_add_templates.py b/migrations/versions/0002_add_templates.py deleted file mode 100644 index 30f4073f4..000000000 --- a/migrations/versions/0002_add_templates.py +++ /dev/null @@ -1,38 +0,0 @@ -"""empty message - -Revision ID: 0002_add_templates -Revises: 0001_initialise_data -Create Date: 2016-01-13 10:10:37.303109 - -""" - -# revision identifiers, used by Alembic. -revision = '0002_add_templates' -down_revision = '0001_initialise_data' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('templates', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('template_type', sa.Enum('sms', 'email', 'letter', name='template_type'), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.Column('content', sa.Text(), nullable=False), - sa.Column('service_id', sa.BigInteger(), nullable=True), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_templates_service_id'), 'templates', ['service_id'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_templates_service_id'), table_name='templates') - op.drop_table('templates') - ### end Alembic commands ### diff --git a/migrations/versions/0003_create_tokens.py b/migrations/versions/0003_create_tokens.py deleted file mode 100644 index b850980e3..000000000 --- a/migrations/versions/0003_create_tokens.py +++ /dev/null @@ -1,36 +0,0 @@ -"""empty message - -Revision ID: 0003_create_tokens -Revises: 0001_initialise_data -Create Date: 2016-01-13 17:07:49.061776 - -""" - -# revision identifiers, used by Alembic. -revision = '0003_create_tokens' -down_revision = '0002_add_templates' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('tokens', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('token', sa.String(length=255), nullable=False), - sa.Column('service_id', sa.Integer(), nullable=False), - sa.Column('expiry_date', sa.DateTime(), nullable=True), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('token') - ) - op.create_index(op.f('ix_tokens_service_id'), 'tokens', ['service_id'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_tokens_service_id'), table_name='tokens') - op.drop_table('tokens') - ### end Alembic commands ### diff --git a/migrations/versions/0004_create_jobs.py b/migrations/versions/0004_create_jobs.py deleted file mode 100644 index d5f1cafb6..000000000 --- a/migrations/versions/0004_create_jobs.py +++ /dev/null @@ -1,40 +0,0 @@ -"""empty message - -Revision ID: 0004_create_jobs -Revises: 0003_create_tokens -Create Date: 2016-01-15 10:12:02.381160 - -""" - -# revision identifiers, used by Alembic. -revision = '0004_create_jobs' -down_revision = '0003_create_tokens' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('jobs', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('original_file_name', sa.String(), nullable=False), - sa.Column('service_id', sa.BigInteger(), nullable=True), - sa.Column('template_id', sa.BigInteger(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_jobs_service_id'), 'jobs', ['service_id'], unique=False) - op.create_index(op.f('ix_jobs_template_id'), 'jobs', ['template_id'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_jobs_template_id'), table_name='jobs') - op.drop_index(op.f('ix_jobs_service_id'), table_name='jobs') - op.drop_table('jobs') - ### end Alembic commands ### diff --git a/migrations/versions/0005_add_job_details.py b/migrations/versions/0005_add_job_details.py deleted file mode 100644 index 78fe3efdb..000000000 --- a/migrations/versions/0005_add_job_details.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 0005_add_job_details -Revises: 0004_create_jobs -Create Date: 2016-01-15 15:57:38.022562 - -""" - -# revision identifiers, used by Alembic. -revision = '0005_add_job_details' -down_revision = '0004_create_jobs' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('jobs', sa.Column('bucket_name', sa.String(), nullable=False)) - op.add_column('jobs', sa.Column('file_name', sa.String(), nullable=False)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('jobs', 'file_name') - op.drop_column('jobs', 'bucket_name') - ### end Alembic commands ### diff --git a/migrations/versions/0006_add_user_details.py b/migrations/versions/0006_add_user_details.py deleted file mode 100644 index a789a348c..000000000 --- a/migrations/versions/0006_add_user_details.py +++ /dev/null @@ -1,40 +0,0 @@ -"""empty message - -Revision ID: 0006_add_user_details -Revises: 0005_add_job_details -Create Date: 2016-01-19 11:16:06.518285 - -""" - -# revision identifiers, used by Alembic. -revision = '0006_add_user_details' -down_revision = '0005_add_job_details' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('users', sa.Column('_password', sa.String(), nullable=False)) - op.add_column('users', sa.Column('failed_login_count', sa.Integer(), nullable=False)) - op.add_column('users', sa.Column('logged_in_at', sa.DateTime(), nullable=True)) - op.add_column('users', sa.Column('mobile_number', sa.String(), nullable=False)) - op.add_column('users', sa.Column('name', sa.String(), nullable=False)) - op.add_column('users', sa.Column('password_changed_at', sa.DateTime(), nullable=True)) - op.add_column('users', sa.Column('state', sa.String(), nullable=False)) - op.create_index(op.f('ix_users_name'), 'users', ['name'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_users_name'), table_name='users') - op.drop_column('users', 'state') - op.drop_column('users', 'password_changed_at') - op.drop_column('users', 'name') - op.drop_column('users', 'mobile_number') - op.drop_column('users', 'logged_in_at') - op.drop_column('users', 'failed_login_count') - op.drop_column('users', '_password') - ### end Alembic commands ### diff --git a/migrations/versions/0007_change_to_api_keys.py b/migrations/versions/0007_change_to_api_keys.py deleted file mode 100644 index d63c111d6..000000000 --- a/migrations/versions/0007_change_to_api_keys.py +++ /dev/null @@ -1,47 +0,0 @@ -"""empty message - -Revision ID: 0007_change_to_api_keys -Revises: 0005_add_job_details -Create Date: 2016-01-19 10:50:46.269618 - -""" - -# revision identifiers, used by Alembic. -revision = '0007_change_to_api_keys' -down_revision = '0006_add_user_details' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('api_key', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=255), nullable=False), - sa.Column('secret', sa.String(length=255), nullable=False), - sa.Column('service_id', sa.Integer(), nullable=False), - sa.Column('expiry_date', sa.DateTime(), nullable=True), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('secret') - ) - op.create_index(op.f('ix_api_key_service_id'), 'api_key', ['service_id'], unique=False) - op.drop_table('tokens') - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('tokens', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('token', sa.VARCHAR(length=255), autoincrement=False, nullable=False), - sa.Column('service_id', sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column('expiry_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], name='tokens_service_id_fkey'), - sa.PrimaryKeyConstraint('id', name='tokens_pkey'), - sa.UniqueConstraint('token', name='tokens_token_key') - ) - op.drop_index(op.f('ix_api_key_service_id'), table_name='api_key') - op.drop_table('api_key') - ### end Alembic commands ### diff --git a/migrations/versions/0008_add_verify_codes.py b/migrations/versions/0008_add_verify_codes.py deleted file mode 100644 index 47d79be9e..000000000 --- a/migrations/versions/0008_add_verify_codes.py +++ /dev/null @@ -1,38 +0,0 @@ -"""empty message - -Revision ID: 0008_add_verify_codes -Revises: 0007_change_to_api_keys -Create Date: 2016-01-21 16:59:05.818017 - -""" - -# revision identifiers, used by Alembic. -revision = '0008_add_verify_codes' -down_revision = '0007_change_to_api_keys' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('verify_codes', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('_code', sa.String(), nullable=False), - sa.Column('code_type', sa.Enum('email', 'sms', name='verify_code_types'), nullable=False), - sa.Column('expiry_datetime', sa.DateTime(), nullable=False), - sa.Column('code_used', sa.Boolean(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_verify_codes_user_id'), 'verify_codes', ['user_id'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_verify_codes_user_id'), table_name='verify_codes') - op.drop_table('verify_codes') - ### end Alembic commands ### diff --git a/migrations/versions/0009_unique_service_to_key_name.py b/migrations/versions/0009_unique_service_to_key_name.py deleted file mode 100644 index 1185131bb..000000000 --- a/migrations/versions/0009_unique_service_to_key_name.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0009_unique_service_to_key_name -Revises: 0007_change_to_api_keys -Create Date: 2016-01-21 16:14:51.773001 - -""" - -# revision identifiers, used by Alembic. -revision = '0009_unique_service_to_key_name' -down_revision = '0008_add_verify_codes' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_unique_constraint('uix_service_to_key_name', 'api_key', ['service_id', 'name']) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint('uix_service_to_key_name', 'api_key', type_='unique') - ### end Alembic commands ### diff --git a/migrations/versions/0010_add_queue_name_to_service.py b/migrations/versions/0010_add_queue_name_to_service.py deleted file mode 100644 index 636847cd3..000000000 --- a/migrations/versions/0010_add_queue_name_to_service.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 0010_add_queue_name_to_service -Revises: 0009_unique_service_to_key_name -Create Date: 2016-01-27 13:53:34.717916 - -""" - -# revision identifiers, used by Alembic. - -revision = '0010_add_queue_name_to_service' -down_revision = '0009_unique_service_to_key_name' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('services', sa.Column('queue_name', postgresql.UUID(as_uuid=True), nullable=True)) - op.get_bind() - op.execute('update services set queue_name = (SELECT uuid_in(md5(random()::text || now()::text)::cstring))') - ### end Alembic commands ### - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('services', 'queue_name') - ### end Alembic commands ### diff --git a/migrations/versions/0011_uuid_service_id.py b/migrations/versions/0011_uuid_service_id.py deleted file mode 100644 index d332930ef..000000000 --- a/migrations/versions/0011_uuid_service_id.py +++ /dev/null @@ -1,121 +0,0 @@ -"""empty message - -Revision ID: 0011_uuid_service_id -Revises: 0010_add_queue_name_to_service -Create Date: 2016-02-01 15:47:30.553052 - -""" - -# revision identifiers, used by Alembic. -from sqlalchemy.dialects import postgresql - -revision = '0011_uuid_service_id' -down_revision = '0010_add_queue_name_to_service' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - - # op.execute('update jobs set new_service_id = (SELECT queue_name from services where service_id = services.id)') - - op.add_column('user_to_service', sa.Column('new_service_id', postgresql.UUID(as_uuid=True), nullable=True)) - op.get_bind() - op.execute('update user_to_service '\ - 'set new_service_id = (SELECT queue_name from services where service_id = services.id)') - - op.drop_column('user_to_service', 'service_id') - op.alter_column('user_to_service', 'new_service_id', new_column_name='service_id') - - op.add_column('jobs', sa.Column('new_service_id', postgresql.UUID(as_uuid=True), nullable=True)) - op.execute('update jobs '\ - 'set new_service_id = (SELECT queue_name from services where service_id = services.id)') - - op.drop_column('jobs', 'service_id') - op.alter_column('jobs', 'new_service_id', new_column_name='service_id', nullable=False) - - op.add_column('api_key', sa.Column('new_service_id', postgresql.UUID(as_uuid=True), nullable=True)) - op.execute('update api_key '\ - 'set new_service_id = (SELECT queue_name from services where service_id = services.id)') - - op.drop_column('api_key', 'service_id') - op.alter_column('api_key', 'new_service_id', new_column_name='service_id', nullable=False) - - op.add_column('templates', sa.Column('new_service_id', postgresql.UUID(as_uuid=True), nullable=True)) - op.execute('update templates '\ - 'set new_service_id = (SELECT queue_name from services where service_id = services.id)') - - op.drop_column('templates', 'service_id') - op.alter_column('templates', 'new_service_id', new_column_name='service_id', nullable=False) - - op.drop_constraint('services_pkey', 'services') - op.alter_column('services', 'id', new_column_name='old_id') - op.alter_column('services', 'queue_name', new_column_name='id', nullable=False) - - op.create_primary_key('services_pkey', 'services', ['id']) - - op.create_foreign_key('user_to_service_service_id_fkey', 'user_to_service', 'services', ['service_id'], ['id']) - op.create_foreign_key('api_key_service_id_fkey', 'api_key', 'services', ['service_id'], ['id']) - op.create_foreign_key('jobs_service_id_fkey', 'jobs', 'services', ['service_id'], ['id']) - op.create_foreign_key('templates_service_id_fkey', 'templates', 'services', ['service_id'], ['id']) - - op.create_index(op.f('ix_templates_service_id'), 'templates', ['service_id'], unique=False) - op.create_index(op.f('ix_jobs_service_id'), 'jobs', ['service_id'], unique=False) - op.create_index(op.f('ix_api_key_service_id'), 'api_key', ['service_id'], unique=False) - op.create_unique_constraint('uix_service_to_key_name', 'api_key', ['service_id', 'name']) - - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - - op.add_column('user_to_service', sa.Column('new_service_id', sa.Integer, nullable=True)) - op.get_bind() - op.execute('update user_to_service '\ - 'set new_service_id = (SELECT old_id from services where service_id = services.id)') - - op.drop_column('user_to_service', 'service_id') - op.alter_column('user_to_service', 'new_service_id', new_column_name='service_id', nullable=False) - - op.add_column('jobs', sa.Column('new_service_id', sa.Integer, nullable=True)) - op.execute('update jobs '\ - 'set new_service_id = (SELECT old_id from services where service_id = services.id)') - - op.drop_column('jobs', 'service_id') - op.alter_column('jobs', 'new_service_id', new_column_name='service_id', nullable=False) - - op.add_column('api_key', sa.Column('new_service_id', sa.Integer, nullable=True)) - op.execute('update api_key '\ - 'set new_service_id = (SELECT old_id from services where service_id = services.id)') - - op.drop_column('api_key', 'service_id') - op.alter_column('api_key', 'new_service_id', new_column_name='service_id', nullable=False) - - op.add_column('templates', sa.Column('new_service_id', sa.Integer, nullable=True)) - op.execute('update templates '\ - 'set new_service_id = (SELECT old_id from services where service_id = services.id)') - - op.drop_column('templates', 'service_id') - op.alter_column('templates', 'new_service_id', new_column_name='service_id', nullable=False) - - op.drop_constraint('services_pkey', 'services') - - op.alter_column('services', 'id', new_column_name='queue_name', nullable=False) - op.alter_column('services', 'old_id', new_column_name='id', nullable=True) - - op.create_primary_key('services_pkey', 'services', ['id']) - - op.create_foreign_key('user_to_service_service_id_fkey', 'user_to_service', 'services', ['service_id'], ['id']) - op.create_foreign_key('api_key_service_id_fkey', 'api_key', 'services', ['service_id'], ['id']) - op.create_foreign_key('jobs_service_id_fkey', 'jobs', 'services', ['service_id'], ['id']) - op.create_foreign_key('templates_service_id_fkey', 'templates', 'services', ['service_id'], ['id']) - - op.create_index(op.f('ix_api_key_service_id'), 'api_key', ['service_id'], unique=False) - op.create_unique_constraint('uix_service_to_key_name', 'api_key', ['service_id', 'name']) - op.create_index(op.f('ix_jobs_service_id'), 'jobs', ['service_id'], unique=False) - op.create_index(op.f('ix_templates_service_id'), 'templates', ['service_id'], unique=False) - - ### end Alembic commands ### diff --git a/migrations/versions/0012_add_status_to_job.py b/migrations/versions/0012_add_status_to_job.py deleted file mode 100644 index e5ca0a3f1..000000000 --- a/migrations/versions/0012_add_status_to_job.py +++ /dev/null @@ -1,34 +0,0 @@ -"""empty message - -Revision ID: 0012_add_status_to_job -Revises: 0011_uuid_service_id -Create Date: 2016-02-02 11:25:34.402864 - -""" - -# revision identifiers, used by Alembic. -revision = '0012_add_status_to_job' -down_revision = '0011_uuid_service_id' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - job_status_types = sa.Enum('pending', 'in progress', 'finished', name='job_status_types') - job_status_types.create(op.get_bind()) - op.add_column('jobs', sa.Column('status', job_status_types, nullable=True)) - op.get_bind() - op.execute("update jobs set status='pending'") - op.alter_column('jobs', 'status', nullable=False) - - - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('jobs', 'status') - op.execute('DROP TYPE job_status_types') - ### end Alembic commands ### diff --git a/migrations/versions/0013_add_notifications.py b/migrations/versions/0013_add_notifications.py deleted file mode 100644 index 61fd55a66..000000000 --- a/migrations/versions/0013_add_notifications.py +++ /dev/null @@ -1,47 +0,0 @@ -"""empty message - -Revision ID: 0013_add_notifications -Revises: 0012_add_status_to_job -Create Date: 2016-02-09 11:14:46.708551 - -""" - -# revision identifiers, used by Alembic. -revision = '0013_add_notifications' -down_revision = '0012_add_status_to_job' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('notifications', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('to', sa.String(), nullable=False), - sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), - sa.Column('template_id', sa.BigInteger(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.Column('status', sa.Enum('sent', 'failed', name='notification_status_types'), nullable=False), - sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_notifications_job_id'), 'notifications', ['job_id'], unique=False) - op.create_index(op.f('ix_notifications_service_id'), 'notifications', ['service_id'], unique=False) - op.create_index(op.f('ix_notifications_template_id'), 'notifications', ['template_id'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_notifications_template_id'), table_name='notifications') - op.drop_index(op.f('ix_notifications_service_id'), table_name='notifications') - op.drop_index(op.f('ix_notifications_job_id'), table_name='notifications') - op.drop_table('notifications') - op.get_bind() - op.execute("drop type notification_status_types") - ### end Alembic commands ### diff --git a/migrations/versions/0014_job_id_nullable.py b/migrations/versions/0014_job_id_nullable.py deleted file mode 100644 index 8c27b3ce1..000000000 --- a/migrations/versions/0014_job_id_nullable.py +++ /dev/null @@ -1,30 +0,0 @@ -"""empty message - -Revision ID: 0014_job_id_nullable -Revises: 0013_add_notifications -Create Date: 2016-02-10 10:57:39.414061 - -""" - -# revision identifiers, used by Alembic. -revision = '0014_job_id_nullable' -down_revision = '0013_add_notifications' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.alter_column('notifications', 'job_id', - existing_type=postgresql.UUID(), - nullable=True) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.alter_column('notifications', 'job_id', - existing_type=postgresql.UUID(), - nullable=False) - ### end Alembic commands ### diff --git a/migrations/versions/0015_add_permissions.py b/migrations/versions/0015_add_permissions.py deleted file mode 100644 index 507a5effa..000000000 --- a/migrations/versions/0015_add_permissions.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0015_add_permissions -Revises: 0014_job_id_nullable -Create Date: 2016-02-19 14:16:59.359493 - -""" - -# revision identifiers, used by Alembic. -revision = '0015_add_permissions' -down_revision = '0014_job_id_nullable' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('users', sa.Column('permissions', postgresql.ARRAY(sa.String()), nullable=True)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('users', 'permissions') - ### end Alembic commands ### diff --git a/migrations/versions/0015_add_subject_line.py b/migrations/versions/0015_add_subject_line.py deleted file mode 100644 index 88102327d..000000000 --- a/migrations/versions/0015_add_subject_line.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0015_add_subject_line -Revises: 0015_add_permissions -Create Date: 2016-02-18 09:43:29.282804 - -""" - -# revision identifiers, used by Alembic. -revision = '0015_add_subject_line' -down_revision = '0015_add_permissions' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - pass - op.add_column('templates', sa.Column('subject', sa.Text(), nullable=True)) - op.create_unique_constraint(None, 'templates', ['subject']) - - -def downgrade(): - pass - op.drop_constraint(None, 'templates', type_='unique') - op.drop_column('templates', 'subject') diff --git a/migrations/versions/0016_add_email_from.py b/migrations/versions/0016_add_email_from.py deleted file mode 100644 index 053d65765..000000000 --- a/migrations/versions/0016_add_email_from.py +++ /dev/null @@ -1,23 +0,0 @@ -"""empty message - -Revision ID: 0016_add_email_from -Revises: 0015_add_subject_line -Create Date: 2016-02-18 11:25:37.915137 - -""" - -# revision identifiers, used by Alembic. -revision = '0016_add_email_from' -down_revision = '0015_add_subject_line' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('services', sa.Column('email_from', sa.Text(), nullable=True)) - op.execute("UPDATE services SET email_from=name") - - -def downgrade(): - op.drop_column('services', 'email_from') diff --git a/migrations/versions/0017_emailfrom_notnull.py b/migrations/versions/0017_emailfrom_notnull.py deleted file mode 100644 index f30ac105d..000000000 --- a/migrations/versions/0017_emailfrom_notnull.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0017_emailfrom_notnull -Revises: 0016_add_email_from -Create Date: 2016-02-18 11:41:25.753694 - -""" - -# revision identifiers, used by Alembic. -revision = '0017_emailfrom_notnull' -down_revision = '0016_add_email_from' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.alter_column('services', 'email_from', - existing_type=sa.TEXT(), - nullable=False) - - -def downgrade(): - op.alter_column('services', 'email_from', - existing_type=sa.TEXT(), - nullable=True) diff --git a/migrations/versions/0018_unique_emailfrom.py b/migrations/versions/0018_unique_emailfrom.py deleted file mode 100644 index f36d61bce..000000000 --- a/migrations/versions/0018_unique_emailfrom.py +++ /dev/null @@ -1,22 +0,0 @@ -"""empty message - -Revision ID: 0018_unique_emailfrom -Revises: 0017_emailfrom_notnull -Create Date: 2016-02-18 11:42:18.246280 - -""" - -# revision identifiers, used by Alembic. -revision = '0018_unique_emailfrom' -down_revision = '0017_emailfrom_notnull' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.create_unique_constraint(None, 'services', ['email_from']) - - -def downgrade(): - op.drop_constraint(None, 'services', type_='unique') diff --git a/migrations/versions/0019_unique_servicename.py b/migrations/versions/0019_unique_servicename.py deleted file mode 100644 index 1c8d83976..000000000 --- a/migrations/versions/0019_unique_servicename.py +++ /dev/null @@ -1,22 +0,0 @@ -"""empty message - -Revision ID: 0019_unique_servicename -Revises: 0018_unique_emailfrom -Create Date: 2016-02-18 11:45:29.102891 - -""" - -# revision identifiers, used by Alembic. -revision = '0019_unique_servicename' -down_revision = '0018_unique_emailfrom' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.create_unique_constraint(None, 'services', ['name']) - - -def downgrade(): - op.drop_constraint(None, 'services', type_='unique') diff --git a/migrations/versions/0020_email_has_subject.py b/migrations/versions/0020_email_has_subject.py deleted file mode 100644 index 2290b83bf..000000000 --- a/migrations/versions/0020_email_has_subject.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0020_email_has_subject -Revises: 0019_unique_servicename -Create Date: 2016-02-18 11:45:29.102891 - -""" - -# revision identifiers, used by Alembic. -revision = '0020_email_has_subject' -down_revision = '0019_unique_servicename' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.create_check_constraint( - "ch_email_template_has_subject", - "templates", - "((template_type='email' and subject is not null) or (template_type!='email' and subject is null))" - ) - - -def downgrade(): - op.drop_constraint('ch_email_template_has_subject', 'templates', type_='check') diff --git a/migrations/versions/0021_add_job_metadata.py b/migrations/versions/0021_add_job_metadata.py deleted file mode 100644 index a72d86c23..000000000 --- a/migrations/versions/0021_add_job_metadata.py +++ /dev/null @@ -1,29 +0,0 @@ -"""empty message - -Revision ID: 0021_add_job_metadata -Revises: 0020_email_has_subject -Create Date: 2016-02-22 12:33:02.360780 - -""" - -# revision identifiers, used by Alembic. -revision = '0021_add_job_metadata' -down_revision = '0020_email_has_subject' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('jobs', sa.Column('notification_count', sa.Integer(), nullable=True)) - op.get_bind() - op.execute('update jobs set notification_count = 0') - op.alter_column('jobs', 'notification_count', nullable=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('jobs', 'notification_count') - ### end Alembic commands ### diff --git a/migrations/versions/0022_add_invite_users.py b/migrations/versions/0022_add_invite_users.py deleted file mode 100644 index b77be1d73..000000000 --- a/migrations/versions/0022_add_invite_users.py +++ /dev/null @@ -1,42 +0,0 @@ -"""empty message - -Revision ID: 0022_add_invite_users -Revises: 0021_add_job_metadata -Create Date: 2016-02-23 16:41:40.481468 - -""" - -# revision identifiers, used by Alembic. -revision = '0022_add_invite_users' -down_revision = '0021_add_job_metadata' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('invited_users', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('email_address', sa.String(length=255), nullable=False), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), - sa.Column('_token', sa.String(), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.Column('status', sa.Enum('pending', 'accepted', 'cancelled', name='invited_users_status_types'), nullable=False), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_invited_users_service_id'), 'invited_users', ['service_id'], unique=False) - op.create_index(op.f('ix_invited_users_user_id'), 'invited_users', ['user_id'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_invited_users_user_id'), table_name='invited_users') - op.drop_index(op.f('ix_invited_users_service_id'), table_name='invited_users') - op.drop_table('invited_users') - op.execute('DROP TYPE invited_users_status_types') - ### end Alembic commands ### diff --git a/migrations/versions/0023_drop_token.py b/migrations/versions/0023_drop_token.py deleted file mode 100644 index bf6f705d7..000000000 --- a/migrations/versions/0023_drop_token.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0023_drop_token -Revises: 0022_add_invite_users -Create Date: 2016-02-24 13:58:04.440296 - -""" - -# revision identifiers, used by Alembic. -revision = '0023_drop_token' -down_revision = '0022_add_invite_users' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('invited_users', '_token') - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('invited_users', sa.Column('_token', sa.VARCHAR(), autoincrement=False, nullable=False)) - ### end Alembic commands ### diff --git a/migrations/versions/0024_uix_user_to_service.py b/migrations/versions/0024_uix_user_to_service.py deleted file mode 100644 index 63b131c68..000000000 --- a/migrations/versions/0024_uix_user_to_service.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0024_uix_user_to_service -Revises: 0023_drop_token -Create Date: 2016-02-25 11:15:06.088508 - -""" - -# revision identifiers, used by Alembic. -revision = '0024_uix_user_to_service' -down_revision = '0023_drop_token' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_unique_constraint('uix_user_to_service', 'user_to_service', ['user_id', 'service_id']) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_constraint('uix_user_to_service', 'user_to_service', type_='unique') - ### end Alembic commands ### diff --git a/migrations/versions/0025_add_processing_dates.py b/migrations/versions/0025_add_processing_dates.py deleted file mode 100644 index 850658148..000000000 --- a/migrations/versions/0025_add_processing_dates.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0025_add_processing_dates -Revises: 0024_uix_user_to_service -Create Date: 2016-02-24 17:15:47.457200 - -""" - -# revision identifiers, used by Alembic. -revision = '0025_add_processing_dates' -down_revision = '0024_uix_user_to_service' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('jobs', sa.Column('processing_finished', sa.DateTime(), nullable=True)) - op.add_column('jobs', sa.Column('processing_started', sa.DateTime(), nullable=True)) - op.add_column('notifications', sa.Column('sent_at', sa.DateTime(), nullable=True)) - - -def downgrade(): - op.drop_column('notifications', 'sent_at') - op.drop_column('jobs', 'processing_started') - op.drop_column('jobs', 'processing_finished') diff --git a/migrations/versions/0026_add_sender.py b/migrations/versions/0026_add_sender.py deleted file mode 100644 index ffe86f920..000000000 --- a/migrations/versions/0026_add_sender.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0026_add_sender -Revises: 0025_add_processing_dates -Create Date: 2016-02-24 17:18:21.942772 - -""" - -# revision identifiers, used by Alembic. -revision = '0026_add_sender' -down_revision = '0025_add_processing_dates' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('notifications', sa.Column('sent_by', sa.String(), nullable=True)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('notifications', 'sent_by') - ### end Alembic commands ### diff --git a/migrations/versions/0027_add_service_permission.py b/migrations/versions/0027_add_service_permission.py deleted file mode 100644 index fe3149588..000000000 --- a/migrations/versions/0027_add_service_permission.py +++ /dev/null @@ -1,42 +0,0 @@ -"""empty message - -Revision ID: 0027_add_service_permission -Revises: 0026_add_sender -Create Date: 2016-02-26 10:33:20.536362 - -""" - -# revision identifiers, used by Alembic. -revision = '0027_add_service_permission' -down_revision = '0026_add_sender' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('permissions', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('permission', sa.String(length=255), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('service_id', 'user_id', 'permission', name='uix_service_user_permission') - ) - op.create_index(op.f('ix_permissions_service_id'), 'permissions', ['service_id'], unique=False) - op.create_index(op.f('ix_permissions_user_id'), 'permissions', ['user_id'], unique=False) - op.drop_column('users', 'permissions') - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('users', sa.Column('permissions', postgresql.ARRAY(VARCHAR()), autoincrement=False, nullable=True)) - op.drop_index(op.f('ix_permissions_user_id'), table_name='permissions') - op.drop_index(op.f('ix_permissions_service_id'), table_name='permissions') - op.drop_table('permissions') - ### end Alembic commands ### diff --git a/migrations/versions/0028_add_default_permissions.py b/migrations/versions/0028_add_default_permissions.py deleted file mode 100644 index 893f4f851..000000000 --- a/migrations/versions/0028_add_default_permissions.py +++ /dev/null @@ -1,44 +0,0 @@ -"""empty message - -Revision ID: 0028_add_default_permissions -Revises: 0027_add_service_permission -Create Date: 2016-02-26 10:33:20.536362 - -""" - -# revision identifiers, used by Alembic. -revision = '0028_add_default_permissions' -down_revision = '0027_add_service_permission' -import uuid -from datetime import datetime -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - user_services = conn.execute("SELECT * FROM user_to_service").fetchall() - for entry in user_services: - id_ = uuid.uuid4() - created_at = datetime.now().isoformat().replace('T', ' ') - conn.execute(( - "INSERT INTO permissions (id, user_id, service_id, permission, created_at)" - " VALUES ('{}', '{}', '{}', 'manage_service', '{}')").format(id_, entry[0], entry[1], created_at)) - id_ = uuid.uuid4() - conn.execute(( - "INSERT INTO permissions (id, user_id, service_id, permission, created_at)" - " VALUES ('{}', '{}', '{}', 'send_messages', '{}')").format(id_, entry[0], entry[1], created_at)) - id_ = uuid.uuid4() - conn.execute(( - "INSERT INTO permissions (id, user_id, service_id, permission, created_at)" - " VALUES ('{}', '{}', '{}', 'manage_api_keys', '{}')").format(id_, entry[0], entry[1], created_at)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - conn.execute("DELETE FROM permissions") - - ### end Alembic commands ### \ No newline at end of file diff --git a/migrations/versions/0029_add_permissions_to_invite.py b/migrations/versions/0029_add_permissions_to_invite.py deleted file mode 100644 index b00cbee62..000000000 --- a/migrations/versions/0029_add_permissions_to_invite.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0029_add_permissions_to_invite -Revises: 0028_add_default_permissions -Create Date: 2016-02-26 16:17:30.612924 - -""" - -# revision identifiers, used by Alembic. -revision = '0029_add_permissions_to_invite' -down_revision = '0028_add_default_permissions' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('invited_users', sa.Column('permissions', sa.String(), nullable=False)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('invited_users', 'permissions') - ### end Alembic commands ### diff --git a/migrations/versions/0030_add_template_permission.py b/migrations/versions/0030_add_template_permission.py deleted file mode 100644 index 7eb2795c3..000000000 --- a/migrations/versions/0030_add_template_permission.py +++ /dev/null @@ -1,36 +0,0 @@ -"""empty message - -Revision ID: 0030_add_template_permission -Revises: 0029_add_permissions_to_invite -Create Date: 2016-02-26 10:33:20.536362 - -""" - -# revision identifiers, used by Alembic. -revision = '0030_add_template_permission' -down_revision = '0029_add_permissions_to_invite' -import uuid -from datetime import datetime -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - user_services = conn.execute("SELECT * FROM user_to_service").fetchall() - for entry in user_services: - id_ = uuid.uuid4() - created_at = datetime.now().isoformat().replace('T', ' ') - conn.execute(( - "INSERT INTO permissions (id, user_id, service_id, permission, created_at)" - " VALUES ('{}', '{}', '{}', 'manage_templates', '{}')").format(id_, entry[0], entry[1], created_at)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - conn.execute("DELETE FROM permissions where permission='manage_templates'") - - ### end Alembic commands ### \ No newline at end of file diff --git a/migrations/versions/0031_add_manage_team_permission.py b/migrations/versions/0031_add_manage_team_permission.py deleted file mode 100644 index 05413da45..000000000 --- a/migrations/versions/0031_add_manage_team_permission.py +++ /dev/null @@ -1,41 +0,0 @@ -"""empty message - -Revision ID: 0031_add_manage_team_permission -Revises: 0030_add_template_permission -Create Date: 2016-02-26 10:33:20.536362 - -""" - -# revision identifiers, used by Alembic. -revision = '0031_add_manage_team_permission' -down_revision = '0030_add_template_permission' -import uuid -from datetime import datetime -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - user_services = conn.execute("SELECT * FROM user_to_service").fetchall() - for entry in user_services: - id_ = uuid.uuid4() - created_at = datetime.now().isoformat().replace('T', ' ') - conn.execute(( - "INSERT INTO permissions (id, user_id, service_id, permission, created_at)" - " VALUES ('{}', '{}', '{}', 'manage_team', '{}')").format(id_, entry[0], entry[1], created_at)) - id_ = uuid.uuid4() - conn.execute(( - "INSERT INTO permissions (id, user_id, service_id, permission, created_at)" - " VALUES ('{}', '{}', '{}', 'view_activity', '{}')").format(id_, entry[0], entry[1], created_at)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - conn.execute("DELETE FROM permissions where permission='manage_team'") - conn.execute("DELETE FROM permissions where permission='view_activity'") - - ### end Alembic commands ### \ No newline at end of file diff --git a/migrations/versions/0032_update_permission_to_enum.py b/migrations/versions/0032_update_permission_to_enum.py deleted file mode 100644 index 0bf9d0ea4..000000000 --- a/migrations/versions/0032_update_permission_to_enum.py +++ /dev/null @@ -1,48 +0,0 @@ -"""empty message - -Revision ID: 0032_update_permission_to_enum -Revises: 0031_add_manage_team_permission -Create Date: 2016-03-01 17:08:12.184393 - -""" - -# revision identifiers, used by Alembic. -revision = '0032_update_permission_to_enum' -down_revision = '0031_add_manage_team_permission' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - permissions = conn.execute("SELECT id, permission FROM permissions").fetchall() - op.drop_constraint('uix_service_user_permission', 'permissions', type_='unique') - op.drop_column('permissions', 'permission') - permission_types = sa.Enum('manage_service', 'send_messages', 'manage_api_keys', 'manage_templates', 'manage_team', 'view_activity', name='permission_types') - permission_types.create(op.get_bind()) - op.add_column('permissions', sa.Column('permission', permission_types, nullable=True)) - for p in permissions: - conn.execute("UPDATE permissions SET permission='{}' WHERE id='{}'".format(str(p[1]), str(p[0]))) - op.create_unique_constraint('uix_service_user_permission', 'permissions', ['service_id', 'user_id', 'permission']) - op.alter_column('permissions', 'permission', nullable=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - permissions = conn.execute("SELECT id, permission FROM permissions").fetchall() - op.drop_constraint('uix_service_user_permission', 'permissions', type_='unique') - op.drop_column('permissions', 'permission') - try: - sa.Enum(name='permission_types').drop(conn, checkfirst=False) - except: - pass - op.add_column('permissions', sa.Column('permission', sa.VARCHAR(length=255), autoincrement=False, nullable=True)) - for p in permissions: - conn.execute("UPDATE permissions SET permission='{}' WHERE ID='{}'".format(str(p[1]), str(p[0]))) - op.create_unique_constraint('uix_service_user_permission', 'permissions', ['service_id', 'user_id', 'permission']) - op.alter_column('permissions', 'permission', nullable=False) - ### end Alembic commands ### diff --git a/migrations/versions/0033_correct_permission_enums.py b/migrations/versions/0033_correct_permission_enums.py deleted file mode 100644 index 52989b6c4..000000000 --- a/migrations/versions/0033_correct_permission_enums.py +++ /dev/null @@ -1,81 +0,0 @@ -"""empty message - -Revision ID: 0033_correct_permission_enums -Revises: 0032_update_permission_to_enum -Create Date: 2016-03-02 15:00:25.358153 - -""" - -# revision identifiers, used by Alembic. -revision = '0033_correct_permission_enums' -down_revision = '0032_update_permission_to_enum' - -import uuid -from datetime import datetime -from alembic import op -import sqlalchemy as sa - - -def add_default_permissions(conn, permissions): - user_services = conn.execute("SELECT * FROM user_to_service").fetchall() - for entry in user_services: - for p in permissions: - id_ = uuid.uuid4() - created_at = datetime.now().isoformat().replace('T', ' ') - conn.execute(( - "INSERT INTO permissions (id, user_id, service_id, permission, created_at)" - " VALUES ('{}', '{}', '{}', '{}', '{}')").format(id_, entry[0], entry[1], p, created_at)) - - -def upgrade(): - # Since there are no specific permissions set for services yet - # we can just remove all and re-add all. - ### commands auto generated by Nick - please adjust! ### - new_permissions = ['manage_users', - 'manage_templates', - 'manage_settings', - 'send_texts', - 'send_emails', - 'send_letters', - 'manage_api_keys', - 'access_developer_docs'] - conn = op.get_bind() - conn.execute("DELETE FROM permissions") - op.drop_constraint('uix_service_user_permission', 'permissions', type_='unique') - op.drop_column('permissions', 'permission') - try: - sa.Enum(name='permission_types').drop(conn, checkfirst=False) - except: - pass - permission_types = sa.Enum(*new_permissions, name='permission_types') - permission_types.create(op.get_bind()) - op.add_column('permissions', sa.Column('permission', permission_types, nullable=False)) - add_default_permissions(conn, new_permissions) - op.alter_column('permissions', 'permission', nullable=False) - op.create_unique_constraint('uix_service_user_permission', 'permissions', ['service_id', 'user_id', 'permission']) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Nick - please adjust! ### - old_permissions = ['manage_service', - 'send_messages', - 'manage_api_keys', - 'manage_templates', - 'manage_team', - 'view_activity'] - conn = op.get_bind() - conn.execute("DELETE FROM permissions") - op.drop_constraint('uix_service_user_permission', 'permissions', type_='unique') - op.drop_column('permissions', 'permission') - try: - sa.Enum(name='permission_types').drop(conn, checkfirst=False) - except: - pass - permission_types = sa.Enum(*old_permissions, name='permission_types') - permission_types.create(op.get_bind()) - op.add_column('permissions', sa.Column('permission', permission_types, nullable=False)) - add_default_permissions(conn, old_permissions) - op.alter_column('permissions', 'permission', nullable=False) - op.create_unique_constraint('uix_service_user_permission', 'permissions', ['service_id', 'user_id', 'permission']) - ### end Alembic commands ### diff --git a/migrations/versions/0034_job_sent_count.py b/migrations/versions/0034_job_sent_count.py deleted file mode 100644 index d741d1b88..000000000 --- a/migrations/versions/0034_job_sent_count.py +++ /dev/null @@ -1,26 +0,0 @@ -"""empty message - -Revision ID: 0034_job_sent_count -Revises: 0033_correct_permission_enums -Create Date: 2016-03-04 13:44:32.217058 - -""" - -# revision identifiers, used by Alembic. -revision = '0034_job_sent_count' -down_revision = '0033_correct_permission_enums' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('jobs', sa.Column('notifications_sent', sa.Integer(), nullable=True)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('jobs', 'notifications_sent') - ### end Alembic commands ### diff --git a/migrations/versions/0035_default_sent_count.py b/migrations/versions/0035_default_sent_count.py deleted file mode 100644 index aac9524a6..000000000 --- a/migrations/versions/0035_default_sent_count.py +++ /dev/null @@ -1,27 +0,0 @@ -"""empty message - -Revision ID: 0035_default_sent_count -Revises: 0034_job_sent_count -Create Date: 2016-03-08 09:08:55.721654 - -""" - -# revision identifiers, used by Alembic. -revision = '0035_default_sent_count' -down_revision = '0034_job_sent_count' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.execute('update jobs set notifications_sent = notification_count') - op.alter_column('jobs', 'notifications_sent', - existing_type=sa.INTEGER(), - nullable=False) - - -def downgrade(): - op.alter_column('jobs', 'notifications_sent', - existing_type=sa.INTEGER(), - nullable=True) diff --git a/migrations/versions/0036_notification_stats.py b/migrations/versions/0036_notification_stats.py deleted file mode 100644 index 33c6d3f90..000000000 --- a/migrations/versions/0036_notification_stats.py +++ /dev/null @@ -1,37 +0,0 @@ -"""empty message - -Revision ID: 0036_notification_stats -Revises: 0035_default_sent_count -Create Date: 2016-03-08 11:16:25.659463 - -""" - -# revision identifiers, used by Alembic. -revision = '0036_notification_stats' -down_revision = '0035_default_sent_count' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - op.create_table('notification_statistics', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('day', sa.String(length=255), nullable=False), - sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('emails_requested', sa.BigInteger(), nullable=False), - sa.Column('emails_delivered', sa.BigInteger(), nullable=True), - sa.Column('emails_error', sa.BigInteger(), nullable=True), - sa.Column('sms_requested', sa.BigInteger(), nullable=False), - sa.Column('sms_delivered', sa.BigInteger(), nullable=True), - sa.Column('sms_error', sa.BigInteger(), nullable=True), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('service_id', 'day', name='uix_service_to_day') - ) - op.create_index(op.f('ix_service_notification_stats_service_id'), 'notification_statistics', ['service_id'], unique=False) - - -def downgrade(): - op.drop_index(op.f('ix_service_notification_stats_service_id'), table_name='notification_statistics') - op.drop_table('notification_statistics') diff --git a/migrations/versions/0037_more_job_states.py b/migrations/versions/0037_more_job_states.py deleted file mode 100644 index ef6e5671b..000000000 --- a/migrations/versions/0037_more_job_states.py +++ /dev/null @@ -1,30 +0,0 @@ -"""empty message - -Revision ID: 0037_more_job_states -Revises: 0036_notification_stats -Create Date: 2016-03-08 11:16:25.659463 - -""" - -# revision identifiers, used by Alembic. -revision = '0037_more_job_states' -down_revision = '0036_notification_stats' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -def upgrade(): - op.drop_column('jobs', 'status') - op.execute('DROP TYPE job_status_types') - job_status_types = sa.Enum('pending', 'in progress', 'finished', 'sending limits exceeded', name='job_status_types') - job_status_types.create(op.get_bind()) - op.add_column('jobs', sa.Column('status', job_status_types, nullable=True)) - op.get_bind() - op.execute("update jobs set status='finished'") - op.alter_column('jobs', 'status', nullable=False) - - -def downgrade(): - op.drop_column('jobs', 'status') - op.execute('DROP TYPE job_status_types') diff --git a/migrations/versions/0038_reduce_limits.py b/migrations/versions/0038_reduce_limits.py deleted file mode 100644 index e9d9fd1f3..000000000 --- a/migrations/versions/0038_reduce_limits.py +++ /dev/null @@ -1,21 +0,0 @@ -"""empty message - -Revision ID: 0038_reduce_limits -Revises: 0037_more_job_states -Create Date: 2016-03-08 11:16:25.659463 - -""" - -# revision identifiers, used by Alembic. -revision = '0038_reduce_limits' -down_revision = '0037_more_job_states' - -from alembic import op - - -def upgrade(): - op.execute('update services set "limit" = 50') - - -def downgrade(): - pass \ No newline at end of file diff --git a/migrations/versions/0039_more_notification_states.py b/migrations/versions/0039_more_notification_states.py deleted file mode 100644 index 7ac99e6ab..000000000 --- a/migrations/versions/0039_more_notification_states.py +++ /dev/null @@ -1,31 +0,0 @@ -"""empty message - -Revision ID: 0039_more_notification_states -Revises: 0038_reduce_limits -Create Date: 2016-03-08 11:16:25.659463 - -""" - -# revision identifiers, used by Alembic. -revision = '0039_more_notification_states' -down_revision = '0038_reduce_limits' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - - -def upgrade(): - op.drop_column('notifications', 'status') - op.execute('DROP TYPE notification_status_types') - notification_status_types = sa.Enum('sent', 'delivered', 'failed', 'complaint', 'bounce', name='notification_status_types') - notification_status_types.create(op.get_bind()) - op.add_column('notifications', sa.Column('status', notification_status_types, nullable=True)) - op.get_bind() - op.execute("update notifications set status='delivered'") - op.alter_column('notifications', 'status', nullable=False) - - -def downgrade(): - op.drop_column('notifications', 'status') - op.execute('DROP TYPE notification_status_types') diff --git a/migrations/versions/0040_add_reference.py b/migrations/versions/0040_add_reference.py deleted file mode 100644 index 65a6ad785..000000000 --- a/migrations/versions/0040_add_reference.py +++ /dev/null @@ -1,24 +0,0 @@ -"""empty message - -Revision ID: 0040_add_reference -Revises: 0039_more_notification_states -Create Date: 2016-03-11 09:15:57.900192 - -""" - -# revision identifiers, used by Alembic. -revision = '0040_add_reference' -down_revision = '0039_more_notification_states' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('notifications', sa.Column('reference', sa.String(), nullable=True)) - op.create_index(op.f('ix_notifications_reference'), 'notifications', ['reference'], unique=False) - - -def downgrade(): - op.drop_index(op.f('ix_notifications_reference'), table_name='notifications') - op.drop_column('notifications', 'reference') diff --git a/migrations/versions/0041_platform_admin.py b/migrations/versions/0041_platform_admin.py deleted file mode 100644 index d75c8f5c0..000000000 --- a/migrations/versions/0041_platform_admin.py +++ /dev/null @@ -1,33 +0,0 @@ -"""empty message - -Revision ID: 0041_platform_admin -Revises: 0040_add_reference -Create Date: 2016-03-16 16:33:15.279429 - -""" - -# revision identifiers, used by Alembic. -revision = '0041_platform_admin' -down_revision = '0040_add_reference' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_index(op.f('ix_notification_statistics_service_id'), 'notification_statistics', ['service_id'], unique=False) - op.drop_index('ix_service_notification_stats_service_id', table_name='notification_statistics') - op.add_column('users', sa.Column('platform_admin', sa.Boolean(), nullable=True, default=False)) - op.get_bind() - op.execute('update users set platform_admin = False') - op.alter_column('users', 'platform_admin', nullable=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('users', 'platform_admin') - op.create_index('ix_service_notification_stats_service_id', 'notification_statistics', ['service_id'], unique=False) - op.drop_index(op.f('ix_notification_statistics_service_id'), table_name='notification_statistics') - ### end Alembic commands ### diff --git a/migrations/versions/0042_default_stats_to_zero.py b/migrations/versions/0042_default_stats_to_zero.py deleted file mode 100644 index 4d862c903..000000000 --- a/migrations/versions/0042_default_stats_to_zero.py +++ /dev/null @@ -1,45 +0,0 @@ -"""empty message - -Revision ID: 0042_default_stats_to_zero -Revises: 0041_platform_admin -Create Date: 2016-03-17 11:09:17.906910 - -""" - -# revision identifiers, used by Alembic. -revision = '0042_default_stats_to_zero' -down_revision = '0041_platform_admin' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.get_bind() - op.execute('update notification_statistics set emails_delivered = 0 where emails_delivered is Null') - op.execute('update notification_statistics set emails_error = 0 where emails_error is Null') - op.execute('update notification_statistics set sms_delivered = 0 where sms_delivered is Null') - op.execute('update notification_statistics set sms_error = 0 where sms_error is Null') - op.alter_column('notification_statistics', 'emails_requested', server_default='0') - op.alter_column('notification_statistics', 'emails_delivered', server_default='0', nullable=False) - op.alter_column('notification_statistics', 'emails_error', server_default='0', nullable=False) - op.alter_column('notification_statistics', 'sms_requested', server_default='0') - op.alter_column('notification_statistics', 'sms_delivered', server_default='0', nullable=False) - op.alter_column('notification_statistics', 'sms_error', server_default='0', nullable=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.alter_column('notification_statistics', 'emails_requested', server_default=None) - op.alter_column('notification_statistics', 'emails_delivered', server_default=None, nullable=True) - op.alter_column('notification_statistics', 'emails_error', server_default=None, nullable=True) - op.alter_column('notification_statistics', 'sms_requested', server_default=None) - op.alter_column('notification_statistics', 'sms_delivered', server_default=None, nullable=True) - op.alter_column('notification_statistics', 'sms_error', server_default=None, nullable=True) - op.execute('update notification_statistics set emails_delivered = Null where emails_delivered = 0') - op.execute('update notification_statistics set emails_error = Null where emails_error = 0') - op.execute('update notification_statistics set sms_delivered = Null where sms_delivered = 0') - op.execute('update notification_statistics set sms_error = Null where sms_error = 0') - ### end Alembic commands ### diff --git a/migrations/versions/0043_view_activity.py b/migrations/versions/0043_view_activity.py deleted file mode 100644 index c69089603..000000000 --- a/migrations/versions/0043_view_activity.py +++ /dev/null @@ -1,47 +0,0 @@ -"""empty message - -Revision ID: 0043_add_view_activity -Revises: 0042_default_stats_to_zero -Create Date: 2016-03-29 13:46:36.219549 - -""" - -# revision identifiers, used by Alembic. -import uuid - -revision = '0043_add_view_activity' -down_revision = '0042_default_stats_to_zero' - -from alembic import op - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - conn.execute('COMMIT') - conn.execute("alter type permission_types add value IF NOT EXISTS 'view_activity'") - user_services = conn.execute("SELECT * FROM user_to_service where user_id " - "not in (select user_id from permissions " - "where permission='view_activity')").fetchall() - for user_service in user_services: - conn.execute( - "insert into permissions (id, service_id, user_id, created_at, permission) " - "values('{0}', '{1}', {2}, now(), 'view_activity')".format( - uuid.uuid4(), user_service.service_id, user_service.user_id)) - conn.execute("delete from permissions where permission = 'access_developer_docs'") - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - conn = op.get_bind() - conn.execute("delete from permissions where permission = 'view_activity'") - conn.execute('COMMIT') - conn.execute("alter type permission_types add value IF NOT EXISTS 'access_developer_docs'") - manage_api_key_users = conn.execute("SELECT * FROM permissions where permission='manage_api_keys'").fetchall() - for user_service in manage_api_key_users: - conn.execute( - "insert into permissions (id, service_id, user_id, created_at, permission) " - "values('{0}', '{1}', {2}, now(), 'access_developer_docs')".format( - uuid.uuid4(), user_service.service_id, user_service.user_id)) - ### end Alembic commands ### diff --git a/migrations/versions/0044_add_template_stats.py b/migrations/versions/0044_add_template_stats.py deleted file mode 100644 index d85d8fd72..000000000 --- a/migrations/versions/0044_add_template_stats.py +++ /dev/null @@ -1,42 +0,0 @@ -"""empty message - -Revision ID: 0044_add_template_stats -Revises: 0043_add_view_activity -Create Date: 2016-03-31 12:05:19.630792 - -""" - -# revision identifiers, used by Alembic. -revision = '0044_add_template_stats' -down_revision = '0043_add_view_activity' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.create_table('template_statistics', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('template_id', sa.BigInteger(), nullable=False), - sa.Column('usage_count', sa.BigInteger(), nullable=False), - sa.Column('day', sa.Date(), nullable=False), - sa.ForeignKeyConstraint(['service_id'], ['services.id'], ), - sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_index(op.f('ix_template_statistics_day'), 'template_statistics', ['day'], unique=False) - op.create_index(op.f('ix_template_statistics_service_id'), 'template_statistics', ['service_id'], unique=False) - op.create_index(op.f('ix_template_statistics_template_id'), 'template_statistics', ['template_id'], unique=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_template_statistics_template_id'), table_name='template_statistics') - op.drop_index(op.f('ix_template_statistics_service_id'), table_name='template_statistics') - op.drop_index(op.f('ix_template_statistics_day'), table_name='template_statistics') - op.drop_table('template_statistics') - ### end Alembic commands ### diff --git a/migrations/versions/0045_template_stats_update_timestamp.py b/migrations/versions/0045_template_stats_update_timestamp.py deleted file mode 100644 index fb9d8d0b1..000000000 --- a/migrations/versions/0045_template_stats_update_timestamp.py +++ /dev/null @@ -1,32 +0,0 @@ -"""empty message - -Revision ID: 0045_template_stats_update_time -Revises: 0044_add_template_stats -Create Date: 2016-04-05 14:32:45.165755 - -""" - -# revision identifiers, used by Alembic. -revision = '0045_template_stats_update_time' -down_revision = '0044_add_template_stats' - -import datetime - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.sql import table, column - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('template_statistics', sa.Column('updated_at', sa.DateTime(), nullable=True)) - updated_at = table('template_statistics', column('updated_at')) - op.execute(updated_at.update().values(updated_at=datetime.datetime.utcnow())) - op.alter_column('template_statistics', 'updated_at', nullable=False) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('template_statistics', 'updated_at') - ### end Alembic commands ### diff --git a/migrations/versions/0046_remove_bucketname.py b/migrations/versions/0046_remove_bucketname.py deleted file mode 100644 index d5cfd2377..000000000 --- a/migrations/versions/0046_remove_bucketname.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 0046_remove_bucketname -Revises: 0045_template_stats_update_time -Create Date: 2016-04-07 12:23:55.050714 - -""" - -# revision identifiers, used by Alembic. -revision = '0046_remove_bucketname' -down_revision = '0045_template_stats_update_time' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('jobs', 'file_name') - op.drop_column('jobs', 'bucket_name') - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('jobs', sa.Column('bucket_name', sa.VARCHAR(), autoincrement=False, nullable=False)) - op.add_column('jobs', sa.Column('file_name', sa.VARCHAR(), autoincrement=False, nullable=False)) - ### end Alembic commands ### diff --git a/tests/app/authentication/test_authentication.py b/tests/app/authentication/test_authentication.py index 147d8ffb1..bbf706db4 100644 --- a/tests/app/authentication/test_authentication.py +++ b/tests/app/authentication/test_authentication.py @@ -133,7 +133,7 @@ def test_should_allow_valid_token_with_post_body(notify_api, sample_api_key): 'email_from': 'new name', 'name': 'new name', 'users': [service.users[0].id], - 'limit': 1000, + 'message_limit': 1000, 'restricted': False, 'active': False} diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 2f8fe5da0..04d32a5f8 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -307,7 +307,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat assert persisted_notification.id == notification_id assert persisted_notification.to == '+447234123123' assert persisted_notification.template_id == sample_template_with_placeholders.id - assert persisted_notification.status == 'sent' + assert persisted_notification.status == 'sending' assert persisted_notification.created_at == now assert persisted_notification.sent_at > now assert persisted_notification.sent_by == 'MMG' @@ -481,7 +481,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sa assert persisted_notification.to == '+447234123123' assert persisted_notification.job_id == sample_job.id assert persisted_notification.template_id == sample_job.template.id - assert persisted_notification.status == 'sent' + assert persisted_notification.status == 'sending' assert persisted_notification.sent_at > now assert persisted_notification.created_at == now assert persisted_notification.sent_by == 'MMG' @@ -522,7 +522,7 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh assert persisted_notification.template_id == sample_email_template_with_placeholders.id assert persisted_notification.created_at == now assert persisted_notification.sent_at > now - assert persisted_notification.status == 'sent' + assert persisted_notification.status == 'sending' assert persisted_notification.sent_by == 'ses' diff --git a/tests/app/clients/test_aws_ses.py b/tests/app/clients/test_aws_ses.py index 4ed02f9ac..4d6560b87 100644 --- a/tests/app/clients/test_aws_ses.py +++ b/tests/app/clients/test_aws_ses.py @@ -14,7 +14,7 @@ def test_should_return_correct_details_for_delivery(): def test_should_return_correct_details_for_bounced(): response_dict = get_aws_responses('Bounce') assert response_dict['message'] == 'Bounced' - assert response_dict['notification_status'] == 'bounce' + assert response_dict['notification_status'] == 'failed' assert response_dict['notification_statistics_status'] == 'failure' assert not response_dict['success'] @@ -22,9 +22,9 @@ def test_should_return_correct_details_for_bounced(): def test_should_return_correct_details_for_complaint(): response_dict = get_aws_responses('Complaint') assert response_dict['message'] == 'Complaint' - assert response_dict['notification_status'] == 'complaint' - assert response_dict['notification_statistics_status'] == 'failure' - assert not response_dict['success'] + assert response_dict['notification_status'] == 'delivered' + assert response_dict['notification_statistics_status'] == 'delivered' + assert response_dict['success'] def test_should_be_none_if_unrecognised_status_code(): diff --git a/tests/app/clients/test_firetext.py b/tests/app/clients/test_firetext.py index ba35762fc..75586dbed 100644 --- a/tests/app/clients/test_firetext.py +++ b/tests/app/clients/test_firetext.py @@ -22,9 +22,9 @@ def test_should_return_correct_details_for_bounced(): def test_should_return_correct_details_for_complaint(): response_dict = get_firetext_responses('2') assert response_dict['message'] == 'Undelivered (Pending with Network)' - assert response_dict['notification_status'] == 'sent' - assert not response_dict['notification_statistics_status'] - assert not response_dict['success'] + assert response_dict['notification_status'] == 'delivered' + assert response_dict['notification_statistics_status'] == 'delivered' + assert response_dict['success'] def test_should_be_none_if_unrecognised_status_code(): diff --git a/tests/app/conftest.py b/tests/app/conftest.py index fa67cb573..1fde778e1 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -112,7 +112,7 @@ def sample_service(notify_db, user = sample_user(notify_db, notify_db_session) data = { 'name': service_name, - 'limit': limit, + 'message_limit': limit, 'active': False, 'restricted': restricted, 'email_from': email_from @@ -285,7 +285,7 @@ def sample_notification(notify_db, template=None, job=None, to_field=None, - status='sent', + status='sending', reference=None, created_at=datetime.utcnow()): if service is None: @@ -421,3 +421,8 @@ def sample_service_permission(notify_db, db.session.add(p_model) db.session.commit() return p_model + + +@pytest.fixture(scope='function') +def fake_uuid(): + return "6ce466d0-fd6a-11e5-82f5-e0accb9d11a6" diff --git a/tests/app/dao/test_api_key_dao.py b/tests/app/dao/test_api_key_dao.py index fbb33e517..b70bb2172 100644 --- a/tests/app/dao/test_api_key_dao.py +++ b/tests/app/dao/test_api_key_dao.py @@ -42,10 +42,13 @@ def test_save_api_key_should_update_the_api_key(notify_api, notify_db, notify_db assert all_api_keys[0].service_id == saved_api_key.service_id -def test_get_api_key_should_raise_exception_when_api_key_does_not_exist(notify_api, notify_db, notify_db_session, - sample_service): +def test_get_api_key_should_raise_exception_when_api_key_does_not_exist(notify_api, + notify_db, + notify_db_session, + sample_service, + fake_uuid): try: - get_model_api_keys(sample_service.id, id=123) + get_model_api_keys(sample_service.id, id=fake_uuid) fail("Should have thrown a NoResultFound exception") except NoResultFound: pass @@ -78,9 +81,10 @@ def test_get_unsigned_secret_returns_key(notify_api, def test_should_not_allow_duplicate_key_names_per_service(notify_api, notify_db, notify_db_session, - sample_api_key): + sample_api_key, + fake_uuid): api_key = ApiKey( - **{'id': sample_api_key.id + 1, 'service_id': sample_api_key.service_id, 'name': sample_api_key.name}) + **{'id': fake_uuid, 'service_id': sample_api_key.service_id, 'name': sample_api_key.name}) try: save_model_api_key(api_key) fail("should throw IntegrityError") diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index acbc633ae..b9ffc73d4 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -56,7 +56,7 @@ def test_should_by_able_to_update_status_by_reference(sample_email_template): notification = Notification(**data) dao_create_notification(notification, sample_email_template.template_type) - assert Notification.query.get(notification.id).status == "sent" + assert Notification.query.get(notification.id).status == "sending" update_notification_reference_by_id(notification.id, 'reference') update_notification_status_by_reference('reference', 'delivered', 'delivered') assert Notification.query.get(notification.id).status == 'delivered' @@ -68,11 +68,11 @@ def test_should_by_able_to_update_status_by_reference(sample_email_template): ).one().emails_requested == 1 assert NotificationStatistics.query.filter_by( service_id=sample_email_template.service.id - ).one().emails_error == 0 + ).one().emails_failed == 0 def test_should_by_able_to_update_status_by_id(sample_notification): - assert Notification.query.get(sample_notification.id).status == 'sent' + assert Notification.query.get(sample_notification.id).status == 'sending' count = update_notification_status_by_id(sample_notification.id, 'delivered', 'delivered') assert count == 1 assert Notification.query.get(sample_notification.id).status == 'delivered' @@ -84,11 +84,11 @@ def test_should_by_able_to_update_status_by_id(sample_notification): ).one().sms_requested == 1 assert NotificationStatistics.query.filter_by( service_id=sample_notification.service.id - ).one().sms_error == 0 + ).one().sms_failed == 0 def test_should_be_able_to_record_statistics_failure_for_sms(sample_notification): - assert Notification.query.get(sample_notification.id).status == 'sent' + assert Notification.query.get(sample_notification.id).status == 'sending' count = update_notification_status_by_id(sample_notification.id, 'delivered', 'failure') assert count == 1 assert Notification.query.get(sample_notification.id).status == 'delivered' @@ -100,7 +100,7 @@ def test_should_be_able_to_record_statistics_failure_for_sms(sample_notification ).one().sms_requested == 1 assert NotificationStatistics.query.filter_by( service_id=sample_notification.service.id - ).one().sms_error == 1 + ).one().sms_failed == 1 def test_should_be_able_to_record_statistics_failure_for_email(sample_email_template): @@ -117,9 +117,9 @@ def test_should_be_able_to_record_statistics_failure_for_email(sample_email_temp dao_create_notification(notification, sample_email_template.template_type) update_notification_reference_by_id(notification.id, 'reference') - count = update_notification_status_by_reference('reference', 'bounce', 'failure') + count = update_notification_status_by_reference('reference', 'failed', 'failure') assert count == 1 - assert Notification.query.get(notification.id).status == 'bounce' + assert Notification.query.get(notification.id).status == 'failed' assert NotificationStatistics.query.filter_by( service_id=notification.service.id ).one().emails_delivered == 0 @@ -128,7 +128,7 @@ def test_should_be_able_to_record_statistics_failure_for_email(sample_email_temp ).one().emails_requested == 1 assert NotificationStatistics.query.filter_by( service_id=notification.service.id - ).one().emails_error == 1 + ).one().emails_failed == 1 def test_should_return_zero_count_if_no_notification_with_id(): @@ -157,12 +157,12 @@ def test_should_be_able_to_get_statistics_for_a_service(sample_template): assert stats[0].emails_requested == 0 assert stats[0].sms_requested == 1 assert stats[0].sms_delivered == 0 - assert stats[0].sms_error == 0 + assert stats[0].sms_failed == 0 assert stats[0].day == notification.created_at.strftime(DATE_FORMAT) assert stats[0].service_id == notification.service_id assert stats[0].emails_requested == 0 assert stats[0].emails_delivered == 0 - assert stats[0].emails_error == 0 + assert stats[0].emails_failed == 0 def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_template): @@ -182,10 +182,10 @@ def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_templat sample_template.service.id, now.strftime(DATE_FORMAT) ) assert stat.emails_requested == 0 - assert stat.emails_error == 0 + assert stat.emails_failed == 0 assert stat.emails_delivered == 0 assert stat.sms_requested == 1 - assert stat.sms_error == 0 + assert stat.sms_failed == 0 assert stat.sms_delivered == 0 assert stat.day == notification.created_at.strftime(DATE_FORMAT) assert stat.service_id == notification.service_id @@ -303,7 +303,7 @@ def test_save_notification_creates_sms_and_template_stats(sample_template, sampl assert data['service'] == notification_from_db.service assert data['template'] == notification_from_db.template assert data['created_at'] == notification_from_db.created_at - assert 'sent' == notification_from_db.status + assert 'sending' == notification_from_db.status assert Job.query.get(sample_job.id).notifications_sent == 1 stats = NotificationStatistics.query.filter( @@ -348,7 +348,7 @@ def test_save_notification_and_create_email_and_template_stats(sample_email_temp assert data['service'] == notification_from_db.service assert data['template'] == notification_from_db.template assert data['created_at'] == notification_from_db.created_at - assert 'sent' == notification_from_db.status + assert 'sending' == notification_from_db.status assert Job.query.get(sample_job.id).notifications_sent == 1 stats = NotificationStatistics.query.filter( @@ -537,7 +537,7 @@ def test_save_notification_and_increment_job(sample_template, sample_job): assert data['service'] == notification_from_db.service assert data['template'] == notification_from_db.template assert data['created_at'] == notification_from_db.created_at - assert 'sent' == notification_from_db.status + assert 'sending' == notification_from_db.status assert Job.query.get(sample_job.id).notifications_sent == 1 notification_2 = Notification(**data) @@ -603,7 +603,7 @@ def test_save_notification_and_increment_correct_job(notify_db, notify_db_sessio assert data['service'] == notification_from_db.service assert data['template'] == notification_from_db.template assert data['created_at'] == notification_from_db.created_at - assert 'sent' == notification_from_db.status + assert 'sending' == notification_from_db.status assert Job.query.get(job_1.id).notifications_sent == 1 assert Job.query.get(job_2.id).notifications_sent == 0 @@ -629,7 +629,7 @@ def test_save_notification_with_no_job(sample_template): assert data['service'] == notification_from_db.service assert data['template'] == notification_from_db.template assert data['created_at'] == notification_from_db.created_at - assert 'sent' == notification_from_db.status + assert 'sending' == notification_from_db.status def test_get_notification(sample_notification): @@ -660,7 +660,7 @@ def test_save_notification_no_job_id(sample_template): assert data['to'] == notification_from_db.to assert data['service'] == notification_from_db.service assert data['template'] == notification_from_db.template - assert 'sent' == notification_from_db.status + assert 'sending' == notification_from_db.status def test_get_notification_for_job(sample_notification): @@ -694,7 +694,7 @@ def test_get_all_notifications_for_job(notify_db, notify_db_session, sample_job) def test_update_notification(sample_notification, sample_template): - assert sample_notification.status == 'sent' + assert sample_notification.status == 'sending' sample_notification.status = 'failed' dao_update_notification(sample_notification) notification_from_db = Notification.query.get(sample_notification.id) @@ -706,7 +706,7 @@ def test_should_delete_notifications_after_one_day(notify_db, notify_db_session) sample_notification(notify_db, notify_db_session, created_at=created_at) sample_notification(notify_db, notify_db_session, created_at=created_at) assert len(Notification.query.all()) == 2 - delete_notifications_created_more_than_a_day_ago('sent') + delete_notifications_created_more_than_a_day_ago('sending') assert len(Notification.query.all()) == 0 @@ -726,7 +726,7 @@ def test_should_not_delete_sent_notifications_before_one_day(notify_db, notify_d sample_notification(notify_db, notify_db_session, created_at=valid, to_field="valid") assert len(Notification.query.all()) == 2 - delete_notifications_created_more_than_a_day_ago('sent') + delete_notifications_created_more_than_a_day_ago('sending') assert len(Notification.query.all()) == 1 assert Notification.query.first().to == 'valid' diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 140256686..65ab67830 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -17,7 +17,7 @@ from sqlalchemy.exc import IntegrityError def test_create_service(sample_user): assert Service.query.count() == 0 - service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False) + service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False) dao_create_service(service, sample_user) assert Service.query.count() == 1 assert Service.query.first().name == "service_name" @@ -27,8 +27,8 @@ def test_create_service(sample_user): def test_cannot_create_two_services_with_same_name(sample_user): assert Service.query.count() == 0 - service1 = Service(name="service_name", email_from="email_from1", limit=1000, active=True, restricted=False) - service2 = Service(name="service_name", email_from="email_from2", limit=1000, active=True, restricted=False) + service1 = Service(name="service_name", email_from="email_from1", message_limit=1000, active=True, restricted=False) + service2 = Service(name="service_name", email_from="email_from2", message_limit=1000, active=True, restricted=False) with pytest.raises(IntegrityError) as excinfo: dao_create_service(service1, sample_user) dao_create_service(service2, sample_user) @@ -37,8 +37,8 @@ def test_cannot_create_two_services_with_same_name(sample_user): def test_cannot_create_two_services_with_same_email_from(sample_user): assert Service.query.count() == 0 - service1 = Service(name="service_name1", email_from="email_from", limit=1000, active=True, restricted=False) - service2 = Service(name="service_name2", email_from="email_from", limit=1000, active=True, restricted=False) + service1 = Service(name="service_name1", email_from="email_from", message_limit=1000, active=True, restricted=False) + service2 = Service(name="service_name2", email_from="email_from", message_limit=1000, active=True, restricted=False) with pytest.raises(IntegrityError) as excinfo: dao_create_service(service1, sample_user) dao_create_service(service2, sample_user) @@ -47,14 +47,14 @@ def test_cannot_create_two_services_with_same_email_from(sample_user): def test_cannot_create_service_with_no_user(notify_db_session): assert Service.query.count() == 0 - service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False) + service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False) with pytest.raises(FlushError) as excinfo: dao_create_service(service, None) assert "Can't flush None value found in collection Service.users" in str(excinfo.value) def test_should_add_user_to_service(sample_user): - service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False) + service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False) dao_create_service(service, sample_user) assert sample_user in Service.query.first().users new_user = User( @@ -69,7 +69,7 @@ def test_should_add_user_to_service(sample_user): def test_should_remove_user_from_service(sample_user): - service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False) + service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False) dao_create_service(service, sample_user) new_user = User( name='Test User', diff --git a/tests/app/dao/test_templates_dao.py b/tests/app/dao/test_templates_dao.py index e534271cb..2c680fac3 100644 --- a/tests/app/dao/test_templates_dao.py +++ b/tests/app/dao/test_templates_dao.py @@ -42,20 +42,6 @@ def test_create_email_template(sample_service): assert dao_get_all_templates_for_service(sample_service.id)[0].name == 'Sample Template' -def test_create_email_template_fails_if_no_subject(sample_service): - data = { - 'name': 'Sample Template', - 'template_type': "email", - 'content': "Template content", - 'service': sample_service - } - template = Template(**data) - - with pytest.raises(IntegrityError) as e: - dao_create_template(template) - assert 'new row for relation "templates" violates check constraint "ch_email_template_has_subject"' in str(e.value) - - def test_update_template(sample_service): data = { 'name': 'Sample Template', @@ -158,7 +144,7 @@ def test_get_template_by_id_and_service(notify_db, notify_db_session, sample_ser assert Template.query.count() == 1 -def test_get_template_by_id_and_service_returns_none_if_no_template(sample_service): +def test_get_template_by_id_and_service_returns_none_if_no_template(sample_service, fake_uuid): with pytest.raises(NoResultFound) as e: - dao_get_template_by_id_and_service_id(template_id=999, service_id=sample_service.id) + dao_get_template_by_id_and_service_id(template_id=fake_uuid, service_id=sample_service.id) assert 'No row was found for one' in str(e.value) diff --git a/tests/app/dao/test_users_dao.py b/tests/app/dao/test_users_dao.py index 35dce1b60..2a36bf1ba 100644 --- a/tests/app/dao/test_users_dao.py +++ b/tests/app/dao/test_users_dao.py @@ -54,9 +54,9 @@ def test_get_user(notify_api, notify_db, notify_db_session): assert get_model_users(user_id=another_user.id).email_address == email -def test_get_user_not_exists(notify_api, notify_db, notify_db_session): +def test_get_user_not_exists(notify_api, notify_db, notify_db_session, fake_uuid): try: - get_model_users(user_id="12345") + get_model_users(user_id=fake_uuid) pytest.fail("NoResultFound exception not thrown.") except NoResultFound as e: pass diff --git a/tests/app/invite/test_invite_rest.py b/tests/app/invite/test_invite_rest.py index 78c6223d4..4f2ad9b69 100644 --- a/tests/app/invite/test_invite_rest.py +++ b/tests/app/invite/test_invite_rest.py @@ -19,7 +19,7 @@ def test_create_invited_user(notify_api, sample_service, mocker): data = { 'service': str(sample_service.id), 'email_address': email_address, - 'from_user': invite_from.id, + 'from_user': str(invite_from.id), 'permissions': 'send_messages,manage_service,manage_api_keys' } @@ -41,7 +41,7 @@ def test_create_invited_user(notify_api, sample_service, mocker): assert json_resp['data']['service'] == str(sample_service.id) assert json_resp['data']['email_address'] == email_address - assert json_resp['data']['from_user'] == invite_from.id + assert json_resp['data']['from_user'] == str(invite_from.id) assert json_resp['data']['permissions'] == 'send_messages,manage_service,manage_api_keys' assert json_resp['data']['id'] invitation_expiration_days = notify_api.config['INVITATION_EXPIRATION_DAYS'] @@ -70,7 +70,7 @@ def test_create_invited_user_invalid_email(notify_api, sample_service, mocker): data = { 'service': str(sample_service.id), 'email_address': email_address, - 'from_user': invite_from.id, + 'from_user': str(invite_from.id), 'permissions': 'send_messages,manage_service,manage_api_keys' } @@ -128,7 +128,7 @@ def test_get_all_invited_users_by_service(notify_api, notify_db, notify_db_sessi for invite in json_resp['data']: assert invite['service'] == str(sample_service.id) - assert invite['from_user'] == invite_from.id + assert invite['from_user'] == str(invite_from.id) assert invite['id'] @@ -176,7 +176,7 @@ def test_get_invited_user_by_service_and_id(notify_api, sample_service, sample_i assert json_resp['data']['service'] == str(sample_service.id) assert json_resp['data']['email_address'] == invite_email_address - assert json_resp['data']['from_user'] == invite_from.id + assert json_resp['data']['from_user'] == str(invite_from.id) assert json_resp['data']['id'] @@ -218,12 +218,11 @@ def test_update_invited_user_set_status_to_cancelled(notify_api, sample_invited_ assert json_resp['status'] == 'cancelled' -def test_update_invited_user_for_wrong_service_returns_404(notify_api, sample_invited_user): +def test_update_invited_user_for_wrong_service_returns_404(notify_api, sample_invited_user, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: data = {'status': 'cancelled'} - bad_service_id = uuid.uuid4() - url = '/service/{0}/invite/{1}'.format(bad_service_id, sample_invited_user.id) + url = '/service/{0}/invite/{1}'.format(fake_uuid, sample_invited_user.id) auth_header = create_authorization_header( path=url, method='POST', diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index c2468fa8a..a604a346f 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -54,12 +54,11 @@ def test_get_job_with_invalid_job_id_returns404(notify_api, sample_template): assert resp_json['message'] == 'No result found' -def test_get_job_with_unknown_id_returns404(notify_api, sample_template): - random_id = str(uuid.uuid4()) +def test_get_job_with_unknown_id_returns404(notify_api, sample_template, fake_uuid): service_id = sample_template.service.id with notify_api.test_request_context(): with notify_api.test_client() as client: - path = '/service/{}/job/{}'.format(service_id, random_id) + path = '/service/{}/job/{}'.format(service_id, fake_uuid) auth_header = create_authorization_header( service_id=sample_template.service.id, path=path, @@ -89,15 +88,14 @@ def test_get_job_by_id(notify_api, sample_job): assert resp_json['data']['id'] == job_id -def test_create_job(notify_api, sample_template, mocker): +def test_create_job(notify_api, sample_template, mocker, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: mocker.patch('app.celery.tasks.process_job.apply_async') - job_id = uuid.uuid4() data = { - 'id': str(job_id), + 'id': fake_uuid, 'service': str(sample_template.service.id), - 'template': sample_template.id, + 'template': str(sample_template.id), 'original_file_name': 'thisisatest.csv', 'notification_count': 1 } @@ -115,15 +113,15 @@ def test_create_job(notify_api, sample_template, mocker): assert response.status_code == 201 app.celery.tasks.process_job.apply_async.assert_called_once_with( - ([str(job_id)]), + ([str(fake_uuid)]), queue="process-job" ) resp_json = json.loads(response.get_data(as_text=True)) - assert resp_json['data']['id'] == str(job_id) + assert resp_json['data']['id'] == fake_uuid assert resp_json['data']['service'] == str(sample_template.service.id) - assert resp_json['data']['template'] == sample_template.id + assert resp_json['data']['template'] == str(sample_template.id) assert resp_json['data']['original_file_name'] == 'thisisatest.csv' diff --git a/tests/app/notifications/test_process_client_response.py b/tests/app/notifications/test_process_client_response.py index 169161e6e..8e4e1580a 100644 --- a/tests/app/notifications/test_process_client_response.py +++ b/tests/app/notifications/test_process_client_response.py @@ -58,7 +58,7 @@ def test_process_sms_response_updates_notification_stats_for_valid_request(notif assert len(stats) == 1 assert stats[0].sms_requested == 1 assert stats[0].sms_delivered == 0 - assert stats[0].sms_error == 0 + assert stats[0].sms_failed == 0 success, error = process_sms_client_response(status='0', reference=str(sample_notification.id), client_name='Firetext') assert error is None @@ -67,7 +67,7 @@ def test_process_sms_response_updates_notification_stats_for_valid_request(notif assert len(stats) == 1 assert stats[0].sms_requested == 1 assert stats[0].sms_delivered == 1 - assert stats[0].sms_error == 0 + assert stats[0].sms_failed == 0 def test_process_sms_response_updates_notification_stats_for_valid_request_with_failed_status(notify_api, @@ -79,7 +79,7 @@ def test_process_sms_response_updates_notification_stats_for_valid_request_with_ assert len(stats) == 1 assert stats[0].sms_requested == 1 assert stats[0].sms_delivered == 0 - assert stats[0].sms_error == 0 + assert stats[0].sms_failed == 0 success, error = process_sms_client_response(status='1', reference=str(sample_notification.id), client_name='Firetext') assert success == "{} callback succeeded. reference {} updated".format('Firetext', sample_notification.id) @@ -88,4 +88,4 @@ def test_process_sms_response_updates_notification_stats_for_valid_request_with_ assert len(stats) == 1 assert stats[0].sms_requested == 1 assert stats[0].sms_delivered == 0 - assert stats[0].sms_error == 1 + assert stats[0].sms_failed == 1 diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index f4226a656..9bc5813a4 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -28,9 +28,9 @@ def test_get_notification_by_id(notify_api, sample_notification): headers=[auth_header]) notification = json.loads(response.get_data(as_text=True))['data']['notification'] - assert notification['status'] == 'sent' + assert notification['status'] == 'sending' assert notification['template'] == { - 'id': sample_notification.template.id, + 'id': str(sample_notification.template.id), 'name': sample_notification.template.name, 'template_type': sample_notification.template.template_type} assert notification['job'] == { @@ -74,9 +74,9 @@ def test_get_all_notifications(notify_api, sample_notification): headers=[auth_header]) notifications = json.loads(response.get_data(as_text=True)) - assert notifications['notifications'][0]['status'] == 'sent' + assert notifications['notifications'][0]['status'] == 'sending' assert notifications['notifications'][0]['template'] == { - 'id': sample_notification.template.id, + 'id': str(sample_notification.template.id), 'name': sample_notification.template.name, 'template_type': sample_notification.template.template_type} assert notifications['notifications'][0]['job'] == { @@ -400,13 +400,13 @@ def test_filter_by_multiple_statuss(notify_api, method='GET') response = client.get( - '/notifications?status=delivered&status=sent', + '/notifications?status=delivered&status=sending', headers=[auth_header]) assert response.status_code == 200 notifications = json.loads(response.get_data(as_text=True)) assert len(notifications['notifications']) == 2 - set(['delivered', 'sent']) == set( + set(['delivered', 'sending']) == set( [x['status'] for x in notifications['notifications']]) @@ -504,14 +504,14 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker): assert response.status_code == 400 -def test_send_notification_invalid_template_id(notify_api, sample_template, mocker): +def test_send_notification_invalid_template_id(notify_api, sample_template, mocker, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: mocker.patch('app.celery.tasks.send_sms.apply_async') data = { 'to': '+447700900855', - 'template': 9999 + 'template': fake_uuid } auth_header = create_authorization_header( service_id=sample_template.service.id, @@ -707,7 +707,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker data = { 'to': '07700 900 855', - 'template': sample_template.id + 'template': str(sample_template.id) } auth_header = create_authorization_header( @@ -767,7 +767,7 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai to_address = "bad-email" data = { 'to': to_address, - 'template': sample_email_template.service.id + 'template': str(sample_email_template.service.id) } auth_header = create_authorization_header( service_id=sample_email_template.service.id, @@ -788,13 +788,13 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai def test_should_reject_email_notification_with_template_id_that_cant_be_found( - notify_api, sample_email_template, mocker): + notify_api, sample_email_template, mocker, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: mocker.patch('app.celery.tasks.send_email.apply_async') data = { 'to': 'ok@ok.com', - 'template': 1234 + 'template': fake_uuid } auth_header = create_authorization_header( service_id=sample_email_template.service.id, @@ -829,7 +829,7 @@ def test_should_not_allow_email_template_from_another_service(notify_api, servic data = { 'to': sample_user.email_address, - 'template': service_2_templates[0].id + 'template': str(service_2_templates[0].id) } auth_header = create_authorization_header( @@ -861,7 +861,7 @@ def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api, data = { 'to': "not-someone-we-trust@email-address.com", - 'template': sample_email_template.id + 'template': str(sample_email_template.id) } auth_header = create_authorization_header( @@ -896,8 +896,8 @@ def test_should_not_send_email_for_job_if_restricted_and_not_a_service_user( data = { 'to': "not-someone-we-trust@email-address.com", - 'template': sample_job.template.id, - 'job': sample_job.id + 'template': str(sample_job.template.id), + 'job': (sample_job.id) } auth_header = create_authorization_header( @@ -927,7 +927,7 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template data = { 'to': 'ok@ok.com', - 'template': sample_email_template.id + 'template': str(sample_email_template.id) } auth_header = create_authorization_header( @@ -971,7 +971,7 @@ def test_should_block_api_call_if_over_day_limit(notify_db, notify_db_session, n data = { 'to': 'ok@ok.com', - 'template': email_template.id + 'template': str(email_template.id) } auth_header = create_authorization_header( @@ -1001,13 +1001,13 @@ def test_no_limit_for_live_service(notify_api, with notify_api.test_request_context(): with notify_api.test_client() as client: - sample_service.limit = 1 + sample_service.message_limit = 1 notify_db.session.add(sample_service) notify_db.session.commit() data = { 'to': 'ok@ok.com', - 'template': sample_email_template.id + 'template': str(sample_email_template.id) } auth_header = create_authorization_header( @@ -1041,7 +1041,7 @@ def test_should_block_api_call_if_over_day_limit_regardless_of_type(notify_db, n data = { 'to': '+447234123123', - 'template': sms_template.id + 'template': str(sms_template.id) } auth_header = create_authorization_header( @@ -1074,7 +1074,7 @@ def test_should_allow_api_call_if_under_day_limit_regardless_of_type(notify_db, data = { 'to': '+447634123123', - 'template': sms_template.id + 'template': str(sms_template.id) } auth_header = create_authorization_header( @@ -1211,7 +1211,7 @@ def test_firetext_callback_should_update_notification_status(notify_api, sample_ with notify_api.test_request_context(): with notify_api.test_client() as client: original = get_notification_by_id(sample_notification.id) - assert original.status == 'sent' + assert original.status == 'sending' response = client.post( path='/notifications/sms/firetext', @@ -1231,14 +1231,14 @@ def test_firetext_callback_should_update_notification_status(notify_api, sample_ assert get_notification_by_id(sample_notification.id).status == 'delivered' assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_delivered == 1 assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_requested == 1 - assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_error == 0 + assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_failed == 0 def test_firetext_callback_should_update_notification_status_failed(notify_api, sample_notification): with notify_api.test_request_context(): with notify_api.test_client() as client: original = get_notification_by_id(sample_notification.id) - assert original.status == 'sent' + assert original.status == 'sending' response = client.post( path='/notifications/sms/firetext', @@ -1257,7 +1257,7 @@ def test_firetext_callback_should_update_notification_status_failed(notify_api, assert updated.status == 'failed' assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_delivered == 0 assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_requested == 1 - assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_error == 1 + assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_failed == 1 def test_firetext_callback_should_update_notification_status_sent(notify_api, notify_db, notify_db_session): @@ -1275,16 +1275,17 @@ def test_firetext_callback_should_update_notification_status_sent(notify_api, no headers=[('Content-Type', 'application/x-www-form-urlencoded')]) json_resp = json.loads(response.get_data(as_text=True)) + print(json_resp) assert response.status_code == 200 assert json_resp['result'] == 'success' assert json_resp['message'] == 'Firetext callback succeeded. reference {} updated'.format( notification.id ) updated = get_notification_by_id(notification.id) - assert updated.status == 'sent' - assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_delivered == 0 + assert updated.status == 'delivered' + assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_delivered == 1 assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_requested == 1 - assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_error == 0 + assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_failed == 0 def test_firetext_callback_should_update_multiple_notification_status_sent(notify_api, notify_db, notify_db_session): @@ -1317,7 +1318,7 @@ def test_firetext_callback_should_update_multiple_notification_status_sent(notif assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_delivered == 3 assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_requested == 3 - assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_error == 0 + assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_failed == 0 def test_process_mmg_response_return_200_when_cid_is_send_sms_code(notify_api): @@ -1458,7 +1459,7 @@ def test_ses_callback_should_update_notification_status( reference='ref' ) - assert get_notification_by_id(notification.id).status == 'sent' + assert get_notification_by_id(notification.id).status == 'sending' response = client.post( path='/notifications/email/ses', @@ -1472,7 +1473,7 @@ def test_ses_callback_should_update_notification_status( assert get_notification_by_id(notification.id).status == 'delivered' assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_delivered == 1 assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_requested == 1 - assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_error == 0 + assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_failed == 0 def test_ses_callback_should_update_multiple_notification_status_sent( @@ -1527,7 +1528,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent( assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_delivered == 3 assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_requested == 3 - assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_error == 0 + assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_failed == 0 def test_should_handle_invite_email_callbacks(notify_api, notify_db, notify_db_session): diff --git a/tests/app/permissions/test_rest.py b/tests/app/permissions/test_rest.py index 79fadd20c..16787bb6d 100644 --- a/tests/app/permissions/test_rest.py +++ b/tests/app/permissions/test_rest.py @@ -22,7 +22,7 @@ def test_get_permission_list(notify_api, notify_db, notify_db_session, sample_pe assert len(json_resp['data']) == 1 expected = { "permission": sample_permission.permission, - "user": sample_permission.user.id, + "user": str(sample_permission.user.id), "id": str(sample_permission.id), "service": None } @@ -52,7 +52,7 @@ def test_get_permission_filter(notify_api, service_id=str(sample_service.id)).first() expected = { "permission": another_permission.permission, - "user": sample_user.id, + "user": str(sample_user.id), "id": str(another_permission.id), "service": str(sample_service.id) } @@ -75,7 +75,7 @@ def test_get_permission(notify_api, notify_db, notify_db_session, sample_permiss json_resp = json.loads(response.get_data(as_text=True)) expected = { "permission": sample_permission.permission, - "user": sample_permission.user.id, + "user": str(sample_permission.user.id), "id": str(sample_permission.id), "service": None } diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 60f1ed3cd..31641097a 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -177,8 +177,8 @@ def test_create_service(notify_api, sample_user): with notify_api.test_client() as client: data = { 'name': 'created service', - 'user_id': sample_user.id, - 'limit': 1000, + 'user_id': str(sample_user.id), + 'message_limit': 1000, 'restricted': False, 'active': False, 'email_from': 'created.service'} @@ -218,7 +218,7 @@ def test_should_not_create_service_with_missing_user_id_field(notify_api): data = { 'email_from': 'service', 'name': 'created service', - 'limit': 1000, + 'message_limit': 1000, 'restricted': False, 'active': False } @@ -238,14 +238,17 @@ def test_should_not_create_service_with_missing_user_id_field(notify_api): assert 'Missing data for required field.' in json_resp['message']['user_id'] -def test_should_not_create_service_with_missing_if_user_id_is_not_in_database(notify_api, notify_db, notify_db_session): +def test_should_not_create_service_with_missing_if_user_id_is_not_in_database(notify_api, + notify_db, + notify_db_session, + fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: data = { 'email_from': 'service', - 'user_id': 1234, + 'user_id': fake_uuid, 'name': 'created service', - 'limit': 1000, + 'message_limit': 1000, 'restricted': False, 'active': False } @@ -269,7 +272,7 @@ def test_should_not_create_service_if_missing_data(notify_api, sample_user): with notify_api.test_request_context(): with notify_api.test_client() as client: data = { - 'user_id': sample_user.id + 'user_id': str(sample_user.id) } auth_header = create_authorization_header( path='/service', @@ -286,7 +289,7 @@ def test_should_not_create_service_if_missing_data(notify_api, sample_user): assert json_resp['result'] == 'error' assert 'Missing data for required field.' in json_resp['message']['name'] assert 'Missing data for required field.' in json_resp['message']['active'] - assert 'Missing data for required field.' in json_resp['message']['limit'] + assert 'Missing data for required field.' in json_resp['message']['message_limit'] assert 'Missing data for required field.' in json_resp['message']['restricted'] @@ -299,8 +302,8 @@ def test_should_not_create_service_with_duplicate_name(notify_api, with notify_api.test_client() as client: data = { 'name': sample_service.name, - 'user_id': sample_service.users[0].id, - 'limit': 1000, + 'user_id': str(sample_service.users[0].id), + 'message_limit': 1000, 'restricted': False, 'active': False, 'email_from': 'sample.service2'} @@ -327,8 +330,8 @@ def test_create_service_should_throw_duplicate_key_constraint_for_existing_email with notify_api.test_client() as client: data = { 'name': 'First SERVICE', - 'user_id': first_service.users[0].id, - 'limit': 1000, + 'user_id': str(first_service.users[0].id), + 'message_limit': 1000, 'restricted': False, 'active': False, 'email_from': 'first.service'} @@ -543,8 +546,8 @@ def test_default_permissions_are_added_for_user_service(notify_api, with notify_api.test_client() as client: data = { 'name': 'created service', - 'user_id': sample_user.id, - 'limit': 1000, + 'user_id': str(sample_user.id), + 'message_limit': 1000, 'restricted': False, 'active': False, 'email_from': 'created.service'} @@ -650,7 +653,7 @@ def test_add_existing_user_to_another_service_with_all_permissions(notify_api, ) assert resp.status_code == 200 json_resp = json.loads(resp.get_data(as_text=True)) - assert user_to_add.id in json_resp['data']['users'] + assert str(user_to_add.id) in json_resp['data']['users'] # check user has all permissions auth_header = create_authorization_header( diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index fbb3cd6d2..13551afa9 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -67,25 +67,24 @@ def test_should_create_a_new_email_template_for_a_service(notify_api, sample_ser assert json_resp['data']['id'] -def test_should_be_error_if_service_does_not_exist_on_create(notify_api): +def test_should_be_error_if_service_does_not_exist_on_create(notify_api, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: - bad_id = str(uuid.uuid4()) data = { 'name': 'my template', 'template_type': 'sms', 'content': 'template content', - 'service': bad_id + 'service': fake_uuid } data = json.dumps(data) auth_header = create_authorization_header( - path='/service/{}/template'.format(bad_id), + path='/service/{}/template'.format(fake_uuid), method='POST', request_body=data ) response = client.post( - '/service/{}/template'.format(bad_id), + '/service/{}/template'.format(fake_uuid), headers=[('Content-Type', 'application/json'), auth_header], data=data ) @@ -95,22 +94,21 @@ def test_should_be_error_if_service_does_not_exist_on_create(notify_api): assert json_resp['message'] == 'No result found' -def test_should_be_error_if_service_does_not_exist_on_update(notify_api): +def test_should_be_error_if_service_does_not_exist_on_update(notify_api, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: - bad_id = str(uuid.uuid4()) data = { 'name': 'my template' } data = json.dumps(data) auth_header = create_authorization_header( - path='/service/{}/template/123'.format(bad_id), + path='/service/{}/template/{}'.format(fake_uuid, fake_uuid), method='POST', request_body=data ) response = client.post( - '/service/{}/template/123'.format(bad_id), + '/service/{}/template/{}'.format(fake_uuid, fake_uuid), headers=[('Content-Type', 'application/json'), auth_header], data=data ) @@ -142,9 +140,9 @@ def test_must_have_a_subject_on_an_email_template(notify_api, sample_service): data=data ) json_resp = json.loads(response.get_data(as_text=True)) - assert response.status_code == 500 + assert response.status_code == 400 assert json_resp['result'] == 'error' - assert json_resp['message'] == 'Failed to create template' + assert json_resp['message'] == {'subject': ['Invalid template subject']} def test_must_have_a_uniqe_subject_on_an_email_template(notify_api, sample_service): @@ -393,18 +391,17 @@ def test_should_return_empty_array_if_no_templates_for_service(notify_api, sampl assert len(json_resp['data']) == 0 -def test_should_return_404_if_no_templates_for_service_with_id(notify_api, sample_service): +def test_should_return_404_if_no_templates_for_service_with_id(notify_api, sample_service, fake_uuid): with notify_api.test_request_context(): with notify_api.test_client() as client: - uuid_ = uuid.uuid4() auth_header = create_authorization_header( - path='/service/{}/template/{}'.format(sample_service.id, 9999), + path='/service/{}/template/{}'.format(sample_service.id, fake_uuid), method='GET' ) response = client.get( - '/service/{}/template/{}'.format(sample_service.id, 9999), + '/service/{}/template/{}'.format(sample_service.id, fake_uuid), headers=[auth_header] ) diff --git a/tests/app/user/test_rest.py b/tests/app/user/test_rest.py index 1679e0c17..49674bf9e 100644 --- a/tests/app/user/test_rest.py +++ b/tests/app/user/test_rest.py @@ -27,7 +27,7 @@ def test_get_user_list(notify_api, notify_db, notify_db_session, sample_service) expected_permissions = default_service_permissions fetched = json_resp['data'][0] - assert sample_user.id == fetched['id'] + assert str(sample_user.id) == fetched['id'] assert sample_user.name == fetched['name'] assert sample_user.mobile_number == fetched['mobile_number'] assert sample_user.email_address == fetched['email_address'] @@ -53,7 +53,7 @@ def test_get_user(notify_api, notify_db, notify_db_session, sample_service): expected_permissions = default_service_permissions fetched = json_resp['data'] - assert sample_user.id == fetched['id'] + assert str(sample_user.id) == fetched['id'] assert sample_user.name == fetched['name'] assert sample_user.mobile_number == fetched['mobile_number'] assert sample_user.email_address == fetched['email_address'] @@ -90,9 +90,8 @@ def test_post_user(notify_api, notify_db, notify_db_session): assert resp.status_code == 201 user = User.query.filter_by(email_address='user@digital.cabinet-office.gov.uk').first() json_resp = json.loads(resp.get_data(as_text=True)) - json_resp['data'] == {"email_address": user.email_address, "id": user.id} assert json_resp['data']['email_address'] == user.email_address - assert json_resp['data']['id'] == user.id + assert json_resp['data']['id'] == str(user.id) def test_post_user_missing_attribute_email(notify_api, notify_db, notify_db_session): @@ -186,7 +185,7 @@ def test_put_user(notify_api, notify_db, notify_db_session, sample_service): expected_permissions = default_service_permissions fetched = json_resp['data'] - assert sample_user.id == fetched['id'] + assert str(sample_user.id) == fetched['id'] assert sample_user.name == fetched['name'] assert sample_user.mobile_number == fetched['mobile_number'] assert new_email == fetched['email_address'] @@ -230,13 +229,13 @@ def test_put_user_update_password(notify_api, request_body=json.dumps(data)) headers = [('Content-Type', 'application/json'), auth_header] resp = client.post( - url_for('user.verify_user_password', user_id=sample_user.id), + url_for('user.verify_user_password', user_id=str(sample_user.id)), data=json.dumps(data), headers=headers) assert resp.status_code == 204 -def test_put_user_not_exists(notify_api, notify_db, notify_db_session, sample_user): +def test_put_user_not_exists(notify_api, notify_db, notify_db_session, sample_user, fake_uuid): """ Tests PUT endpoint '/' to update a user doesn't exist. """ @@ -245,17 +244,17 @@ def test_put_user_not_exists(notify_api, notify_db, notify_db_session, sample_us assert User.query.count() == 1 new_email = 'new@digital.cabinet-office.gov.uk' data = {'email_address': new_email} - auth_header = create_authorization_header(path=url_for('user.update_user', user_id="9999"), + auth_header = create_authorization_header(path=url_for('user.update_user', user_id=fake_uuid), method='PUT', request_body=json.dumps(data)) headers = [('Content-Type', 'application/json'), auth_header] resp = client.put( - url_for('user.update_user', user_id="9999"), + url_for('user.update_user', user_id=fake_uuid), data=json.dumps(data), headers=headers) assert resp.status_code == 404 assert User.query.count() == 1 - user = User.query.filter_by(id=sample_user.id).first() + user = User.query.filter_by(id=str(sample_user.id)).first() json_resp = json.loads(resp.get_data(as_text=True)) assert json_resp['result'] == "error" assert json_resp['message'] == 'No result found' @@ -278,7 +277,7 @@ def test_get_user_by_email(notify_api, notify_db, notify_db_session, sample_serv expected_permissions = default_service_permissions fetched = json_resp['data'] - assert sample_user.id == fetched['id'] + assert str(sample_user.id) == fetched['id'] assert sample_user.name == fetched['name'] assert sample_user.mobile_number == fetched['mobile_number'] assert sample_user.email_address == fetched['email_address'] @@ -325,9 +324,9 @@ def test_get_user_with_permissions(notify_api, with notify_api.test_request_context(): with notify_api.test_client() as client: header = create_authorization_header( - path=url_for('user.get_user', user_id=sample_service_permission.user.id), + path=url_for('user.get_user', user_id=str(sample_service_permission.user.id)), method='GET') - response = client.get(url_for('user.get_user', user_id=sample_service_permission.user.id), + response = client.get(url_for('user.get_user', user_id=str(sample_service_permission.user.id)), headers=[header]) assert response.status_code == 200 permissions = json.loads(response.get_data(as_text=True))['data']['permissions'] @@ -345,7 +344,7 @@ def test_set_user_permissions(notify_api, header = create_authorization_header( path=url_for( 'user.set_permissions', - user_id=sample_user.id, + user_id=str(sample_user.id), service_id=str(sample_service.id)), method='POST', request_body=data) @@ -353,7 +352,7 @@ def test_set_user_permissions(notify_api, response = client.post( url_for( 'user.set_permissions', - user_id=sample_user.id, + user_id=str(sample_user.id), service_id=str(sample_service.id)), headers=headers, data=data) @@ -376,7 +375,7 @@ def test_set_user_permissions_multiple(notify_api, header = create_authorization_header( path=url_for( 'user.set_permissions', - user_id=sample_user.id, + user_id=str(sample_user.id), service_id=str(sample_service.id)), method='POST', request_body=data) @@ -384,7 +383,7 @@ def test_set_user_permissions_multiple(notify_api, response = client.post( url_for( 'user.set_permissions', - user_id=sample_user.id, + user_id=str(sample_user.id), service_id=str(sample_service.id)), headers=headers, data=data) @@ -411,7 +410,7 @@ def test_set_user_permissions_remove_old(notify_api, header = create_authorization_header( path=url_for( 'user.set_permissions', - user_id=sample_user.id, + user_id=str(sample_user.id), service_id=str(sample_service.id)), method='POST', request_body=data) @@ -419,7 +418,7 @@ def test_set_user_permissions_remove_old(notify_api, response = client.post( url_for( 'user.set_permissions', - user_id=sample_user.id, + user_id=str(sample_user.id), service_id=str(sample_service.id)), headers=headers, data=data) diff --git a/tests/app/user/test_rest_verify.py b/tests/app/user/test_rest_verify.py index e666c0140..d386085b5 100644 --- a/tests/app/user/test_rest_verify.py +++ b/tests/app/user/test_rest_verify.py @@ -336,7 +336,10 @@ def test_send_user_email_code(notify_api, queue='email-code') -def test_send_user_email_code_returns_404_for_when_user_does_not_exist(notify_api, notify_db, notify_db_session): +def test_send_user_email_code_returns_404_for_when_user_does_not_exist(notify_api, + notify_db, + notify_db_session, + fake_uuid): """ Tests POST endpoint /user//email-code return 404 for missing user """ @@ -344,11 +347,11 @@ def test_send_user_email_code_returns_404_for_when_user_does_not_exist(notify_ap with notify_api.test_client() as client: data = json.dumps({}) auth_header = create_authorization_header( - path=url_for('user.send_user_email_code', user_id=1), + path=url_for('user.send_user_email_code', user_id=fake_uuid), method='POST', request_body=data) resp = client.post( - url_for('user.send_user_email_code', user_id=1), + url_for('user.send_user_email_code', user_id=fake_uuid), data=data, headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 404 @@ -364,11 +367,11 @@ def test_send_user_email_verification(notify_api, with notify_api.test_client() as client: data = json.dumps({}) auth_header = create_authorization_header( - path=url_for('user.send_user_email_verification', user_id=sample_email_code.user.id), + path=url_for('user.send_user_email_verification', user_id=str(sample_email_code.user.id)), method='POST', request_body=data) resp = client.post( - url_for('user.send_user_email_verification', user_id=sample_email_code.user.id), + url_for('user.send_user_email_verification', user_id=str(sample_email_code.user.id)), data=data, headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 204 diff --git a/tests/conftest.py b/tests/conftest.py index 1908447f0..1b45b6369 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -39,7 +39,6 @@ def notify_db(notify_api, request): def teardown(): db.session.remove() - db.engine.execute("drop sequence services_id_seq cascade") db.drop_all() db.engine.execute("drop table alembic_version") db.get_engine(notify_api).dispose()