Esempio n. 1
0
    def testMigration(self):
        project = self._CreateProject('Migration', with_equivalence=True)
        migration_id = self._client.StartMigration(
            base.Migration.EXPORT, InternalRevision('1003', project))
        migration = self._client.GetMigration(migration_id)
        expected = base.Migration(
            **{
                'migration_id': migration_id,
                'status': 'Pending',
                'direction': 'export',
                'project_name': 'Migration',
                'up_to_revision': InternalRevision('1003', project),
                'submitted_as': None
            })
        self.assertDictEqual(migration.Dict(), expected.Dict())

        migration = self._client.FindMigration(
            InternalRevision('1003', project))
        self.assertDictEqual(migration.Dict(), expected.Dict())

        self._client.FinishMigration(migration_id,
                                     PublicRevision('5', project))
        migration = self._client.GetMigration(migration_id)
        expected = base.Migration(
            **{
                'migration_id': migration_id,
                'status': 'Submitted',
                'direction': 'export',
                'project_name': 'Migration',
                'up_to_revision': InternalRevision('1003', project),
                'submitted_as': PublicRevision('5', project).Dump(),
            })
        self.assertDictEqual(migration.Dict(), expected.Dict())

        migration = self._client.FindMigration(
            InternalRevision('1003', project))
        self.assertDictEqual(migration.Dict(), expected.Dict())

        migration = self._client.FindMigration(
            InternalRevision('1007', project))
        self.assertEqual(None, migration)

        migration = self._client.HasRevisionBeenMigrated(
            InternalRevision('1003', project))
        self.assertEqual(expected.Dict(), migration.Dict())

        migration = self._client.HasRevisionBeenMigrated(
            InternalRevision('1007', project))
        self.assertEqual(None, migration)
Esempio n. 2
0
 def testStoringRevisions(self):
     project = self._CreateProject('Revisions', with_equivalence=True)
     revision_1002 = InternalRevision('1002',
                                      project,
                                      author='*****@*****.**')
     revision_1004 = InternalRevision('1004',
                                      project,
                                      author='*****@*****.**')
     migration_id = self._client.StartMigration(
         base.Migration.EXPORT,
         revision_1004,
         migrated_revisions=[revision_1002, revision_1004])
     migration = self._client.GetMigration(migration_id, abbreviated=False)
     expected = base.Migration(
         **{
             'migration_id': migration_id,
             'status': 'Pending',
             'direction': 'export',
             'project_name': 'LongLog',
             'up_to_revision': revision_1004,
             'submitted_as': None,
             'revisions': [revision_1002.Dump(),
                           revision_1004.Dump()],
         })
     self.assertDictEqual(migration.Dict(), expected.Dict())
Esempio n. 3
0
    def testLongChangelog(self):
        project = self._CreateProject('LongLog', with_equivalence=True)
        changelog = resources.GetResource(
            TestResourceName('long_changelog.txt'))
        migration_id = self._client.StartMigration(base.Migration.EXPORT,
                                                   InternalRevision(
                                                       '1003', project),
                                                   changelog=changelog)
        migration = self._client.GetMigration(migration_id, abbreviated=False)
        expected = base.Migration(
            **{
                'migration_id': migration_id,
                'changelog': changelog,
                'status': 'Pending',
                'direction': 'export',
                'project_name': 'LongLog',
                'up_to_revision': InternalRevision('1003', project),
                'submitted_as': None
            })
        self.assertDictEqual(migration.Dict(), expected.Dict())

        migration = self._client.FindMigration(InternalRevision(
            '1003', project),
                                               abbreviated=False)
        self.assertDictEqual(migration.Dict(), expected.Dict())
Esempio n. 4
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())
Esempio n. 5
0
 def NoteImport(up_to_revision, submitted_as):
     migration_id = self._client.NoteMigration(base.Migration.IMPORT,
                                               up_to_revision,
                                               submitted_as)
     imports.append(
         base.Migration(migration_id, base.Migration.IMPORT,
                        base.Migration.SUBMITTED, up_to_revision,
                        submitted_as))
Esempio n. 6
0
  def StartMigration(self, direction, up_to_revision,
                     changelog='', diff='', link='', migrated_revisions=None,
                     source_repository='', pre_approved=False):
    """Note the start of a migration."""
    migration = base.Migration(
        self._NextID(), direction,
        pre_approved and base.Migration.APPROVED or base.Migration.ACTIVE,
        up_to_revision, changelog=changelog, diff=diff, link=link,
        revisions=migrated_revisions)

    self.migrations[migration.migration_id] = migration
    return migration.migration_id
Esempio n. 7
0
    def HasRevisionBeenMigrated(self, revision):
        request_dict = {
            'project_name': self.project.name,
            'revision': simplejson.dumps(revision.Dump())
        }

        data = self._Get('migration_for_revision',
                         request_dict).get('migration')
        if data:
            result = base.Migration(**StringifyKeys(data))
            return result
        else:
            return None
Esempio n. 8
0
    def GetMigration(self, migration_id, abbreviated=True):
        """Get one migration from the database.

    Args:
      migration_id: str, the id of the migration to get info about.
      abbreviated: bool, whether to skip returning large data fields

    Returns:
      base.Migration
    """
        info = self.MigrationInfo(migration_id, abbreviated)
        if not info:
            return None
        return base.Migration(**StringifyKeys(info))
Esempio n. 9
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())
Esempio n. 10
0
    def FindMigration(self, up_to_revision, abbreviated=True):
        """Get one migration from the database.

    Args:
      up_to_revision: base.Revision

    Returns:
      base.Migration or None if there is no matching migration
    """
        result = self._Get(
            'find_migration', {
                'project_name': self.project.name,
                'up_to_revision': simplejson.dumps(up_to_revision.Dump()),
                'abbreviated': abbreviated
            })
        if result:
            return base.Migration(**StringifyKeys(result))
        else:
            return None
Esempio n. 11
0
    def testNoteMigration_new(self):
        project = self._CreateProject('NoteNewMigration',
                                      with_equivalence=True)
        migration_id = self._client.NoteMigration(
            base.Migration.EXPORT, InternalRevision('1003', project),
            PublicRevision('3', project))
        migration = self._client.GetMigration(migration_id)
        expected = base.Migration(
            **{
                'migration_id': migration_id,
                'status': 'Submitted',
                'direction': 'export',
                'project_name': 'NoteNewMigration',
                'up_to_revision': InternalRevision('1003', project),
                'submitted_as': PublicRevision('3', project).Dump(),
            })
        self.assertDictEqual(migration.Dict(), expected.Dict())

        migration = self._client.FindMigration(
            InternalRevision('1003', project))
        self.assertDictEqual(migration.Dict(), expected.Dict())
Esempio n. 12
0
    def testDiff(self):
        project = self._CreateProject('Diff', with_equivalence=True)
        migration_id = self._client.StartMigration(
            base.Migration.EXPORT,
            InternalRevision('1003', project),
            changelog=u'sample changelog\u2026')
        diff = 'somewhat long diff...' * 1000
        self._client.UpdateMigrationDiff(migration_id, diff=diff)

        migration = self._client.GetMigration(migration_id, abbreviated=False)
        expected = base.Migration(
            **{
                'migration_id': migration_id,
                'changelog': u'sample changelog\u2026',
                'status': 'Pending',
                'direction': 'export',
                'diff': diff,
                'project_name': 'Migration',
                'up_to_revision': InternalRevision('1003', project),
                'submitted_as': None
            })
        self.assertDictEqual(migration.Dict(), expected.Dict())
Esempio n. 13
0
def MigrationsFromDicts(migration_dicts):
    return [base.Migration(**StringifyKeys(m)) for m in migration_dicts]