diff --git a/python-api/gstswitch/server.py b/python-api/gstswitch/server.py index b925aed..4adbc7d 100644 --- a/python-api/gstswitch/server.py +++ b/python-api/gstswitch/server.py @@ -17,11 +17,19 @@ def __init__(self): def set_video_port(self, video_port): """Sets the server's video port + Should be between 1 and 65535 :param video_port: Video port :returns: nothing """ - self.VIDEO_PORT = str(video_port) + try: + video_port + 1 + except TypeError: + raise TypeError + if video_port > 0 and video_port < 65536: + self.VIDEO_PORT = str(video_port) + else: + raise ValueError('video port not in range') def set_audio_port(self, audio_port): """Sets the server's audio port @@ -175,7 +183,7 @@ def set_executable_path(self, path): class Server(BaseServer, ServerProcess): """Controls all Server operations - :param path: Path where all exceutables gst-switch-srv, gst-launch-1.0, wtc are located + :param path: Path where all exceutables gst-switch-srv, gst-launch-1.0, etc are located :param video_port: The video port number - default = 3000 :param audio_port: The audio port number - default = 4000 :param control_port: The control port number - default = 5000 diff --git a/python-api/gstswitch/test_BaseServer.py b/python-api/gstswitch/test_BaseServer.py new file mode 100644 index 0000000..3c399fb --- /dev/null +++ b/python-api/gstswitch/test_BaseServer.py @@ -0,0 +1,47 @@ +from server import BaseServer +import pytest + + +class TestSetVideoPort(object): + + def test_negative(self): + port = -3 + instance = BaseServer() + with pytest.raises(ValueError): + instance.set_video_port(port) + + def test_zero(self): + port = 0 + instance = BaseServer() + with pytest.raises(ValueError): + instance.set_video_port(port) + + def test_huge(self): + port = 1e6 + instance = BaseServer() + with pytest.raises(ValueError): + instance.set_video_port(port) + + def test_none(self): + port = None + instance = BaseServer() + with pytest.raises(TypeError): + instance.set_video_port(port) + + def test_string(self): + port = "" + instance = BaseServer() + with pytest.raises(TypeError): + instance.set_video_port(port) + + def test_dict(self): + port = {} + instance = BaseServer() + with pytest.raises(TypeError): + instance.set_video_port(port) + + def test_normal(self): + port = 3000 + instance = BaseServer() + instance.set_video_port(port) + assert port == int(instance.VIDEO_PORT)