mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-02 17:48:36 -04:00
Add versioning to Organisations
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import transactional
|
from app.dao.dao_utils import transactional, version_class
|
||||||
from app.models import Organisation
|
from app.models import Organisation
|
||||||
|
|
||||||
|
|
||||||
@@ -12,10 +12,12 @@ def dao_get_organisation_by_id(org_id):
|
|||||||
|
|
||||||
|
|
||||||
@transactional
|
@transactional
|
||||||
|
@version_class(Organisation)
|
||||||
def dao_create_organisation(organisation):
|
def dao_create_organisation(organisation):
|
||||||
db.session.add(organisation)
|
db.session.add(organisation)
|
||||||
|
|
||||||
|
|
||||||
@transactional
|
@transactional
|
||||||
|
@version_class(Organisation)
|
||||||
def dao_update_organisation(organisation):
|
def dao_update_organisation(organisation):
|
||||||
db.session.add(organisation)
|
db.session.add(organisation)
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class BrandingTypes(db.Model):
|
|||||||
name = db.Column(db.String(255), primary_key=True)
|
name = db.Column(db.String(255), primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class Organisation(db.Model):
|
class Organisation(db.Model, Versioned):
|
||||||
__tablename__ = 'organisation'
|
__tablename__ = 'organisation'
|
||||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
colour = db.Column(db.String(7), nullable=True)
|
colour = db.Column(db.String(7), nullable=True)
|
||||||
@@ -142,8 +142,7 @@ class Organisation(db.Model):
|
|||||||
"""
|
"""
|
||||||
Assumption: data has been validated appropriately.
|
Assumption: data has been validated appropriately.
|
||||||
|
|
||||||
Returns a Service object based on the provided data. Deserialises created_by to created_by_id as marshmallow
|
Returns a Organisation object based on the provided data.
|
||||||
would.
|
|
||||||
"""
|
"""
|
||||||
# validate json with marshmallow
|
# validate json with marshmallow
|
||||||
fields = data.copy()
|
fields = data.copy()
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def test_update_organisation(notify_db, notify_db_session):
|
|||||||
organisation = create_organisation()
|
organisation = create_organisation()
|
||||||
|
|
||||||
organisation_from_db = Organisation.query.first()
|
organisation_from_db = Organisation.query.first()
|
||||||
assert organisation.name != updated_name
|
assert organisation_from_db.name != updated_name
|
||||||
|
|
||||||
organisation.name = updated_name
|
organisation.name = updated_name
|
||||||
|
|
||||||
@@ -46,3 +46,21 @@ def test_update_organisation(notify_db, notify_db_session):
|
|||||||
organisation_from_db = Organisation.query.first()
|
organisation_from_db = Organisation.query.first()
|
||||||
|
|
||||||
assert organisation_from_db.name == updated_name
|
assert organisation_from_db.name == updated_name
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_organisation_creates_a_history_record_with_current_data(sample_user):
|
||||||
|
assert Organisation.query.count() == 0
|
||||||
|
assert Organisation.get_history_model().query.count() == 0
|
||||||
|
organisation = create_organisation()
|
||||||
|
assert Organisation.query.count() == 1
|
||||||
|
assert Organisation.get_history_model().query.count() == 1
|
||||||
|
|
||||||
|
organisation_from_db = Organisation.query.first()
|
||||||
|
organisation_history = Organisation.get_history_model().query.first()
|
||||||
|
|
||||||
|
assert organisation_from_db.id == organisation_history.id
|
||||||
|
assert organisation_from_db.name == organisation_history.name
|
||||||
|
assert organisation_from_db.version == 1
|
||||||
|
assert organisation_from_db.version == organisation_history.version
|
||||||
|
assert sample_user.id == organisation_history.created_by_id
|
||||||
|
assert organisation_from_db.created_by.id == organisation_history.created_by_id
|
||||||
|
|||||||
Reference in New Issue
Block a user