def testNothingToExport(self): project = test_util.EmptyMoeProjectConfig() internal_creator = test_util.StaticCodebaseCreator({ '1001': 'simple_python', '1002': 'simple_python' }) public_creator = test_util.StaticCodebaseCreator( {'1': 'simple_python'}) config = actions.MigrationConfig(base.Migration.EXPORT, internal_creator, project.internal_repository_config, public_creator, project.public_repository_config, None, project.export_strategy) revisions = [base.Revision('1002')] export = actions.Migration(base.Revision('1001'), base.Revision('1'), revisions, project, [], config, False, -1) result = export.Perform() self.assertEqual(result, None)
def testErrorsOnLastBrokenCodebase(self): mock_db = test_util.MockDbClient(migration_id_seed=88) mock_editor = test_util.MockEditor() mock_client = test_util.MockClient( lambda migration_strategy, revisions: mock_editor) report = base.MoeReport() project = test_util.EmptyMoeProjectConfig() internal_creator = test_util.StaticCodebaseCreator( { '1001': 'simple_python', '1002': None, }, lambda: mock_client) public_creator = test_util.StaticCodebaseCreator( {'1': 'simple_python'}) config = actions.MigrationConfig(base.Migration.EXPORT, internal_creator, project.internal_repository_config, public_creator, project.public_repository_config, None, project.export_strategy) revisions = [base.Revision('1002', changelog='1002')] action = actions.Migration(base.Revision('1001'), base.Revision('1'), revisions, project, [], config, False, 1) self.assertRaises(base.CodebaseCreationError, action.Perform, db=mock_db)
def testSingleImport(self): mock_db = test_util.MockDbClient(migration_id_seed=88) mock_editor = test_util.MockEditor() mock_client = test_util.MockClient( lambda migration_strategy, revisions: mock_editor) project = test_util.EmptyMoeProjectConfig() internal_creator = test_util.StaticCodebaseCreator( {'1001': 'simple_python'}, lambda: mock_client) public_creator = test_util.StaticCodebaseCreator({ '1': 'simple_python', '2': 'simple_python2' }) config = actions.MigrationConfig(base.Migration.IMPORT, public_creator, project.public_repository_config, internal_creator, project.internal_repository_config, None, project.import_strategy) revisions = [base.Revision('2', changelog='log')] action = actions.Migration(base.Revision('1'), base.Revision('1001'), revisions, project, [], config, False, -1) result = action.Perform(db=mock_db) self.assertFalse(result) self.assertTrue(mock_editor.ChangesMade()) expected = base.Migration(migration_id='88', direction=base.Migration.IMPORT, status=base.Migration.ACTIVE, up_to_revision=base.Revision('2'), changelog='log', revisions=revisions) self.assertEqual(mock_db.GetMigration('88').Dict(), expected.Dict())
def testDivideMultipleChangelogs(self): mock_db = test_util.MockDbClient() mock_editor = test_util.MockEditor() mock_client = test_util.MockClient( lambda migration_strategy, revisions: mock_editor) project = test_util.EmptyMoeProjectConfig() project.export_strategy.separate_revisions = True internal_creator = test_util.StaticCodebaseCreator({ '1001': 'simple_python', '1002': 'simple_python2', '1003': 'simple_python', '1004': 'simple_python2' }) public_creator = test_util.StaticCodebaseCreator( {'1': 'simple_python'}, lambda: mock_client) config = actions.MigrationConfig(base.Migration.EXPORT, internal_creator, project.internal_repository_config, public_creator, project.public_repository_config, None, project.export_strategy) revisions = [ base.Revision('1002', changelog='Change 1: a change', single_scrubbed_log='a change'), base.Revision('1003', changelog='Change 2: another change', single_scrubbed_log='another change'), base.Revision('1004', changelog='Change 3: something', single_scrubbed_log='something') ] action = actions.Migration(base.Revision('1001'), base.Revision('1'), revisions, project, [], config, False, 1) result = action.Perform(db=mock_db) self.assertEqual(len(result.actions), 1) self.assertEqual( mock_db.GetMigration('1', abbreviated=False).changelog, 'a change') result = result.actions[0].Perform(db=mock_db) self.assertEqual(len(result.actions), 1) self.assertEqual( mock_db.GetMigration('2', abbreviated=False).changelog, 'another change') result = result.actions[0].Perform(db=mock_db) self.assertEqual(result, None) self.assertEqual( mock_db.GetMigration('3', abbreviated=False).changelog, 'something')
def testSingleExportCommit(self): mock_db = test_util.MockDbClient(migration_id_seed=88) mock_editor = test_util.MockEditor(commit_id='2') mock_client = test_util.MockClient( lambda migration_strategy, revisions: mock_editor) report = base.MoeReport() project = test_util.EmptyMoeProjectConfig() project.public_repository_config = test_util.MockRepositoryConfig( '', repository=test_util.MockRepository('')) internal_creator = test_util.StaticCodebaseCreator({ '1001': 'simple_python', '1002': 'simple_python2' }) public_creator = test_util.StaticCodebaseCreator( {'1': 'simple_python'}, lambda: mock_client) config = actions.MigrationConfig( base.Migration.EXPORT, internal_creator, project.internal_repository_config, public_creator, project.public_repository_config, project.public_repository_config.MakeRepository()[0], project.export_strategy) revisions = [base.Revision('1002', changelog='log')] action = actions.Migration(base.Revision('1001'), base.Revision('1'), revisions, project, [], config, False, -1) result = action.Perform(db=mock_db) equivalence_check = result.actions[0] self.assertEqual(equivalence_check.internal_revision, '1002') self.assertEqual(equivalence_check.public_revision, '2') self.assertFalse(result.actions[1:]) self.assertTrue(mock_editor.ChangesMade()) expected = base.Migration( migration_id='88', direction=base.Migration.EXPORT, status=base.Migration.SUBMITTED, up_to_revision=base.Revision('1002'), revisions=revisions, submitted_as=base.Revision('2'), changelog='log', ) self.assertEqual(mock_db.GetMigration('88').Dict(), expected.Dict())
def testSkipsBrokenCodebase(self): mock_db = test_util.MockDbClient(migration_id_seed=88) mock_editor = test_util.MockEditor() mock_client = test_util.MockClient( lambda migration_strategy, revisions: mock_editor) project = test_util.EmptyMoeProjectConfig() internal_creator = test_util.StaticCodebaseCreator( { '1001': 'simple_python', '1002': None, '1003': 'simple_python2', }, lambda: mock_client) public_creator = test_util.StaticCodebaseCreator( {'1': 'simple_python'}) config = actions.MigrationConfig(base.Migration.EXPORT, internal_creator, project.internal_repository_config, public_creator, project.export_strategy, None, project.public_repository_config) revisions = [ base.Revision('1002', changelog='1002'), base.Revision('1003', changelog='1003') ] action = actions.Migration(base.Revision('1001'), base.Revision('1'), revisions, project, [], config, False, 1) result = action.Perform(db=mock_db) migration = result.actions[0] migrated_revisions = migration.revisions # because we couldn't migrate 1002 on its own, we now want to migrate # 1002 *and* 1003 self.assertEqual(len(migrated_revisions), 2) self.assertEqual(migrated_revisions[0].rev_id, '1002') self.assertEqual(migrated_revisions[1].rev_id, '1003')
def _ChooseActions(self, book): """Choose the actions we should perform. Args: book: Book, the book Returns: sequence of Actions NB(dbentley): an Action will, when performed, have the chance to modify the Actions performed after it. """ result = [] # TODO(dbentley): Here is where we should determine what we are going # to do in this run. # First, we check that an equivalence is, in fact, equivalent result.append( actions.EquivalenceCheck( book.equivalence.internal_revision, book.equivalence.public_revision, self.project.config, self.project.translators, actions.EquivalenceCheck.ErrorIfDifferent)) # Next, we check newly-finished migrations. # Specifically, we think the up_to_revision and submitted_as may be # equivalent. for m in book.finished_imports: result.append( actions.EquivalenceCheck(m.submitted_as.rev_id, m.up_to_revision.rev_id, self.project.config, self.project.translators, actions.EquivalenceCheck.NoteIfSame)) for m in book.finished_exports: result.append( actions.EquivalenceCheck( # Note the different order of arguments m.up_to_revision.rev_id, m.submitted_as.rev_id, self.project.config, self.project.translators, actions.EquivalenceCheck.NoteIfSame)) # At this point, we're just trying to see if we happen to be lucky. # We could check all pairs of revisions, but that's expensive. # Instead, we just see if we happen to be equivalent. result.append( actions.EquivalenceCheck( book.current.internal_revision, book.current.public_revision, self.project.config, self.project.translators, actions.EquivalenceCheck.NoteAndStopIfSame)) if book.revisions_to_import: import_config = actions.MigrationConfig( base.Migration.IMPORT, self.project.public_codebase_creator, self.project.config.public_repository_config, self.project.internal_codebase_creator, self.project.config.internal_repository_config, self.project.internal_repository, self.project.config.import_strategy) # TODO(dbentley): we can't handle separate revisions from # a repository that is a DVCS. We should check this. if self.project.config.import_strategy.separate_revisions: num_revisions_to_migrate = 1 else: num_revisions_to_migrate = -1 # Which public revision should we apply this migration against? # We should apply it against the public revision that corresponds to the # last internal revision to get exported. This is probably the last # export. But an equivalence will do too. So use last export, and if # it doesn't exist, use equivalence. if book.last_import: previous_revision = book.last_import.up_to_revision applied_against = book.last_import.submitted_as else: previous_revision = self.project.public_repository.MakeRevisionFromId( book.equivalence.public_revision) applied_against = self.project.internal_repository.MakeRevisionFromId( book.equivalence.internal_revision) result.append( actions.Migration(previous_revision, applied_against, book.revisions_to_import, self.project.config, self.project.translators, import_config, False, num_revisions_to_migrate)) # TODO(dbentley): we should only do one of importing or exporting per run. if book.revisions_to_export: # Choose exports export_config = actions.MigrationConfig( base.Migration.EXPORT, self.project.internal_codebase_creator, self.project.config.internal_repository_config, self.project.public_codebase_creator, self.project.config.public_repository_config, self.project.public_repository, self.project.config.export_strategy) if self.project.config.export_strategy.separate_revisions: num_revisions_to_migrate = 1 else: num_revisions_to_migrate = -1 # Choose correspondence to migrate against (as described above). if book.last_export: previous_revision = book.last_export.up_to_revision applied_against = book.last_export.submitted_as else: previous_revision = self.project.internal_repository.MakeRevisionFromId( book.equivalence.internal_revision) applied_against = self.project.public_repository.MakeRevisionFromId( book.equivalence.public_revision) result.append( actions.Migration(previous_revision, applied_against, book.revisions_to_export, self.project.config, self.project.translators, export_config, False, num_revisions_to_migrate)) return result