mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-25 06:56:15 +02:00
moved controller tests into subdir
This commit is contained in:
parent
c277f87491
commit
67ba050a6c
3 changed files with 50 additions and 16 deletions
66
control/testClient.py
Executable file
66
control/testClient.py
Executable file
|
@ -0,0 +1,66 @@
|
|||
import sys
|
||||
import telnetlib
|
||||
import json
|
||||
import threading
|
||||
import time
|
||||
|
||||
HOST = "localhost"
|
||||
|
||||
telnet = telnetlib.Telnet(HOST, 1705)
|
||||
|
||||
|
||||
class ReaderThread(threading.Thread):
|
||||
def __init__(self, tn, stop_event):
|
||||
super(ReaderThread, self).__init__()
|
||||
self.tn = tn
|
||||
self.stop_event = stop_event
|
||||
|
||||
def run(self):
|
||||
while (not self.stop_event.is_set()):
|
||||
response = self.tn.read_until("\r\n", 2)
|
||||
if response:
|
||||
print("received: " + response)
|
||||
jresponse = json.loads(response)
|
||||
print(json.dumps(jresponse, indent=2))
|
||||
print("\r\n")
|
||||
|
||||
|
||||
def doRequest( str ):
|
||||
print("send: " + str)
|
||||
telnet.write(str)
|
||||
time.sleep(1)
|
||||
return;
|
||||
|
||||
|
||||
t_stop= threading.Event()
|
||||
t = ReaderThread(telnet, t_stop)
|
||||
t.start()
|
||||
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"System.GetStatus\", \"id\": 1}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"System.GetStatus\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\"}, \"id\": 2}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"volume\": 10}, \"id\": 3}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"volume\": 30}, \"id\": 4}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"volume\": 50}, \"id\": 5}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"volume\": 70}, \"id\": 6}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetMute\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"mute\": true}, \"id\": 9}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetMute\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"mute\": false}, \"id\": 9}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetMute\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"mute\": true}, \"id\": 9}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetMute\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"mute\": false}, \"id\": 9}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetLatency\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"latency\": 10}, \"id\": 7}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetName\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"name\": \"living room\"}, \"id\": 8}\r\n")
|
||||
#invalid json
|
||||
doRequest("some message to test invalid requests\r\n")
|
||||
#missing id
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetName\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"name\": \"living room\"}}\r\n")
|
||||
#missing parameter
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetName\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\"}, \"id\": 8}\r\n")
|
||||
#invalid method
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"NonExistingMethod\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\"}, \"id\": 8}\r\n")
|
||||
#out of range
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"volume\": 101}, \"id\": 3}\r\n")
|
||||
|
||||
s = raw_input("")
|
||||
print(s)
|
||||
t_stop.set();
|
||||
t.join()
|
||||
telnet.close
|
Loading…
Add table
Add a link
Reference in a new issue