class TestUpdateProfileAction(BaseTestCase):
    def setUp(self):
        app = Application()
        self.settings = getSettings(app)
        self.switchProfileAction = MagicMock(SwitchProfileAction)
        self.updateProfileAction = UpdateProfileAction(self.settings, self.switchProfileAction)

    def test_execute_withProfile_updatesProfile(self):
        self.updateProfileAction.profile = Profile('test/vimrc')

        self.updateProfileAction.execute()

        self.assertTrue(self.switchProfileAction.execute.called)
        self.assertEqual(self.switchProfileAction.profile, Profile('test/vimrc'))
        self.assertEqual(self.switchProfileAction.update, True)

    def test_execute_withoutProfile_updatesCurrentProfile(self):
        self.settings.currentProfile = Profile('test/currentProfile')
        self.updateProfileAction.profile = None

        self.updateProfileAction.execute()

        self.assertTrue(self.switchProfileAction.execute.called)
        self.assertEqual(self.switchProfileAction.profile, Profile('test/currentProfile'))
        self.assertEqual(self.switchProfileAction.update, True)

    @patch('sys.stdout', new_callable=StringIO)
    def test_execute_withDefaultProfile_printError(self, stdout):
        self.updateProfileAction.profile = Profile('default')

        self.updateProfileAction.execute()

        self.assertFalse(self.switchProfileAction.execute.called)
        self.assertEqual(self.updateProfileAction.exitCode, -1)
        self.assertStdout(stdout, 'Cannot update default profile')
Example #2
0
class TestUpdateProfileAction(BaseTestCase):
    def setUp(self):
        app = Application()
        self.settings = getSettings(app)
        self.switchProfileAction = MagicMock(SwitchProfileAction)
        self.updateProfileAction = UpdateProfileAction(
            self.settings, self.switchProfileAction)

    def test_execute_withProfile_updatesProfile(self):
        self.updateProfileAction.profile = Profile('test/vimrc')

        self.updateProfileAction.execute()

        self.assertTrue(self.switchProfileAction.execute.called)
        self.assertEqual(self.switchProfileAction.profile,
                         Profile('test/vimrc'))
        self.assertEqual(self.switchProfileAction.update, True)

    def test_execute_withoutProfile_updatesCurrentProfile(self):
        self.settings.currentProfile = Profile('test/currentProfile')
        self.updateProfileAction.profile = None

        self.updateProfileAction.execute()

        self.assertTrue(self.switchProfileAction.execute.called)
        self.assertEqual(self.switchProfileAction.profile,
                         Profile('test/currentProfile'))
        self.assertEqual(self.switchProfileAction.update, True)

    @patch('sys.stdout', new_callable=StringIO)
    def test_execute_withDefaultProfile_printError(self, stdout):
        self.updateProfileAction.profile = Profile('default')

        self.updateProfileAction.execute()

        self.assertFalse(self.switchProfileAction.execute.called)
        self.assertEqual(self.updateProfileAction.exitCode, -1)
        self.assertStdout(stdout, 'Cannot update default profile')
Example #3
0
 def setUp(self):
     app = Application()
     self.settings = getSettings(app)
     self.switchProfileAction = MagicMock(SwitchProfileAction)
     self.updateProfileAction = UpdateProfileAction(
         self.settings, self.switchProfileAction)
 def setUp(self):
     app = Application()
     self.settings = getSettings(app)
     self.switchProfileAction = MagicMock(SwitchProfileAction)
     self.updateProfileAction = UpdateProfileAction(self.settings, self.switchProfileAction)