def build_test_ical(content:str):
  t = Ical()
  s = http.ContentServer()
  s.serve_content(content)
  s.start()
  t.link = s.url
  return t, s
    def setup_class(cls):
        # Turn off exponential backoff for faster execution.
        _http_client.DEFAULT_RETRY_CONFIG.backoff_factor = 0

        # Start a test server instance scoped to the class.
        server = http.ContentServer()
        server.start()
        cls.httpserver = server
Exemplo n.º 3
0
def httpserver(request):
    """The returned ``httpserver`` provides a threaded HTTP server instance
    running on a randomly assigned port on localhost. It can be taught which
    content (i.e. string) to serve with which response code and comes with
    following attributes:

    * ``code`` - HTTP response code (int)
    * ``content`` - content of next response (str)
    * ``headers`` - response headers (dict)

    Once these attribute are set, all subsequent requests will be answered with
    these values until they are changed or the server is stopped. A more
    convenient way to change these is ::

        httpserver.serve_content(
            content='My content', code=200,
            headers={'content-type': 'text/plain'})

    The server address can be found in property

    * ``url``

    which is the string representation of tuple ``server_address`` (host as
    str, port as int).

    Example::

        import requests
        def scrape(url):
            html = requests.get(url).text
            # some parsing happens here
            # ...
            return result

        def test_retrieve_some_content(httpserver):
            httpserver.serve_content(open('cached-content.html').read())
            assert scrape(httpserver.url) == 'Found it!'

    """
    from pytest_localserver import http
    server = http.ContentServer()
    server.start()
    request.addfinalizer(server.stop)
    return server
Exemplo n.º 4
0
def movie_server(httpserver, sample_output):
    """Based on pytest_localserver.httpserver fixture.

    Server port needs to remain the same, so that responses will match the
    requests during tests against pre-recorded cassettes. Port has been choosen
    from IANA non-asigned ones:
    http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=56478"""

    from pytest_localserver import http
    server = http.ContentServer()  # port=56478)
    server.start()
    httpserver.serve_content(json.dumps(sample_output),
                             200,
                             headers={
                                 "Content-Type": "application/json",
                                 "X-VTS-Testing": "Reporting"
                             })
    yield httpserver
    server.stop()
Exemplo n.º 5
0
    def setUpClass(cls):
        server = http.ContentServer()
        server.start()
        cls.http_server = server

        cls._disable_werkzeug_logging_to_console()
Exemplo n.º 6
0
 def setUpClass(cls):
     server = http.ContentServer()
     server.start()
     cls.http_server = server
Exemplo n.º 7
0
    def host_file(self, content):
        server = http.ContentServer()
        server.start()
        server.serve_content(content)

        self._servers.append(server)
 def setup():
     server = http.ContentServer()
     server.start()
     return server
Exemplo n.º 9
0
 def setup():
     from pytest_localserver import http
     server = http.ContentServer()
     server.start()
     return server