def test_request_a_page():
    root_page = WikiPage(title="FrontPage", uri="/")
    child_page = WikiPage(title="Child1", text="a child page", tags=["foo"])
    root_page.add_child(child_page)
    myapp = WikiApp(root_page)
    request = Request(request_type="GET", uri="/Child1")
    response = myapp.handle_request(request)
    assert response.page.title == "Child1"
def test_search_replace():
    root_page = WikiPage(title="FrontPage", uri="/")
    child_page = WikiPage(title="Child1", text="a child page with text baz")
    root_page.add_child(child_page)
    myapp = WikiApp(root_page)
    request = Request(request_type="POST",
                      uri="/",
                      data={
                          "search_text": "baz",
                          "replace": "foo"
                      })
    response = myapp.handle_request(request)
    assert "Search/Replace" in response.page.title
    assert "Child1" in response.page.text
    child_page_response = myapp.handle_request(
        Request(request_type="GET", uri="/Child1"))
    assert "foo" in child_page_response.page.text
    assert not "baz" in child_page_response.page.text
예제 #3
0
 def __call__(self, environ, start_response):
     try:
         request = Request(environ)
         callback, args = routers.match(request.path)
         response = callback(request, *args)
     except NotFound:
         response = Response(f'<h1>Not found</h1>', status=404)
     start_response(response.status, response.headers.items())
     return iter(response)
예제 #4
0
def test_wiki_page_responder_ok():
    responder = WikiPageResponder()
    request = Request(request_type="GET", uri="/")
    root_page = WikiPage(title="FrontPage", uri="/")
    context = RequestContext(root_page)

    response = responder.make_response(request, context)

    assert response.http_code == "200"
def test_request_a_search():
    root_page = WikiPage(title="FrontPage", uri="/")
    child_page = WikiPage(title="Child1", text="a child page", tags=["foo"])
    root_page.add_child(child_page)
    myapp = WikiApp(root_page)
    request = Request(request_type="POST",
                      uri="/",
                      data={"search_text": "child"})
    response = myapp.handle_request(request)
    assert response.page.title == "Search Results"
    assert "Child1" in response.page.text
예제 #6
0
def test_search_responder_no_results():
    responder = SearchResponder()
    request = Request(request_type="POST",
                      uri="/",
                      data={"search_text": "term"})
    root_page = WikiPage(title="FrontPage", uri="/")
    context = RequestContext(root_page)

    response = responder.make_response(request, context)

    assert response.page.text == "found term in pages:<ul></ul>"
예제 #7
0
def test_search_responder_with_results():
    responder = SearchResponder()
    request = Request(request_type="POST",
                      uri="/",
                      data={"search_text": "spam"})
    root_page = WikiPage(title="SpamPage", uri="/spam", text="spam")
    context = RequestContext(root_page)

    response = responder.make_response(request, context)

    assert response.page.text == "found term in pages:" \
                                 "<ul><li>SpamPage</li></ul>"
def test_request_where_used():
    root_page = WikiPage(title="FrontPage", uri="/")
    child_page = WikiPage(title="Child1",
                          text="a child page referencing FrontPage",
                          tags=["foo"])
    root_page.add_child(child_page)
    myapp = WikiApp(root_page)
    request = Request(request_type="POST",
                      uri="/",
                      data={"where_used": "FrontPage"})
    response = myapp.handle_request(request)
    assert "Where Used" in response.page.title
    assert "Child1" in response.page.text
def test_request_property_search():
    root_page = WikiPage(title="FrontPage", uri="/")
    child_page = WikiPage(title="Child1",
                          text="a child page",
                          tags={"foo", "bar"})
    child2_page = WikiPage(title="Child2",
                           text="a second child page",
                           tags={"foo"})
    root_page.add_child(child_page)
    root_page.add_child(child2_page)
    myapp = WikiApp(root_page)
    request = Request(request_type="POST", uri="/", data={"tags": {"bar"}})
    response = myapp.handle_request(request)
    assert "Property Search" in response.page.title
    assert "Child1" in response.page.text
    assert not "Child2" in response.page.text
def test_request_response_cycle():
    root_page = WikiPage(title="FrontPage", uri="/")
    myapp = WikiApp(root_page)
    request = Request(request_type="GET", uri="/")
    response = myapp.handle_request(request)
    assert response.page.title == "FrontPage"
예제 #11
0
def test_unsupported_http_method():
    root_page = WikiPage(title="FrontPage", uri="/")
    myapp = WikiApp(root_page)
    request = Request(request_type="UPDATE", uri="/")
    with pytest.raises(Exception):
        myapp.handle_request(request)