Skip to content

Commit

Permalink
Add unit tests for get volume function
Browse files Browse the repository at this point in the history
  • Loading branch information
Liborsaf committed Apr 6, 2024
1 parent 96b8f06 commit 1ae988c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/data/volume.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetVolumeResponse xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
<CurrentVolume>64</CurrentVolume>
</u:GetVolumeResponse>
</s:Body>
</s:Envelope>
15 changes: 15 additions & 0 deletions tests/device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
BASE_URL = 'http://test/sony'
AV_TRANSPORT_URL = 'http://test:52323/upnp/control/AVTransport'
AV_TRANSPORT_URL_NO_MEDIA = 'http://test2:52323/upnp/control/AVTransport'
RENDERING_CONTROL_URL = 'http://test:52323/upnp/control/RenderingControl'
REQUESTS_ERROR = 'http://ERROR'

ACTION_LIST = [
Expand Down Expand Up @@ -168,6 +169,12 @@ def mocked_requests_post(*args, **kwargs):
read_file(
'data/playing_status_legacy_no_media.xml'))

elif url == RENDERING_CONTROL_URL:
return MockResponse(None,
200,
read_file(
'data/volume.xml'))

elif url == COMMAND_LIST_V4:
json_data = jsonpickle.decode(read_file('data/commandList.json'))
return MockResponse(json_data, 200, "")
Expand Down Expand Up @@ -849,6 +856,14 @@ def test_playing_status_no_media_legacy(self, mocked_requests_post):
device.av_transport_url = AV_TRANSPORT_URL
self.assertEqual("PLAYING", device.get_playing_status())

@mock.patch('requests.post', side_effect=mocked_requests_post)
def test_volume(self, mocked_requests_post):
device = self.create_device()
self.assertEqual(-1, device.get_volume())

device.rendering_control_url = RENDERING_CONTROL_URL
self.assertEqual(64, device.get_volume())

def test_irrc_is_dmr(self):
dev = SonyDevice(host="none", nickname="none", ircc_port=42, dmr_port=42)
self.assertEqual(dev.dmr_url, dev.ircc_url)
Expand Down

0 comments on commit 1ae988c

Please # to comment.