Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
tests: add a test for OpenUriExtended
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy committed May 13, 2021
1 parent ba60b7a commit 1ec637c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/service/functional/MediaHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def check_value(interface, changed, invalidated):
def open_uri(self, uri):
return self.__player.OpenUri(uri)

def open_uri_extended(self, uri, http_headers):
return self.__player.OpenUriExtended(uri, http_headers)

def play(self):
self.__player.Play()

Expand Down
29 changes: 29 additions & 0 deletions tests/service/functional/test_media_hub_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,32 @@ def test_low_battery(
battery_ctrl.set_power_level('low')

assert player.wait_for_prop('PlaybackStatus', 'Paused')

def test_http_headers(self, bus_obj, dbus_monitor, media_hub_service_full):
from http.server import HTTPServer, BaseHTTPRequestHandler
request = None

class HttpHandler(BaseHTTPRequestHandler):
def __init(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def do_GET(self):
print('HTTP server captured request!')
nonlocal request
request = self

httpd = HTTPServer(('', 8000), HttpHandler)

media_hub = MediaHub.Service(bus_obj)
(object_path, uuid) = media_hub.create_session()
player = MediaHub.Player(bus_obj, object_path)

audio_file = 'http://localhost:8000/some-file.mp3'
player.open_uri_extended(audio_file, {
'Cookie': 'biscuit', 'User-Agent': 'MediaHub'})
player.play()
httpd.handle_request()
assert request.path == '/some-file.mp3'
assert 'Cookie' in request.headers
assert request.headers['Cookie'] == 'biscuit'
assert request.headers['User-Agent'] == 'MediaHub'

0 comments on commit 1ec637c

Please sign in to comment.