mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-26 17:23:50 -04:00
move sqlalchemy defaults from booleans to SQL constructs
booleans aren't actually allowed, and quietly do nothing also default Services.active to true
This commit is contained in:
@@ -5,7 +5,7 @@ from sqlalchemy.dialects.postgresql import (
|
|||||||
UUID,
|
UUID,
|
||||||
JSON
|
JSON
|
||||||
)
|
)
|
||||||
from sqlalchemy import UniqueConstraint, and_
|
from sqlalchemy import UniqueConstraint, and_, false, true
|
||||||
from sqlalchemy.orm import foreign, remote
|
from sqlalchemy.orm import foreign, remote
|
||||||
from notifications_utils.recipients import (
|
from notifications_utils.recipients import (
|
||||||
validate_email_address,
|
validate_email_address,
|
||||||
@@ -58,7 +58,7 @@ class User(db.Model):
|
|||||||
logged_in_at = db.Column(db.DateTime, nullable=True)
|
logged_in_at = db.Column(db.DateTime, nullable=True)
|
||||||
failed_login_count = db.Column(db.Integer, nullable=False, default=0)
|
failed_login_count = db.Column(db.Integer, nullable=False, default=0)
|
||||||
state = db.Column(db.String, nullable=False, default='pending')
|
state = db.Column(db.String, nullable=False, default='pending')
|
||||||
platform_admin = db.Column(db.Boolean, nullable=False, default=False)
|
platform_admin = db.Column(db.Boolean, nullable=False, default=false())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def password(self):
|
def password(self):
|
||||||
@@ -115,15 +115,15 @@ class Service(db.Model, Versioned):
|
|||||||
unique=False,
|
unique=False,
|
||||||
nullable=True,
|
nullable=True,
|
||||||
onupdate=datetime.datetime.utcnow)
|
onupdate=datetime.datetime.utcnow)
|
||||||
active = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
active = db.Column(db.Boolean, index=False, unique=False, nullable=False, default=true())
|
||||||
message_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(
|
users = db.relationship(
|
||||||
'User',
|
'User',
|
||||||
secondary=user_to_service,
|
secondary=user_to_service,
|
||||||
backref=db.backref('user_to_service', lazy='dynamic'))
|
backref=db.backref('user_to_service', lazy='dynamic'))
|
||||||
restricted = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
restricted = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
||||||
research_mode = db.Column(db.Boolean, index=False, unique=False, nullable=False, default=False)
|
research_mode = db.Column(db.Boolean, index=False, unique=False, nullable=False, default=false())
|
||||||
can_send_letters = db.Column(db.Boolean, nullable=False, default=False)
|
can_send_letters = db.Column(db.Boolean, nullable=False, default=false())
|
||||||
email_from = db.Column(db.Text, index=False, unique=True, nullable=False)
|
email_from = db.Column(db.Text, index=False, unique=True, nullable=False)
|
||||||
created_by = db.relationship('User')
|
created_by = db.relationship('User')
|
||||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
||||||
@@ -273,7 +273,7 @@ class Template(db.Model):
|
|||||||
nullable=True,
|
nullable=True,
|
||||||
onupdate=datetime.datetime.utcnow)
|
onupdate=datetime.datetime.utcnow)
|
||||||
content = db.Column(db.Text, index=False, unique=False, nullable=False)
|
content = db.Column(db.Text, index=False, unique=False, nullable=False)
|
||||||
archived = db.Column(db.Boolean, index=False, nullable=False, default=False)
|
archived = db.Column(db.Boolean, index=False, nullable=False, default=false())
|
||||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False, 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('templates', lazy='dynamic'))
|
service = db.relationship('Service', backref=db.backref('templates', lazy='dynamic'))
|
||||||
subject = db.Column(db.Text, index=False, unique=False, nullable=True)
|
subject = db.Column(db.Text, index=False, unique=False, nullable=True)
|
||||||
@@ -291,7 +291,7 @@ class TemplateHistory(db.Model):
|
|||||||
created_at = db.Column(db.DateTime, nullable=False)
|
created_at = db.Column(db.DateTime, nullable=False)
|
||||||
updated_at = db.Column(db.DateTime)
|
updated_at = db.Column(db.DateTime)
|
||||||
content = db.Column(db.Text, nullable=False)
|
content = db.Column(db.Text, nullable=False)
|
||||||
archived = db.Column(db.Boolean, nullable=False, default=False)
|
archived = db.Column(db.Boolean, nullable=False, default=false())
|
||||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False)
|
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False)
|
||||||
service = db.relationship('Service')
|
service = db.relationship('Service')
|
||||||
subject = db.Column(db.Text)
|
subject = db.Column(db.Text)
|
||||||
@@ -344,7 +344,7 @@ class ProviderDetails(db.Model):
|
|||||||
identifier = db.Column(db.String, nullable=False)
|
identifier = db.Column(db.String, nullable=False)
|
||||||
priority = db.Column(db.Integer, nullable=False)
|
priority = db.Column(db.Integer, nullable=False)
|
||||||
notification_type = db.Column(notification_types, nullable=False)
|
notification_type = db.Column(notification_types, nullable=False)
|
||||||
active = db.Column(db.Boolean, default=False)
|
active = db.Column(db.Boolean, default=false())
|
||||||
|
|
||||||
|
|
||||||
JOB_STATUS_PENDING = 'pending'
|
JOB_STATUS_PENDING = 'pending'
|
||||||
@@ -431,7 +431,7 @@ class VerifyCode(db.Model):
|
|||||||
code_type = db.Column(db.Enum(*VERIFY_CODE_TYPES, name='verify_code_types'),
|
code_type = db.Column(db.Enum(*VERIFY_CODE_TYPES, name='verify_code_types'),
|
||||||
index=False, unique=False, nullable=False)
|
index=False, unique=False, nullable=False)
|
||||||
expiry_datetime = db.Column(db.DateTime, nullable=False)
|
expiry_datetime = db.Column(db.DateTime, nullable=False)
|
||||||
code_used = db.Column(db.Boolean, default=False)
|
code_used = db.Column(db.Boolean, default=false())
|
||||||
created_at = db.Column(
|
created_at = db.Column(
|
||||||
db.DateTime,
|
db.DateTime,
|
||||||
index=False,
|
index=False,
|
||||||
|
|||||||
23
migrations/versions/0059_set_services_to_active.py
Normal file
23
migrations/versions/0059_set_services_to_active.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
"""
|
||||||
|
we weren't previously using the services.active column , and by default it was set to false. lets set all services to
|
||||||
|
active, so that in the future we can turn it off to signify deactivating a service
|
||||||
|
|
||||||
|
Revision ID: 0059_set_services_to_active
|
||||||
|
Revises: 0058_add_letters_flag
|
||||||
|
Create Date: 2016-10-31 15:17:16.716450
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '0059_set_services_to_active'
|
||||||
|
down_revision = '0058_add_letters_flag'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.execute('UPDATE services SET active = TRUE')
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.execute('UPDATE services SET active = FALSE')
|
||||||
@@ -139,7 +139,7 @@ def sample_service(notify_db,
|
|||||||
data = {
|
data = {
|
||||||
'name': service_name,
|
'name': service_name,
|
||||||
'message_limit': limit,
|
'message_limit': limit,
|
||||||
'active': False,
|
'active': True,
|
||||||
'restricted': restricted,
|
'restricted': restricted,
|
||||||
'email_from': email_from,
|
'email_from': email_from,
|
||||||
'created_by': user
|
'created_by': user
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ def test_create_service(sample_user):
|
|||||||
service = Service(name="service_name",
|
service = Service(name="service_name",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
@@ -77,14 +76,12 @@ def test_cannot_create_two_services_with_same_name(sample_user):
|
|||||||
service1 = Service(name="service_name",
|
service1 = Service(name="service_name",
|
||||||
email_from="email_from1",
|
email_from="email_from1",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
|
|
||||||
service2 = Service(name="service_name",
|
service2 = Service(name="service_name",
|
||||||
email_from="email_from2",
|
email_from="email_from2",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
with pytest.raises(IntegrityError) as excinfo:
|
with pytest.raises(IntegrityError) as excinfo:
|
||||||
@@ -98,13 +95,11 @@ def test_cannot_create_two_services_with_same_email_from(sample_user):
|
|||||||
service1 = Service(name="service_name1",
|
service1 = Service(name="service_name1",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
service2 = Service(name="service_name2",
|
service2 = Service(name="service_name2",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
with pytest.raises(IntegrityError) as excinfo:
|
with pytest.raises(IntegrityError) as excinfo:
|
||||||
@@ -118,7 +113,6 @@ def test_cannot_create_service_with_no_user(notify_db_session, sample_user):
|
|||||||
service = Service(name="service_name",
|
service = Service(name="service_name",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
with pytest.raises(FlushError) as excinfo:
|
with pytest.raises(FlushError) as excinfo:
|
||||||
@@ -130,7 +124,6 @@ def test_should_add_user_to_service(sample_user):
|
|||||||
service = Service(name="service_name",
|
service = Service(name="service_name",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
@@ -150,7 +143,6 @@ def test_should_remove_user_from_service(sample_user):
|
|||||||
service = Service(name="service_name",
|
service = Service(name="service_name",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
@@ -244,7 +236,6 @@ def test_create_service_creates_a_history_record_with_current_data(sample_user):
|
|||||||
service = Service(name="service_name",
|
service = Service(name="service_name",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
@@ -270,7 +261,6 @@ def test_update_service_creates_a_history_record_with_current_data(sample_user):
|
|||||||
service = Service(name="service_name",
|
service = Service(name="service_name",
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
@@ -299,7 +289,6 @@ def test_create_service_and_history_is_transactional(sample_user):
|
|||||||
service = Service(name=None,
|
service = Service(name=None,
|
||||||
email_from="email_from",
|
email_from="email_from",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
|
|
||||||
@@ -348,7 +337,6 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(sam
|
|||||||
service_one = Service(name="service_one",
|
service_one = Service(name="service_one",
|
||||||
email_from="service_one",
|
email_from="service_one",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=sample_user)
|
created_by=sample_user)
|
||||||
|
|
||||||
@@ -367,7 +355,6 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(sam
|
|||||||
service_two = Service(name="service_two",
|
service_two = Service(name="service_two",
|
||||||
email_from="service_two",
|
email_from="service_two",
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
active=True,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
created_by=other_user)
|
created_by=other_user)
|
||||||
dao_create_service(service_two, other_user)
|
dao_create_service(service_two, other_user)
|
||||||
@@ -397,7 +384,6 @@ def test_fetch_stats_filters_on_service(sample_notification):
|
|||||||
service_two = Service(name="service_two",
|
service_two = Service(name="service_two",
|
||||||
created_by=sample_notification.service.created_by,
|
created_by=sample_notification.service.created_by,
|
||||||
email_from="hello",
|
email_from="hello",
|
||||||
active=False,
|
|
||||||
restricted=False,
|
restricted=False,
|
||||||
message_limit=1000)
|
message_limit=1000)
|
||||||
dao_create_service(service_two, sample_notification.service.created_by)
|
dao_create_service(service_two, sample_notification.service.created_by)
|
||||||
|
|||||||
@@ -285,7 +285,6 @@ def test_should_not_create_service_if_missing_data(notify_api, sample_user):
|
|||||||
assert resp.status_code == 400
|
assert resp.status_code == 400
|
||||||
assert json_resp['result'] == 'error'
|
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']['name']
|
||||||
assert 'Missing data for required field.' in json_resp['message']['active']
|
|
||||||
assert 'Missing data for required field.' in json_resp['message']['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']
|
assert 'Missing data for required field.' in json_resp['message']['restricted']
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user