Exemplo n.º 1
0
 def test_get_migration_packages(self, log_mock):
     """
     Ensure that pulp.server.db.migrate.models.get_migration_packages functions correctly.
     """
     packages = models.get_migration_packages()
     self.assertEquals(len(packages), 4)
     self.assertTrue(
         all([
             isinstance(package, models.MigrationPackage)
             for package in packages
         ]))
     # Make sure that the packages are sorted correctly, with platform first
     self.assertEquals(packages[0].name,
                       'unit.server.db.migration_packages.platform')
     self.assertEquals(packages[1].name,
                       'unit.server.db.migration_packages.a')
     self.assertEquals(packages[2].name,
                       'unit.server.db.migration_packages.raise_exception')
     self.assertEquals(packages[3].name,
                       'unit.server.db.migration_packages.z')
     # Assert that we logged the duplicate version exception and the version gap exception
     expected_log_calls = [
         call('There are two migration modules that share version 2 in '
              'unit.server.db.migration_packages.duplicate_versions.'),
         call('Migration version 2 is missing in '
              'unit.server.db.migration_packages.version_gap.')
     ]
     log_mock.assert_has_calls(expected_log_calls)
Exemplo n.º 2
0
 def test_nonconforming_modules(self, log_mock):
     # The z package has a module called doesnt_conform_to_naming_convention.py. This shouldn't
     # count as a migration module, but it also should not interfere with the existing migration
     # modules, and the debug log should mention that the file was found but was not found to be
     # a migration module. The z package also has a module called 0004_doesnt_have_migrate.py.
     # Since it doesn't have a migrate function, it should just be logged and things should keep
     # going as usual.
     mp = models.MigrationPackage(migration_packages.z)
     migrations = mp.migrations
     self.assertEqual(len(migrations), 3)
     self.assertTrue(all([isinstance(migration, models.MigrationModule)
                     for migration in migrations]))
     # Make sure their versions are set and sorted appropriately
     self.assertEqual([1, 2, 3], [migration.version for migration in migrations])
     # Check the names
     self.assertEqual(['unit.server.db.migration_packages.z.0001_test',
                       'unit.server.db.migration_packages.z.0002_test',
                       'unit.server.db.migration_packages.z.0003_test'],
                      [migration.name for migration in migrations])
     # Now let's assert that the non-conforming dealios were logged
     # They actually get logged twice each, once for when we initialized the MP, and the other
     # when we retrieved the migrations
     log_mock.assert_has_calls([
         call('The module unit.server.db.migration_packages.z.0004_doesnt_have_migrate '
              'doesn\'t have a migrate function. It will be ignored.'),
         call('The module '
              'unit.server.db.migration_packages.z.doesnt_conform_to_naming_convention '
              'doesn\'t conform to the migration package naming conventions. It will be '
              'ignored.'),
         call('The module unit.server.db.migration_packages.z.0004_doesnt_have_migrate '
              'doesn\'t have a migrate function. It will be ignored.'),
         call('The module '
              'unit.server.db.migration_packages.z.doesnt_conform_to_naming_convention '
              'doesn\'t conform to the migration package naming conventions. It will be '
              'ignored.')])
Exemplo n.º 3
0
 def test_migrations(self):
     migration_package = models.MigrationPackage(migration_packages.z)
     migrations = migration_package.migrations
     self.assertEqual(len(migrations), 3)
     self.assertTrue(all([isinstance(migration, models.MigrationModule)
                     for migration in migrations]))
     # Make sure their versions are set and sorted appropriately
     self.assertEqual([1, 2, 3], [migration.version for migration in migrations])
     # Check the names
     self.assertEqual(['unit.server.db.migration_packages.z.0001_test',
                       'unit.server.db.migration_packages.z.0002_test',
                       'unit.server.db.migration_packages.z.0003_test'],
                      [migration._module.__name__ for migration in migrations])
Exemplo n.º 4
0
 def test_get_migration_packages(self, log_mock):
     """
     Ensure that pulp.server.db.migrate.models.get_migration_packages functions correctly.
     """
     packages = models.get_migration_packages()
     self.assertEquals(len(packages), 4)
     self.assertTrue(
         all([isinstance(package, models.MigrationPackage) for package in packages]))
     # Make sure that the packages are sorted correctly, with platform first
     self.assertEquals(packages[0].name, 'unit.server.db.migration_packages.platform')
     self.assertEquals(packages[1].name, 'unit.server.db.migration_packages.a')
     self.assertEquals(packages[2].name, 'unit.server.db.migration_packages.raise_exception')
     self.assertEquals(packages[3].name, 'unit.server.db.migration_packages.z')
     # Assert that we logged the duplicate version exception and the version gap exception
     expected_log_calls = [call('There are two migration modules that share version 2 in '
                           'unit.server.db.migration_packages.duplicate_versions.'),
                           call('Migration version 2 is missing in '
                                'unit.server.db.migration_packages.version_gap.')]
     log_mock.assert_has_calls(expected_log_calls)
Exemplo n.º 5
0
 def test_true(self):
     ret = compat.all([1, 'True', True])
     self.assertTrue(ret)
Exemplo n.º 6
0
 def test_false(self):
     ret = compat.all([0, False, None])
     self.assertFalse(ret)
     ret = compat.all([0, False, True])
     self.assertFalse(ret)
Exemplo n.º 7
0
 def test_empty(self):
     # all() returns True on the empty list
     ret = compat.all([])
     self.assertTrue(ret)