baseurl.py (686B)
1 import mozhttpd 2 import mozunit 3 import pytest 4 5 6 @pytest.fixture(name="httpd") 7 def fixture_httpd(): 8 """Yields a started MozHttpd server.""" 9 httpd = mozhttpd.MozHttpd(port=0) 10 httpd.start(block=False) 11 yield httpd 12 httpd.stop() 13 14 15 def test_base_url(httpd): 16 port = httpd.httpd.server_port 17 18 want = f"http://127.0.0.1:{port}/" 19 got = httpd.get_url() 20 assert got == want 21 22 want = f"http://127.0.0.1:{port}/cheezburgers.html" 23 got = httpd.get_url(path="/cheezburgers.html") 24 assert got == want 25 26 27 def test_base_url_when_not_started(): 28 httpd = mozhttpd.MozHttpd(port=0) 29 assert httpd.get_url() is None 30 31 32 if __name__ == "__main__": 33 mozunit.main()