Example #1
0
 def test_it_creates_the_table_if_not_existing(self):
     CQLExecutor.init_table(self.session)
     self.session.execute.assert_called_once_with("""
         CREATE TABLE IF NOT EXISTS schema_migrations
                 (type text, version int, PRIMARY KEY(type, version))
             WITH COMMENT = 'Schema migration history'
             AND CLUSTERING ORDER BY (version DESC)
     """)
Example #2
0
 def test_it_multi_line_statements(self):
     CQLExecutor.execute(
         self.session,
         'statement start\nmore statement\nend statement;\nstatement\n2')
     self.session.execute.assert_has_calls([
         mock.call('statement start more statement end statement'),
         mock.call('statement 2')
     ])
Example #3
0
 def test_it_creates_the_table_if_not_existing(self):
     CQLExecutor.init_table(self.session)
     self.session.execute.assert_called_once_with("""
         CREATE TABLE IF NOT EXISTS schema_migrations
                 (type text, version int, PRIMARY KEY(type, version))
             WITH COMMENT = 'Schema migration history'
             AND CLUSTERING ORDER BY (version DESC)
     """)
Example #4
0
 def test_it_removes_the_most_recent_schema_migration_row(self):
     CQLExecutor.get_top_version = mock.Mock(
         return_value=[mock.Mock(version=5)])
     CQLExecutor.rollback_schema_migration(self.session)
     self.session.execute.assert_called_once_with("""
         DELETE FROM schema_migrations
             WHERE type = 'migration'
                 AND version = 5""")
Example #5
0
 def test_it_ignores_comments(self):
     CQLExecutor.execute(
         self.session,
         'line1;\n--comment\n//comment\n\t//comment\nline2'
     )
     self.session.execute.assert_has_calls([
         mock.call('line1'),
         mock.call('line2')
     ])
Example #6
0
 def test_it_multi_line_statements(self):
     CQLExecutor.execute(
         self.session,
         'statement start\nmore statement\nend statement;\nstatement\n2'
     )
     self.session.execute.assert_has_calls([
         mock.call('statement start more statement end statement'),
         mock.call('statement 2')
     ])
Example #7
0
 def test_it_removes_the_most_recent_schema_migration_row(self):
     CQLExecutor.get_top_version = mock.Mock(
         return_value=[mock.Mock(version=5)]
     )
     CQLExecutor.rollback_schema_migration(self.session)
     self.session.execute.assert_called_once_with("""
         DELETE FROM schema_migrations
             WHERE type = 'migration'
                 AND version = 5""")
    def test_it_selects_the_most_recent_migration(self):
        row = []
        self.session.execute = Mock(return_value=row)

        result = CQLExecutor.get_top_version(self.session)

        self.assertEquals(row, result)
        self.session.execute.assert_called_once_with('SELECT * FROM schema_migrations LIMIT 1')
Example #9
0
 def test_it_ignores_whitespace_and_other_text_following_undo_marker(self):
     CQLExecutor.execute_undo(
         self.session,
         'migration statement;\n\t--//@UNDO  begin undo\nundo statement')
     self.session.execute.assert_called_once_with('undo statement')
Example #10
0
 def test_it_runs_the_undo_section(self):
     CQLExecutor.execute_undo(
         self.session, 'migration statement;\n--//@UNDO\nundo statement')
     self.session.execute.assert_called_once_with('undo statement')
Example #11
0
 def test_it_ignores_comments(self):
     CQLExecutor.execute(
         self.session, 'line1;\n--comment\n//comment\n\t//comment\nline2')
     self.session.execute.assert_has_calls(
         [mock.call('line1'), mock.call('line2')])
Example #12
0
 def test_it_updates_schema_migrations_with_the_migration_version(self):
     CQLExecutor.add_schema_migration(self.session, 10)
     self.session.execute.assert_called_once_with("""
         INSERT INTO schema_migrations (type, version)
             VALUES ('migration', 10)""")
Example #13
0
 def test_it_executes_a_multi_line_migration_script(self):
     CQLExecutor.execute(self.session, 'line1;\nline2;\n')
     self.session.execute.assert_has_calls(
         [mock.call('line1'), mock.call('line2')])
Example #14
0
 def test_it_executes_the_migration_script(self):
     CQLExecutor.execute(self.session, 'script')
     self.session.execute.assert_called_once_with('script')
Example #15
0
 def test_it_executes_the_migration_script(self):
     CQLExecutor.execute(self.session, 'script')
     self.session.execute.assert_called_once_with('script')
Example #16
0
 def test_it_executes_a_multi_line_migration_script(self):
     CQLExecutor.execute(self.session, 'line1;\nline2;\n')
     self.session.execute.assert_has_calls(
         [mock.call('line1'), mock.call('line2')]
     )
Example #17
0
 def test_it_updates_schema_migrations_with_the_migration_version(self):
     CQLExecutor.add_schema_migration(self.session, 10)
     self.session.execute.assert_called_once_with("""
         INSERT INTO schema_migrations (type, version)
             VALUES ('migration', 10)""")
Example #18
0
 def test_it_runs_the_undo_section(self):
     CQLExecutor.execute_undo(
         self.session,
         'migration statement;\n--//@UNDO\nundo statement')
     self.session.execute.assert_called_once_with('undo statement')
Example #19
0
 def test_it_ignores_whitespace_and_other_text_following_undo_marker(self):
     CQLExecutor.execute_undo(
         self.session,
         'migration statement;\n\t--//@UNDO  begin undo\nundo statement')
     self.session.execute.assert_called_once_with('undo statement')