def test_simple_failure(self): # type: () -> None command = ("test", "bad-command") try: remctl.remctl("localhost", 14373, self.principal, command) except remctl.RemctlProtocolError as error: self.assertEqual(str(error), str(b"Unknown command"))
def index(self, **kw): server = config['sipbmp3.server'] out = dict(page="index") volume = int(remctl(server, command=["volume", "get"]).stdout.rstrip()) playing = remctl(server, command=["status", "get"]).stdout # Todo: add better parsing if not playing: playing = "Nothing playing" if not "volume" in kw: kw["volume"] = volume return dict( page="index", playing=playing, volume=volume, volume_form=volume_form, volume_data=kw, )
def test_simple_success(self): # type: () -> None command = ("test", "test") result = remctl.remctl("localhost", 14373, self.principal, command) self.assertEqual(result.stdout, b"hello world\n") self.assertEqual(result.stderr, None) self.assertEqual(result.status, 0)
def test_simple_status(self): # type: () -> None command = ["test", "status", "2"] result = remctl.remctl( host="localhost", command=command, port="14373", principal=self.principal, ) self.assertEqual(result.stdout, None) self.assertEqual(result.stderr, None) self.assertEqual(result.status, 2)
def volume(self, **kw): server = config['sipbmp3.server'] remctl(server, command=["volume", "set", kw["volume"]]) redirect('index')
def test_simple_errors(self): # type: () -> None try: remctl.remctl("localhost") except ValueError as error: self.assertEqual(str(error), "command must not be empty") try: remctl.remctl(host="localhost", command="foo") except TypeError as error: self.assertEqual( str(error), "command must be a sequence or iterator" ) try: remctl.remctl("localhost", "foo", self.principal, []) except TypeError as error: self.assertEqual(str(error), "port must be a number: 'foo'") try: remctl.remctl("localhost", -1, self.principal, []) except ValueError as error: self.assertEqual(str(error), "invalid port number: -1") try: remctl.remctl("localhost", 14373, self.principal, []) except ValueError as error: self.assertEqual(str(error), "command must not be empty") try: remctl.remctl("localhost", 14373, self.principal, "test") except TypeError as error: self.assertEqual( str(error), "command must be a sequence or iterator" )