Ejemplo n.º 1
0
def run_tests_4_actual_httpd():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8081"]\ndef index(r):\n print 1')

    app = App(fn)
    assert urllib.urlopen('http://127.0.0.1:8081/').read().strip() == '1'
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8081/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError:
        pass

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8083"]\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8083/').read().strip() == '1'

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8082"]\ndef index(r):\n print 2')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8082/').read().strip() == '2'

    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8082/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError:
        pass
Ejemplo n.º 2
0
def run_tests_7_syntax_errors():
    fn = 'tests/generated.py'

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    helpers.set_file(fn,
                     'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1..')
    txt = urllib.urlopen('http://127.0.0.1:8090/').read()
    assert 'SyntaxError' in txt

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    assert urllib.urlopen('http://127.0.0.1:8090/').read().strip() == '1'

    app.stop()

    helpers.set_file(fn,
                     'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1..')
    app = App(fn)
    app.set_reload_intervals(-1)
    try:
        txt = urllib.urlopen('http://127.0.0.1:8091/').read()
        raise Exception('Server started when it shouldn\'t have been.')
    except IOError:
        pass

    helpers.set_file(fn, 'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8091/').read().strip() == '1'

    app.stop()
Ejemplo n.º 3
0
def run_tests_4_actual_httpd():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8081"]\ndef index(r):\n print 1')

    app = App(fn)
    assert urllib.urlopen('http://127.0.0.1:8081/').read().strip() == '1'
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8081/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError: 
        pass

   
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8083"]\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8083/').read().strip() == '1'
    
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8082"]\ndef index(r):\n print 2')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8082/').read().strip() == '2'
    
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8082/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError: 
        pass
Ejemplo n.º 4
0
def run_tests_7_syntax_errors():
    fn = 'tests/generated.py'

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    app = App(fn)
    app.set_reload_intervals(-1)
    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1..')
    txt = urllib.urlopen('http://127.0.0.1:8090/').read()
    assert 'SyntaxError' in txt

    helpers.set_file(fn, 'hosts = "127.0.0.1:8090",\ndef index(r):\n print 1')
    assert urllib.urlopen('http://127.0.0.1:8090/').read().strip() == '1'

    app.stop()

    helpers.set_file(fn, 'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1..')
    app = App(fn)
    app.set_reload_intervals(-1)
    try:
        txt = urllib.urlopen('http://127.0.0.1:8091/').read()
        raise Exception('Server started when it shouldn\'t have been.')
    except IOError:
        pass

    helpers.set_file(fn, 'hosts = "127.0.0.1:8091",\ndef index(r):\n print 1')
    app.force_hosts_check()
    assert urllib.urlopen('http://127.0.0.1:8091/').read().strip() == '1'

    app.stop()
Ejemplo n.º 5
0
def run_tests_5_actual_httpd_multiprocess():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 1')
    app = App(fn)
    app.add_proc()
    app.add_proc()
    app.add_proc()
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '1'

    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 2')
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '2'

    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8085/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError:
        pass
Ejemplo n.º 6
0
def run_tests_5_actual_httpd_multiprocess():
    fn = 'tests/generated.py'
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 1')
    app = App(fn)
    app.add_proc()
    app.add_proc()
    app.add_proc()
    app.set_reload_intervals(-1)
    app.force_hosts_check()
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '1'
    
    helpers.set_file(fn, 'hosts = ["127.0.0.1:8085"]\ndef index(r):\n print 2')
    for _ in range(10):
        assert urllib.urlopen('http://127.0.0.1:8085/').read().strip() == '2'
    
    app.stop()
    try:
        urllib.urlopen('http://127.0.0.1:8085/').read().strip()
        raise Exception('Server did not stop properly')
    except IOError: 
        pass