コード例 #1
0
    def test__execute_identical_source_target_raises(self):
        self.args['to_gphome'] = '/from/gphome'
        subject = MigratePackages(**self.args)

        expected_raise = "The source and target GPHOMEs, %s => %s, must differ for packages to be migrated." % (self.args['from_gphome'], self.args['to_gphome'])
        with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, expected_raise):
            subject.execute()
コード例 #2
0
 def test__execute_finds_no_packages(self):
     self.os_path_samefile.side_effect = [True, False]
     subject = MigratePackages(**self.args)
     subject.execute()
     self.mock_logger.info.assert_called_with(
         'There are no packages to migrate from %s.' %
         self.args['from_gphome'])
コード例 #3
0
    def test__execute_target_gphome_mismatch_raises(self):
        self.os_path_samefile.return_value = False
        self.args['to_gphome'] = '/wrong/gphome'
        subject = MigratePackages(**self.args)

        expected_raise = "The target GPHOME, %s, must match the current \$GPHOME used to launch gppkg." % self.args['to_gphome']
        with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded, expected_raise):
            subject.execute()
コード例 #4
0
    def test__execute_identical_source_target_raises(self):
        self.args['to_gphome'] = '/from/gphome'
        subject = MigratePackages(**self.args)

        expected_raise = "The source and target GPHOMEs, %s => %s, must differ for packages to be migrated." % (
            self.args['from_gphome'], self.args['to_gphome'])
        with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded,
                                     expected_raise):
            subject.execute()
コード例 #5
0
    def test__execute_finds_some_packages(self):
        self.os_path_samefile.side_effect = [True, False]
        self.mock_listdir.return_value = ['sample.gppkg', 'sample2.gppkg', 'another-long-one.gppkg']

        subject = MigratePackages(**self.args)
        subject.execute()

        log_messages = [args[1][0] for args in self.mock_logger.method_calls]
        self.assertIn('The following packages will be migrated: %s' % ", ".join(self.mock_listdir.return_value), log_messages)
        self.assertIn('The package migration has completed.', log_messages)
コード例 #6
0
    def test__execute_target_gphome_mismatch_raises(self):
        self.os_path_samefile.return_value = False
        self.args['to_gphome'] = '/wrong/gphome'
        subject = MigratePackages(**self.args)

        expected_raise = "The target GPHOME, %s, must match the current \$GPHOME used to launch gppkg." % self.args[
            'to_gphome']
        with self.assertRaisesRegexp(ExceptionNoStackTraceNeeded,
                                     expected_raise):
            subject.execute()
コード例 #7
0
    def test__execute_catches_AlreadyInstalledError(self):
        self.os_path_samefile.side_effect = [True, False]
        self.mock_listdir.return_value = ['sample.gppkg', 'sample2.gppkg', 'another-long-one.gppkg']
        self.mock_install_package_locally.return_value.run.side_effect = AlreadyInstalledError("sample.gppkg")

        subject = MigratePackages(**self.args)
        subject.execute()
        log_messages = [args[1][0] for args in self.mock_logger.method_calls]
        self.assertIn('The following packages will be migrated: %s' % ", ".join(self.mock_listdir.return_value), log_messages)
        self.assertIn('sample.gppkg is already installed.', log_messages)
        self.assertIn('The package migration has completed.', log_messages)
コード例 #8
0
    def test__execute_catches_Exception_failed_to_migrate(self):
        self.os_path_samefile.side_effect = [True, False]
        self.mock_listdir.return_value = ['sample.gppkg', 'sample2.gppkg', 'another-long-one.gppkg']

        # Let's make the second package fail/raise an exception
        self.mock_install_package_locally.return_value.run.side_effect = [None, Exception("foobar something bad"), None]

        subject = MigratePackages(**self.args)
        subject.execute()
        log_messages = [args[1][0] for args in self.mock_logger.method_calls]
        self.assertIn('The following packages will be migrated: %s' % ", ".join(self.mock_listdir.return_value), log_messages)
        self.assertIn('Failed to migrate %s from %s' % (os.path.join(self.args['from_gphome'], ARCHIVE_PATH),
                                                        self.mock_listdir.return_value[1]), log_messages)
        self.assertIn('The package migration has completed.', log_messages)
コード例 #9
0
    def test__execute_finds_some_packages(self):
        self.os_path_samefile.side_effect = [True, False]
        self.mock_listdir.return_value = [
            'sample.gppkg', 'sample2.gppkg', 'another-long-one.gppkg'
        ]

        subject = MigratePackages(**self.args)
        subject.execute()

        log_messages = [args[1][0] for args in self.mock_logger.method_calls]
        self.assertIn(
            'The following packages will be migrated: %s' %
            ", ".join(self.mock_listdir.return_value), log_messages)
        self.assertIn('The package migration has completed.', log_messages)
コード例 #10
0
    def test__execute_catches_AlreadyInstalledError(self):
        self.os_path_samefile.side_effect = [True, False]
        self.mock_listdir.return_value = [
            'sample.gppkg', 'sample2.gppkg', 'another-long-one.gppkg'
        ]
        self.mock_install_package_locally.return_value.run.side_effect = AlreadyInstalledError(
            "sample.gppkg")

        subject = MigratePackages(**self.args)
        subject.execute()
        log_messages = [args[1][0] for args in self.mock_logger.method_calls]
        self.assertIn(
            'The following packages will be migrated: %s' %
            ", ".join(self.mock_listdir.return_value), log_messages)
        self.assertIn('sample.gppkg is already installed.', log_messages)
        self.assertIn('The package migration has completed.', log_messages)
コード例 #11
0
    def test__execute_catches_Exception_failed_to_migrate(self):
        self.os_path_samefile.side_effect = [True, False]
        self.mock_listdir.return_value = [
            'sample.gppkg', 'sample2.gppkg', 'another-long-one.gppkg'
        ]

        # Let's make the second package fail/raise an exception
        self.mock_install_package_locally.return_value.run.side_effect = [
            None, Exception("foobar something bad"), None
        ]

        subject = MigratePackages(**self.args)
        subject.execute()
        log_messages = [args[1][0] for args in self.mock_logger.method_calls]
        self.assertIn(
            'The following packages will be migrated: %s' %
            ", ".join(self.mock_listdir.return_value), log_messages)
        self.assertIn(
            'Failed to migrate %s from %s' %
            (os.path.join(self.args['from_gphome'],
                          ARCHIVE_PATH), self.mock_listdir.return_value[1]),
            log_messages)
        self.assertIn('The package migration has completed.', log_messages)
コード例 #12
0
 def test__execute_finds_no_packages(self):
     self.os_path_samefile.side_effect = [True, False]
     subject = MigratePackages(**self.args)
     subject.execute()
     self.mock_logger.info.assert_called_with('There are no packages to migrate from %s.' % self.args['from_gphome'])