From 752a359d3ddec826e7b692d89d4af27a5e467580 Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Tue, 12 Jan 2016 09:56:42 +0000 Subject: [PATCH] Added versions file for initial db and fixed tests. --- migrations/versions/0001_initialise_data.py | 52 +++++++++++++++++++++ tests/app/service/views/test_rest.py | 4 +- tests/conftest.py | 4 -- 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 migrations/versions/0001_initialise_data.py diff --git a/migrations/versions/0001_initialise_data.py b/migrations/versions/0001_initialise_data.py new file mode 100644 index 000000000..a1f5ab250 --- /dev/null +++ b/migrations/versions/0001_initialise_data.py @@ -0,0 +1,52 @@ +"""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/tests/app/service/views/test_rest.py b/tests/app/service/views/test_rest.py index ff89f5d8b..2e0cd3e8a 100644 --- a/tests/app/service/views/test_rest.py +++ b/tests/app/service/views/test_rest.py @@ -88,6 +88,7 @@ def test_post_service_multiple_users(notify_api, notify_db, notify_db_session, s assert json_resp['data']['limit'] == service.limit assert len(service.users) == 2 + def test_post_service_without_users_attribute(notify_api, notify_db, notify_db_session): """ Tests POST endpoint '/' to create a service without 'users' attribute. @@ -208,6 +209,3 @@ def test_put_service_remove_user(notify_api, notify_db, notify_db_session, sampl assert len(json_resp['data']['users']) == 1 assert sample_user.id not in json_resp['data']['users'] assert another_user.id in json_resp['data']['users'] - - - diff --git a/tests/conftest.py b/tests/conftest.py index aeddcc02e..a61f1e724 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,10 +34,6 @@ def notify_db(notify_api, request): config.set_main_option("script_location", ALEMBIC_CONFIG) with notify_api.app_context(): - # TODO this next line shouldn't be needed, - # but cannot work out the import order to - # remove it. - db.create_all() upgrade(config, 'head') def teardown():