mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 01:56:03 -04:00
add DVLA organisations to API
when services are created, they'll have a dvla_org_id of 001, or HM Government. That can be changed later using a regular update call
This commit is contained in:
@@ -113,6 +113,16 @@ class Organisation(db.Model):
|
||||
name = db.Column(db.String(255), nullable=True)
|
||||
|
||||
|
||||
DVLA_ORG_HM_GOVERNMENT = '001'
|
||||
DVLA_ORG_LAND_REGISTRY = '500'
|
||||
|
||||
|
||||
class DVLAOrganisation(db.Model):
|
||||
__tablename__ = 'dvla_organisation'
|
||||
id = db.Column(db.String, primary_key=True)
|
||||
name = db.Column(db.String(255), nullable=True)
|
||||
|
||||
|
||||
class Service(db.Model, Versioned):
|
||||
__tablename__ = 'services'
|
||||
|
||||
@@ -147,6 +157,14 @@ class Service(db.Model, Versioned):
|
||||
sms_sender = db.Column(db.String(11), nullable=True)
|
||||
organisation_id = db.Column(UUID(as_uuid=True), db.ForeignKey('organisation.id'), index=True, nullable=True)
|
||||
organisation = db.relationship('Organisation')
|
||||
dvla_organisation_id = db.Column(
|
||||
db.String,
|
||||
db.ForeignKey('dvla_organisation.id'),
|
||||
index=True,
|
||||
nullable=False,
|
||||
default=DVLA_ORG_HM_GOVERNMENT
|
||||
)
|
||||
dvla_organisation = db.relationship('DVLAOrganisation')
|
||||
branding = db.Column(
|
||||
db.String(255),
|
||||
db.ForeignKey('branding_type.name'),
|
||||
|
||||
@@ -177,6 +177,7 @@ class ServiceSchema(BaseSchema):
|
||||
created_by = field_for(models.Service, 'created_by', required=True)
|
||||
organisation = field_for(models.Service, 'organisation')
|
||||
branding = field_for(models.Service, 'branding')
|
||||
dvla_organisation = field_for(models.Service, 'dvla_organisation')
|
||||
|
||||
class Meta:
|
||||
model = models.Service
|
||||
|
||||
60
migrations/versions/0072_add_dvla_orgs.py
Normal file
60
migrations/versions/0072_add_dvla_orgs.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0072_add_dvla_orgs
|
||||
Revises: 0071_add_job_error_state
|
||||
Create Date: 2017-04-19 15:25:45.155886
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0072_add_dvla_orgs'
|
||||
down_revision = '0071_add_job_error_state'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('dvla_organisation',
|
||||
sa.Column('id', sa.String(), nullable=False),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# insert initial values - HMG and Land Reg
|
||||
op.execute("""
|
||||
INSERT INTO dvla_organisation VALUES
|
||||
('001', 'HM Government'),
|
||||
('500', 'Land Registry')
|
||||
""")
|
||||
|
||||
op.add_column('services', sa.Column('dvla_organisation_id', sa.String(), nullable=True))
|
||||
op.add_column('services_history', sa.Column('dvla_organisation_id', sa.String(), nullable=True))
|
||||
|
||||
# set everything to be HMG for now
|
||||
op.execute("UPDATE services SET dvla_organisation_id = '001'")
|
||||
op.execute("UPDATE services_history SET dvla_organisation_id = '001'")
|
||||
|
||||
op.alter_column('services', 'dvla_organisation_id', nullable=False)
|
||||
op.alter_column('services_history', 'dvla_organisation_id', nullable=False)
|
||||
|
||||
op.create_index(
|
||||
op.f('ix_services_dvla_organisation_id'),
|
||||
'services',
|
||||
['dvla_organisation_id'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
op.f('ix_services_history_dvla_organisation_id'),
|
||||
'services_history',
|
||||
['dvla_organisation_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_foreign_key(None, 'services', 'dvla_organisation', ['dvla_organisation_id'], ['id'])
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('services_history', 'dvla_organisation_id')
|
||||
op.drop_column('services', 'dvla_organisation_id')
|
||||
op.drop_table('dvla_organisation')
|
||||
@@ -43,6 +43,7 @@ from app.models import (
|
||||
InvitedUser,
|
||||
Service,
|
||||
BRANDING_GOVUK,
|
||||
DVLA_ORG_HM_GOVERNMENT,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST
|
||||
@@ -77,6 +78,7 @@ def test_create_service(sample_user):
|
||||
assert service_db.name == "service_name"
|
||||
assert service_db.id == service.id
|
||||
assert service_db.branding == BRANDING_GOVUK
|
||||
assert service_db.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT
|
||||
assert service_db.research_mode is False
|
||||
assert service.active is True
|
||||
assert sample_user in service_db.users
|
||||
@@ -263,7 +265,9 @@ def test_create_service_creates_a_history_record_with_current_data(sample_user):
|
||||
assert sample_user.id == service_history.created_by_id
|
||||
assert service_from_db.created_by.id == service_history.created_by_id
|
||||
assert service_from_db.branding == BRANDING_GOVUK
|
||||
assert service_from_db.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT
|
||||
assert service_history.branding == BRANDING_GOVUK
|
||||
assert service_history.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT
|
||||
|
||||
|
||||
def test_update_service_creates_a_history_record_with_current_data(sample_user):
|
||||
|
||||
@@ -10,7 +10,7 @@ from freezegun import freeze_time
|
||||
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.dao.services_dao import dao_remove_user_from_service
|
||||
from app.models import User, Organisation
|
||||
from app.models import User, Organisation, DVLA_ORG_LAND_REGISTRY
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import (
|
||||
sample_service as create_service,
|
||||
@@ -371,41 +371,41 @@ def test_create_service_should_throw_duplicate_key_constraint_for_existing_email
|
||||
assert "Duplicate service name '{}'".format(service_name) in json_resp['message']['name']
|
||||
|
||||
|
||||
def test_update_service(notify_api, notify_db, sample_service):
|
||||
def test_update_service(client, notify_db, sample_service):
|
||||
org = Organisation(colour='#000000', logo='justice-league.png', name='Justice League')
|
||||
notify_db.session.add(org)
|
||||
notify_db.session.commit()
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert resp.status_code == 200
|
||||
assert json_resp['data']['name'] == sample_service.name
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert resp.status_code == 200
|
||||
assert json_resp['data']['name'] == sample_service.name
|
||||
|
||||
data = {
|
||||
'name': 'updated service name',
|
||||
'email_from': 'updated.service.name',
|
||||
'created_by': str(sample_service.created_by.id),
|
||||
'organisation': str(org.id)
|
||||
}
|
||||
data = {
|
||||
'name': 'updated service name',
|
||||
'email_from': 'updated.service.name',
|
||||
'created_by': str(sample_service.created_by.id),
|
||||
'organisation': str(org.id),
|
||||
'dvla_organisation': DVLA_ORG_LAND_REGISTRY
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
result = json.loads(resp.get_data(as_text=True))
|
||||
assert resp.status_code == 200
|
||||
assert result['data']['name'] == 'updated service name'
|
||||
assert result['data']['email_from'] == 'updated.service.name'
|
||||
assert result['data']['organisation'] == str(org.id)
|
||||
resp = client.post(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
result = json.loads(resp.get_data(as_text=True))
|
||||
assert resp.status_code == 200
|
||||
assert result['data']['name'] == 'updated service name'
|
||||
assert result['data']['email_from'] == 'updated.service.name'
|
||||
assert result['data']['organisation'] == str(org.id)
|
||||
assert result['data']['dvla_organisation'] == DVLA_ORG_LAND_REGISTRY
|
||||
|
||||
|
||||
def test_update_service_flags(notify_api, sample_service):
|
||||
|
||||
@@ -75,7 +75,8 @@ def notify_db_session(notify_db):
|
||||
"branding_type",
|
||||
"job_status",
|
||||
"provider_details_history",
|
||||
"template_process_type"]:
|
||||
"template_process_type",
|
||||
"dvla_organisation"]:
|
||||
notify_db.engine.execute(tbl.delete())
|
||||
notify_db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user