def test_supports_info_running(self):
        self.apimock.get_agent_runtime.return_value = {'state': 'running', 'port': 1234}

        Cli(['info', 'first'], out=self.buffer).run()

        self.apimock.get_agent_runtime.assert_called_once_with('first')
        self.assertEqual('port:\t1234\n', self.buffer.getvalue())
    def test_verify_ssl_by_defaut(self):
        self.apimock.list.return_value = [{'name': 'first', 'state': 'stopped', 'uri': 'https://localhost:12345/agents/first'}]

        Cli(['list']).run()

        self.assertEqual(True, self._last_cacert)
        self.assertEqual(True, self._last_ssl)
    def test_supports_info_not_running(self):
        self.apimock.get_agent_runtime.return_value = {'state': 'stopped'}

        Cli(['info', 'first'], out=self.buffer).run()

        self.apimock.get_agent_runtime.assert_called_once_with('first')
        self.assertEqual('Not running\n', self.buffer.getvalue())
    def test_no_ssl(self):
        self.apimock.list.return_value = [{'name': 'first', 'state': 'stopped', 'uri': 'http://localhost:12345/agents/first'}]

        Cli(['--no-ssl', 'list'], out=self.buffer).run()

        self.assertEqual('first\n', self.buffer.getvalue())
        self.assertFalse(self._last_ssl)
    def test_cli_supports_running(self):
        self.apimock.list.return_value = [
            {'name': 'first', 'state': 'stopped', 'uri': 'https://localhost:12345/agents/first'},
            {'name': 'second', 'state': 'running', 'uri': 'https://localhost:12345/agents/second'},
        ]

        Cli(['running'], out=self.buffer).run()

        self.assertEqual('second\n', self.buffer.getvalue())
def run_cli():
    Cli(args=filter_args()).run()
    def test_memory_usage(self):
        self.apimock.memory_usage.return_value = {'total_usage': 1234, 'average_usage': 1234, 'agents': [{'name': 'testagent', 'memory_usage': 1234}]}

        Cli(['memory_usage'], out=self.buffer).run()

        self.assertEqual('memory usage:\t1234\naverage usage:\t1234\n\n\ttestagent:\t1234\n', self.buffer.getvalue())
    def test_cli_supports_stop(self):
        Cli(['stop', 'first']).run()

        self.apimock.stop.assert_called_once_with('first')
    def test_cli_supports_add(self, getpassmock):
        getpassmock.return_value = 'password'
        self.apimock.add.return_value = None
        Cli(['add', 'first']).run()

        self.apimock.add.assert_called_once_with('first', 'password')
 def test_cli_provides_run(self):
     Cli(['-h']).run()
 def test_cli_excepts_args(self):
     Cli([])
    def test_disable_cert_check(self):
        self.apimock.list.return_value = [{'name': 'first', 'state': 'stopped', 'uri': 'https://localhost:12345/agents/first'}]

        Cli(['-k', 'list']).run()

        self.assertEqual(False, self._last_cacert)