testing/marionette/harness/marionette_harness/tests/harness_unit/test_serve.py
author longsonr <longsonr@gmail.com>
Fri, 18 Sep 2020 13:45:32 +0000
changeset 549365 bf7094ba8ae6fcc116bc31caf111620252af7f45
parent 533900 05abde20a94b913447b8279ea6d7035b1266d17a
permissions -rw-r--r--
Bug 1665921 - check result of SVGGeometryProperty calls r=emilio Differential Revision: https://phabricator.services.mozilla.com/D90694

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import

import types

import six

import mozunit
import pytest

from marionette_harness.runner import serve
from marionette_harness.runner.serve import iter_proc, iter_url


def teardown_function(func):
    for server in [server for server in iter_proc(serve.servers) if server.is_alive]:
        server.stop()
        server.kill()


def test_registered_servers():
    # [(name, factory), ...]
    assert serve.registered_servers[0][0] == "http"
    assert serve.registered_servers[1][0] == "https"


def test_globals():
    assert serve.default_doc_root is not None
    assert serve.registered_servers is not None
    assert serve.servers is not None


def test_start():
    serve.start()
    assert len(serve.servers) == 2
    assert "http" in serve.servers
    assert "https" in serve.servers
    for url in iter_url(serve.servers):
        assert isinstance(url, six.string_types)


def test_start_with_custom_root(tmpdir_factory):
    tdir = tmpdir_factory.mktemp("foo")
    serve.start(str(tdir))
    for server in iter_proc(serve.servers):
        assert server.doc_root == tdir


def test_iter_proc():
    serve.start()
    for server in iter_proc(serve.servers):
        server.stop()


def test_iter_url():
    serve.start()
    for url in iter_url(serve.servers):
        assert isinstance(url, six.string_types)


def test_where_is():
    serve.start()
    assert serve.where_is("/") == serve.servers["http"][1].get_url("/")
    assert serve.where_is("/", on="https") == serve.servers["https"][1].get_url("/")


if __name__ == "__main__":
    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-', '--capture', 'no')