示例#1
0
def test_static_file():
    r = requests.get(fixture.url("static_file"))
    print r.text
    assert r.ok
    assert r.status_code == 200
    assert r.text == "Infinite Diversity in Infinite Combinations\n"
    assert "text/plain" in r.headers["Content-Type"]
    r = requests.get(
        fixture.url("static_file?mime_type=application/octet-stream"))
    assert r.ok
    assert r.status_code == 200
    assert r.text == "Infinite Diversity in Infinite Combinations\n"
    assert "application/octet-stream" in r.headers["Content-Type"]
示例#2
0
def test_restful_service():
    pos = ["one", "two", "three"]
    query = {"foo": "bar", "that": "telling"}

    url = fixture.url("restful", *pos, **query)
    expected = "%s: one two three {'foo': u'bar', 'that': u'telling'}"

    get = requests.get(url).text
    post = requests.post(url).text
    put = requests.put(url).text
    delete = requests.delete(url)
    propfind = requests.request("PROPFIND", url).text
    dukat = requests.request("DUKAT", url).text
    undefined = requests.request("UNDEFINED", url)

    # GET, POST, and PUT are standard rest verbs.
    assert get == expected % ("GET")
    assert post == expected % ("POST")
    assert put == expected % ("PUT")

    # PROPFIND is a less common rest verb.
    assert propfind == expected % ("PROPFIND")

    # DUKAT is not a standard rest verb, but the service will still respond to
    # it because it is defined properly.
    assert dukat == expected % ("DUKAT")

    # Though DELETE *is* a standard rest verb, the service module does not
    # expose it properly, resulting in a 405 Method Not Allowed error.
    assert delete.status_code == 405

    # UNDEFINED is not a standard rest verb, and it is not defined in the
    # service module - it should also give a 405 error.
    print undefined
    assert undefined.status_code == 405
示例#3
0
def test_redirect_index():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=8)).json()

    assert analysis["directive"] is not None
    assert analysis["directive"]["type"] == Directive.InternalRedirect
    assert analysis["directive"]["argument"] == "/analyze-url/has-index/index.html"
    assert analysis["content"] is None
示例#4
0
def test_list_plugins():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=9)).json()

    assert analysis["directive"] is not None
    assert analysis["directive"]["type"] == Directive.ListPlugins
    assert analysis["directive"]["argument"] is None
    assert analysis["content"] is None
示例#5
0
def test_redirect_directory():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=7)).json()

    assert analysis["directive"] is not None
    assert analysis["directive"]["type"] == Directive.HTTPRedirect
    assert analysis["directive"]["argument"] == "/analyze-url/"
    assert analysis["content"] is None
示例#6
0
def test_directory():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=6)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.Directory
    assert analysis["content"]["path"] == fixture.relative_path("tests/web/analyze-url/")
    assert analysis["content"]["pargs"] is None
示例#7
0
def test_service():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=10)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.Service
    assert analysis["content"]["path"] == fixture.relative_path("tests/web/analyze-url/analyze-url.py")
    assert analysis["content"]["pargs"] == ["1", "2", "3"]
示例#8
0
def test_list_plugins():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=9)).json()

    assert analysis["directive"] is not None
    assert analysis["directive"]["type"] == Directive.ListPlugins
    assert analysis["directive"]["argument"] is None
    assert analysis["content"] is None
示例#9
0
def test_closed_config():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=3)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.File
    assert analysis["content"]["path"] is None
    assert analysis["content"]["pargs"] is None
示例#10
0
def test_open_nonconfig():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=4)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.File
    assert analysis["content"]["path"] == fixture.relative_path("tests/web/analyze-url/standalone.yaml")
    assert analysis["content"]["pargs"] is None
示例#11
0
def test_not_found():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=11)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.NotFound
    assert analysis["content"]["path"] == "/analyze-url/doesnt-exist.html"
    assert analysis["content"]["pargs"] is None
示例#12
0
def test_open_source():
    analysis = requests.get(fixture.url("analyze-url/analyze-url", test=2)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.File
    assert analysis["content"]["path"] == fixture.relative_path("tests/web/analyze-url/open.py")
    assert analysis["content"]["pargs"] is None
示例#13
0
def test_redirect_directory():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=7)).json()

    assert analysis["directive"] is not None
    assert analysis["directive"]["type"] == Directive.HTTPRedirect
    assert analysis["directive"]["argument"] == "/analyze-url/"
    assert analysis["content"] is None
示例#14
0
def test_not_found():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=11)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.NotFound
    assert analysis["content"]["path"] == "/analyze-url/doesnt-exist.html"
    assert analysis["content"]["pargs"] is None
示例#15
0
def test_closed_config():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=3)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.File
    assert analysis["content"]["path"] is None
    assert analysis["content"]["pargs"] is None
示例#16
0
def test_redirect_index():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=8)).json()

    assert analysis["directive"] is not None
    assert analysis["directive"]["type"] == Directive.InternalRedirect
    assert analysis["directive"][
        "argument"] == "/analyze-url/has-index/index.html"
    assert analysis["content"] is None
示例#17
0
def test_open_source():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=2)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.File
    assert analysis["content"]["path"] == fixture.relative_path(
        "tests/web/analyze-url/open.py")
    assert analysis["content"]["pargs"] is None
示例#18
0
def test_open_nonconfig():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=4)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.File
    assert analysis["content"]["path"] == fixture.relative_path(
        "tests/web/analyze-url/standalone.yaml")
    assert analysis["content"]["pargs"] is None
示例#19
0
def test_directory():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=6)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.Directory
    assert analysis["content"]["path"] == fixture.relative_path(
        "tests/web/analyze-url/")
    assert analysis["content"]["pargs"] is None
示例#20
0
def test_service():
    analysis = requests.get(fixture.url("analyze-url/analyze-url",
                                        test=10)).json()

    assert analysis["directive"] is None
    assert analysis["content"] is not None
    assert analysis["content"]["type"] == Content.Service
    assert analysis["content"]["path"] == fixture.relative_path(
        "tests/web/analyze-url/analyze-url.py")
    assert analysis["content"]["pargs"] == ["1", "2", "3"]
示例#21
0
def test_redirect():
    r = requests.get(fixture.url("redirect/redirect"), allow_redirects=False)
    assert r.ok
    assert r.status_code == 303
    assert r.text.startswith("This resource can be found at")

    r = requests.get(fixture.url("redirect/redirect"))
    assert r.ok
    assert r.status_code == 200
    assert r.text == "hello, world\n"

    r = requests.get(fixture.url("redirect/internal_redirect"), allow_redirects=False)
    assert r.ok
    assert r.status_code == 200
    assert r.text == "hello, world\n"

    r = requests.get(fixture.url("redirect/internal_redirect"))
    assert r.ok
    assert r.status_code == 200
    assert r.text == "hello, world\n"
示例#22
0
def test_watch_plugin():
    times = []
    # Check the original time
    response = requests.get(fixture.url("watch_a"))
    assert "Watch A" in response.content
    times.append(get_times(response))

    # Calling this again shouldn't change any import time.
    response = requests.get(fixture.url("watch_a"))
    times.append(get_times(response))
    assert times[-2] == times[-1]

    # Touch script A and check that we now get a new time for A, but not for
    # the sub scripts.
    touch_file("tests/web/watch_a.py")
    response = requests.get(fixture.url("watch_a"))
    times.append(get_times(response))
    assert times[-2]["A"] != times[-1]["A"]
    assert times[-2]["B"] == times[-1]["B"]
    assert times[-2]["C"] == times[-1]["C"]
    assert times[-2]["D"] == times[-1]["D"]

    # Touch script B and check that script A updates with that, too.
    touch_file("tests/web/watch_b.py")
    response = requests.get(fixture.url("watch_a"))
    times.append(get_times(response))
    assert times[-2]["A"] != times[-1]["A"]
    assert times[-2]["B"] != times[-1]["B"]
    assert times[-2]["C"] == times[-1]["C"]
    assert times[-2]["D"] == times[-1]["D"]

    # And again with script D which is several layers in
    touch_file("tests/web/watch_d.py")
    response = requests.get(fixture.url("watch_a"))
    times.append(get_times(response))
    assert times[-2]["A"] != times[-1]["A"]
    assert times[-2]["B"] != times[-1]["B"]
    assert times[-2]["C"] != times[-1]["C"]
    assert times[-2]["D"] != times[-1]["D"]

    # Touching script C and then loading E should show a new C time
    touch_file("tests/web/watch_c.py")
    response = requests.get(fixture.url("watch_e"))
    times.append(get_times(response))
    assert times[-2]["C"] != times[-1]["C"]
    assert times[-2]["D"] == times[-1]["D"]

    # Touch script B.  Calling E should not show any difference in times.
    touch_file("tests/web/watch_b.py")
    response = requests.get(fixture.url("watch_e"))
    times.append(get_times(response))
    assert times[-2] == times[-1]
示例#23
0
def test_config_no_settings():
    response = requests.get(fixture.url('settings'))
    print response
    assert 'pool="None"' in response
示例#24
0
def test_404_not_found():
    response = requests.get(fixture.url("/does-not-exist.html"))
    assert response.status_code == 404
示例#25
0
def test_200_ok():
    response = requests.get(fixture.url("/"))
    assert response.status_code == 200
示例#26
0
def bad_service():
    return requests.get(fixture.url("bad"))
示例#27
0
def test_source_protected():
    result = requests.get(fixture.url("configured.py"))

    assert result.status_code == 403
示例#28
0
def test_prime_service():
    primes = [int(requests.get(fixture.url("primes", n=nn)).content) for nn in range(5)]

    assert primes == [2, 3, 5, 7, 11]
示例#29
0
def test_config_settings_change():
    response = requests.get(fixture.url('settings', pool='500'))
    print response
    assert 'pool="500"' in response
示例#30
0
def test_service_import_local():
    response = requests.get(fixture.url("import", "oct", "30", color="green", answer="42"))
    expected = "\n".join(["[oct, 30]", "color -> green", "answer -> 42"])

    assert response.content == expected
示例#31
0
def test_service_cwd():
    response = requests.get(fixture.url("/cwd"))
    expected = fixture.relative_path("tests/web")

    assert response.content == expected
示例#32
0
def test_service_config():
    result = requests.get(fixture.url("configured")).content

    assert result == "abracadabra"
示例#33
0
def test_server_identity():
    response = requests.get(fixture.url("/"))
    assert response.headers["server"] == ""