From bde6a9e131c13234700cce10213cc70828a9cabd Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 20 Sep 2017 11:03:48 +0100 Subject: [PATCH] Make organisation logo nullable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now we have the org banner branding, not all organisations need a logo. So it shouldn’t be an error to not provide one. --- app/models.py | 2 +- app/organisation/organisation_schema.py | 2 +- migrations/versions/0121_nullable_logos.py | 25 ++++++++++++++++++++++ tests/app/dao/test_organisations_dao.py | 9 +------- tests/app/organisation/test_rest.py | 5 ++--- 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 migrations/versions/0121_nullable_logos.py diff --git a/app/models.py b/app/models.py index 207e56e8c..bad685309 100644 --- a/app/models.py +++ b/app/models.py @@ -135,7 +135,7 @@ class Organisation(db.Model): __tablename__ = 'organisation' id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) colour = db.Column(db.String(7), nullable=True) - logo = db.Column(db.String(255), nullable=False) + logo = db.Column(db.String(255), nullable=True) name = db.Column(db.String(255), nullable=True) def serialize(self): diff --git a/app/organisation/organisation_schema.py b/app/organisation/organisation_schema.py index 60b523057..44571d3fb 100644 --- a/app/organisation/organisation_schema.py +++ b/app/organisation/organisation_schema.py @@ -7,7 +7,7 @@ post_create_organisation_schema = { "name": {"type": ["string", "null"]}, "logo": {"type": ["string", "null"]} }, - "required": ["logo"] + "required": [] } post_update_organisation_schema = { diff --git a/migrations/versions/0121_nullable_logos.py b/migrations/versions/0121_nullable_logos.py new file mode 100644 index 000000000..c100a2f24 --- /dev/null +++ b/migrations/versions/0121_nullable_logos.py @@ -0,0 +1,25 @@ +""" + +Revision ID: 0121_nullable_logos +Revises: 0120_add_org_banner_branding +Create Date: 2017-09-20 11:00:20.415523 + +""" +from alembic import op +import sqlalchemy as sa + + +revision = '0121_nullable_logos' +down_revision = '0120_add_org_banner_branding' + + +def upgrade(): + op.alter_column( + 'organisation', 'logo', + existing_type=sa.VARCHAR(length=255), + nullable=True + ) + + +def downgrade(): + pass diff --git a/tests/app/dao/test_organisations_dao.py b/tests/app/dao/test_organisations_dao.py index bc5d8c0a6..e46c75878 100644 --- a/tests/app/dao/test_organisations_dao.py +++ b/tests/app/dao/test_organisations_dao.py @@ -21,20 +21,13 @@ def test_create_organisation(notify_db, notify_db_session): def test_create_organisation_without_name_or_colour_is_valid(notify_db, notify_db_session): - organisation = create_organisation(name=None, colour=None) + organisation = create_organisation(logo=None, name=None, colour=None) assert Organisation.query.count() == 1 organisation_from_db = Organisation.query.first() assert organisation == organisation_from_db -def test_create_organisation_without_logo_raises_error(notify_db, notify_db_session): - with pytest.raises(IntegrityError) as excinfo: - create_organisation(logo=None) - assert 'column "logo" violates not-null constraint' in str(excinfo.value) - assert Organisation.query.count() == 0 - - def test_get_organisations_gets_all_organisations(notify_db, notify_db_session): org_1 = create_organisation(name='test_org_1') org_2 = create_organisation(name='test_org_2') diff --git a/tests/app/organisation/test_rest.py b/tests/app/organisation/test_rest.py index ea5926f5d..688f6f74d 100644 --- a/tests/app/organisation/test_rest.py +++ b/tests/app/organisation/test_rest.py @@ -54,7 +54,7 @@ def test_post_create_organisation(admin_request, notify_db_session): assert data['logo'] == response['data']['logo'] -def test_post_create_organisation_without_logo_raises_error(admin_request, notify_db_session): +def test_post_create_organisation_without_logo_is_ok(admin_request, notify_db_session): data = { 'name': 'test organisation', 'colour': '#0000ff', @@ -62,9 +62,8 @@ def test_post_create_organisation_without_logo_raises_error(admin_request, notif response = admin_request.post( 'organisation.create_organisation', _data=data, - _expected_status=400 + _expected_status=201, ) - assert response['errors'][0]['message'] == "logo is a required property" def test_post_create_organisation_without_name_or_colour_is_valid(admin_request, notify_db_session):