Exemplo n.º 1
0
    def post(self, identifier, *args, **kwargs):
        """Perform an operation on the config."""
        if identifier != 'operation':
            return self._bad_request('Invalid operation')

        data = json_decode(self.request.body)

        if data['type'] == 'RESTART' and data['pid']:
            if not Restart.restart(data['pid']):
                self._not_found('Pid does not match running pid')
            return self._created()

        if data['type'] == 'SHUTDOWN' and data['pid']:
            if not Shutdown.stop(data['pid']):
                self._not_found('Pid does not match running pid')
            return self._created()

        if data['type'] == 'CHECKOUT_BRANCH' and data['branch']:
            if app.BRANCH != data['branch']:
                app.BRANCH = data['branch']
                ui.notifications.message('Checking out branch: ',
                                         data['branch'])

                if self._backup():
                    if self._update(data['branch']):
                        return self._created()
                    else:
                        return self._bad_request('Update failed')
                    return self._bad_request('Backup failed')
            else:
                ui.notifications.message('Already on branch: ', data['branch'])
                return self._bad_request('Already on branch')

        if data['type'] == 'NEED_UPDATE':
            if self._need_update():
                return self._created()
            else:
                return self._bad_request('Update not needed')

        if data['type'] == 'UPDATE':
            if self._update():
                return self._created()
            else:
                return self._bad_request('Update failed')

        if data['type'] == 'BACKUP':
            if self._backup():
                return self._created()
            else:
                return self._bad_request('Backup failed')

        if data['type'] == 'CHECKFORUPDATE':
            check_version = CheckVersion()
            if check_version.check_for_new_version():
                return self._created()
            else:
                return self._bad_request('Version already up to date')

        return self._bad_request('Invalid operation')
Exemplo n.º 2
0
def test_shutdown(pid, expected, app_config):
    """Test shutdown."""
    # Given:
    app_config('PID', 123456)
    app_config('events', Events(None))

    # When
    actual = Shutdown.stop(pid)

    # Then
    assert actual == expected
Exemplo n.º 3
0
    def test_shutdown(self):
        app.PID = 123456
        app.events = Events(None)

        test_cases = {
            0: False,
            '0': False,
            123: False,
            '123': False,
            123456: True,
            '123456': True,
        }

        unicode_test_cases = {
            u'0': False,
            u'123': False,
            u'123456': True,
        }

        for tests in test_cases, unicode_test_cases:
            for (pid, result) in iteritems(tests):
                self.assertEqual(Shutdown.stop(pid), result)
Exemplo n.º 4
0
def test_init():
    assert Restart()
    assert Shutdown()