def test_create_timeout_no_number(self): parser = configparser.ConfigParser() parser.read_string('''[section] url = anurl timeout = string''') with pytest.raises(ConfigurationError): Kodi.create('name', parser['section'])
def test_create_timeout_no_number(self) -> None: parser = configparser.ConfigParser() parser.read_string( """ [section] url = anurl timeout = string """ ) with pytest.raises(ConfigurationError): Kodi.create("name", parser["section"])
def test_create_default_url(self) -> None: parser = configparser.ConfigParser() parser.read_string("""[section]""") check = Kodi.create("name", parser["section"]) assert check._url.split("?")[0] == "http://localhost:8080/jsonrpc"
def test_json_error(self, mocker) -> None: mock_reply = mocker.MagicMock() mock_reply.json.side_effect = json.JSONDecodeError("test", "test", 42) mocker.patch("requests.Session.get", return_value=mock_reply) with pytest.raises(TemporaryCheckError): Kodi("foo", url="url", timeout=10).check()
def test_request_error(self, mocker) -> None: mocker.patch( "requests.Session.get", side_effect=requests.exceptions.RequestException() ) with pytest.raises(TemporaryCheckError): Kodi("foo", url="url", timeout=10).check()
def test_assertion_no_result(self, mocker) -> None: mock_reply = mocker.MagicMock() mock_reply.json.return_value = {"id": 1, "jsonrpc": "2.0"} mocker.patch("requests.Session.get", return_value=mock_reply) with pytest.raises(TemporaryCheckError): Kodi("foo", url="url", timeout=10).check()
def test_json_error(self, mocker): mock_reply = mocker.MagicMock() mock_reply.json.side_effect = json.JSONDecodeError('test', 'test', 42) mocker.patch('requests.Session.get', return_value=mock_reply) with pytest.raises(TemporaryCheckError): Kodi('foo', url='url', timeout=10).check()
def test_not_playing(self, mocker) -> None: mock_reply = mocker.MagicMock() mock_reply.json.return_value = {"id": 1, "jsonrpc": "2.0", "result": []} mocker.patch("requests.Session.get", return_value=mock_reply) assert Kodi("foo", url="url", timeout=10).check() is None mock_reply.json.assert_called_once_with()
def test_create(self): parser = configparser.ConfigParser() parser.read_string('''[section] url = anurl timeout = 12''') check = Kodi.create('name', parser['section']) assert check._url.startswith('anurl') assert check._timeout == 12
def test_playing(self, mocker): mock_reply = mocker.MagicMock() mock_reply.json.return_value = { "id": 1, "jsonrpc": "2.0", "result": [{"playerid": 0, "type": "audio"}]} mocker.patch('requests.Session.get', return_value=mock_reply) assert Kodi('foo', url='url', timeout=10).check() is not None mock_reply.json.assert_called_once_with()
def test_create_suspend_while_paused(self): parser = configparser.ConfigParser() parser.read_string('''[section] url = anurl suspend_while_paused = True''') check = Kodi.create('name', parser['section']) assert check._url.startswith('anurl') assert check._suspend_while_paused
def test_create_suspend_while_paused(self) -> None: parser = configparser.ConfigParser() parser.read_string( """ [section] url = anurl suspend_while_paused = True """ ) check = Kodi.create("name", parser["section"]) assert check._url.startswith("anurl") assert check._suspend_while_paused
def test_not_playing_suspend_while_paused(self, mocker) -> None: mock_reply = mocker.MagicMock() mock_reply.json.return_value = { "id": 1, "jsonrpc": "2.0", "result": {"Player.Playing": False}, } mocker.patch("requests.Session.get", return_value=mock_reply) assert ( Kodi("foo", url="url", timeout=10, suspend_while_paused=True).check() is None ) mock_reply.json.assert_called_once_with()
def test_playing_suspend_while_paused(self, mocker): mock_reply = mocker.MagicMock() mock_reply.json.return_value = { "id": 1, "jsonrpc": "2.0", "result": { "Player.Playing": True } } mocker.patch('requests.Session.get', return_value=mock_reply) assert Kodi('foo', url='url', timeout=10, suspend_while_paused=True).check() is not None mock_reply.json.assert_called_once_with()
def create_instance(self, name): return Kodi(name, url="url", timeout=10)
def test_request_error(self, mocker): mocker.patch('requests.Session.get', side_effect=requests.exceptions.RequestException()) with pytest.raises(TemporaryCheckError): Kodi('foo', url='url', timeout=10).check()