From 854b69745f0ff99329ab0e95519d266019578488 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 19 2017 08:14:14 +0000 Subject: [PATCH 1/2] Fix the alembic history to remain linear --- diff --git a/alembic/versions/4255158a6913_create_private_column_in_project_table.py b/alembic/versions/4255158a6913_create_private_column_in_project_table.py index 7baeef6..3e4a81c 100644 --- a/alembic/versions/4255158a6913_create_private_column_in_project_table.py +++ b/alembic/versions/4255158a6913_create_private_column_in_project_table.py @@ -1,14 +1,14 @@ """Create private column in project table Revision ID: 4255158a6913 -Revises: 3ffec872dfdf +Revises: 4df75d40bafa Create Date: 2016-06-06 14:33:47.039207 """ # revision identifiers, used by Alembic. revision = '4255158a6913' -down_revision = '3ffec872dfdf' +down_revision = '4df75d40bafa' from alembic import op import sqlalchemy as sa From 08b640c3de3c33c8682d35755d00c448c628809b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 19 2017 08:14:14 +0000 Subject: [PATCH 2/2] Add a unit-test test enforcing the linearity of the alembic history Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_alembic.py b/tests/test_alembic.py new file mode 100644 index 0000000..6aec50c --- /dev/null +++ b/tests/test_alembic.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2017 - Copyright Red Hat Inc + + Authors: + Pierre-Yves Chibon + +""" + +import os +import subprocess +import unittest + + +REPO_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), '..')) + + +class TestAlembic(unittest.TestCase): + """This test class contains tests pertaining to alembic.""" + + def test_alembic_history(self): + """Enforce a linear alembic history. + + This test runs the `alembic history | grep ' (head), '` command, + and ensure it returns only one line. + """ + + proc1 = subprocess.Popen( + ['alembic', 'history'], + cwd=REPO_PATH, stdout=subprocess.PIPE) + proc2 = subprocess.Popen( + ['grep', ' (head), '], + stdin=proc1.stdout, stdout=subprocess.PIPE) + stdout = proc2.communicate()[0] + stdout = stdout.strip().split('\n') + + self.assertEqual(len(stdout), 1) + + +if __name__ == '__main__': + unittest.main(verbosity=2)