예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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())
예제 #4
0
    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')
예제 #5
0
    def testDifferent(self):
        project = test_util.EmptyMoeProjectConfig()
        ec = actions.EquivalenceCheck(
            '1001', '1', project, [],
            actions.EquivalenceCheck.ErrorIfDifferent)

        internal_creator = test_util.StaticCodebaseCreator(
            {'1001': 'simple_python'})
        public_creator = test_util.StaticCodebaseCreator(
            {'1': 'modified_python'})

        self.assertRaises(base.Error, ec.Perform, internal_creator,
                          public_creator, None, None, FLAGS.test_tmpdir, [])
예제 #6
0
    def testEquivalentIfDifferentButHaveManualDeltas(self):
        project = test_util.EmptyMoeProjectConfig()
        project.manual_equivalence_deltas = True
        ec = actions.EquivalenceCheck(
            '1001', '1', project, [],
            actions.EquivalenceCheck.ErrorIfDifferent)

        internal_creator = test_util.StaticCodebaseCreator(
            {'1001': 'simple_python'})
        public_creator = test_util.StaticCodebaseCreator(
            {'1': 'modified_python'})

        result = ec.Perform(internal_creator, public_creator, None, None,
                            FLAGS.test_tmpdir, [])
        self.assertEqual(result, None)
예제 #7
0
    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())
예제 #8
0
    def testCreateModifiableCopy(self):
        internal_creator = test_util.StaticCodebaseCreator(
            {'1001': 'simple_python'})

        codebase = internal_creator.Create('1001')
        copy = codebase_utils.CreateModifiableCopy(codebase)
        self.assertFalse(base.AreCodebasesDifferent(codebase, copy))
        self.assertFalse(codebase.Path() == copy.Path())
예제 #9
0
    def testSpecifyAnEquivalence(self):
        test_util.MockOutDatabase()
        test_util.MockOutMakeRepositoryConfig(
            repository_configs={
                'test_internal': (None,
                                  test_util.StaticCodebaseCreator(
                                      {'1001': 'simple_python'})),
                'test_public': (
                    None,
                    test_util.StaticCodebaseCreator({'1': 'simple_python'}))
            })

        FLAGS.internal_revision = '1001'
        FLAGS.public_revision = '1'
        FLAGS.project_config_file = test_util.TestResourceFilename(
            os.path.join('init_codebases', 'project_config.txt'))
        init_codebases.main([])
예제 #10
0
    def testWalk(self):
        internal_creator = test_util.StaticCodebaseCreator(
            {'1001': 'simple_python'})

        codebase = internal_creator.Create('1001')
        self.assertEqual(codebase.Walk(), ['foo.py'])

        codebase2 = codebase_utils.Codebase(codebase.ExpandedPath(),
                                            additional_files_re='foo.py')
        self.assertEqual(codebase2.Walk(), [])
예제 #11
0
    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')