示例#1
0
    def setUp(self):
        class Migrations(migopy.MigrationsManager):
            MONGO_DATABASE = 'migopy_db_test'

        self.Migrations = Migrations
        self.migr_mng = Migrations()
        self.tmp_dir = TestDirectory()
        self.tmp_dir.__enter__()
        self.tmp_dir.mkdir('mongomigrations')
        for path in files:
            self.tmp_dir.create_file(path, files[path])
示例#2
0
    def test_it_returns_unregistered_migrations_in_order(self):
        with TestDirectory() as test_dir:
            test_dir.mkdir('mongomigrations')
            test_dir.touch('mongomigrations/1_test.py')
            test_dir.touch('mongomigrations/12_test.py')
            test_dir.touch('mongomigrations/3_test.py')
            self.migr_mng.collection = \
                MigrationsCollectionMock(['1_test.py'])
            unregistered = self.migr_mng.unregistered()
            self.assertEqual(unregistered, ['3_test.py', '12_test.py'])

            # when migrations directory is not python module,
            # creates __init__.py
            self.assertTrue(os.path.exists('mongomigrations/__init__.py'))

            # when no migrations directory founded, raise exception
            test_dir.clear()
            with self.assertRaises(migopy.MigopyException) as cm:
                self.migr_mng.unregistered()

            self.assertTrue(cm.exception.message.startswith("Migrations dir"))
示例#3
0
    def test_it_prints_status_of_migrations(self):
        # given test directory
        with TestDirectory() as test_dir:
            self.migr_mng.collection = MigrationsCollectionMock()
            test_dir.mkdir('mongomigrations')
            # when no migrations files found, show 'all registered'
            self.migr_mng.show_status()
            self.assertEqual(self.migr_mng.logger.green.call_count, 1,
                             "Not logged with green message")

            # when some files found, check them and show status
            test_dir.touch('mongomigrations/1_test.py')
            test_dir.touch('mongomigrations/002_test.py')

            self.migr_mng.logger.reset_mock()
            self.migr_mng.show_status()
            self.assertEqual(self.migr_mng.logger.white_bold.call_count, 1,
                             "Not logged with white message")
            self.migr_mng.logger.red.\
                assert_has_calls([mock.call('1_test.py'),
                                  mock.call('002_test.py')])