def test_charset_static_barely_working(): response = check( "Greetings, program!", 'index.html', False , argv=['--charset_static=OOG'] ) expected = 'text/html; charset=OOG' actual = response.headers['Content-Type'] assert actual == expected
def test_json_content_type_is_configurable_for_static_json(): configure_aspen_py = 'website.media_type_json = "floober/blah"' expected = "floober/blah" actual = check( '{"Greetings": "program!"}', filename="foo.json", body=False, configure_aspen_py=configure_aspen_py ).headers["Content-Type"] assert actual == expected
def test_json_defaults_to_application_json_for_static_json(): expected = 'application/json' actual = check( '{"Greetings": "program!"}' , filename="foo.json" , body=False ).headers['Content-Type'] assert actual == expected, actual
def test_json_handles_unicode(): expected = b'''{ "Greetings": "\u00b5" }''' actual = check("[---]\nresponse.body = {'Greetings': unichr(181)}", filename="foo.json.spt") assert actual == expected
def test_json_content_type_is_per_file_configurable(): expected = 'floober/blah' actual = check( "[---]\nresponse.body = {'Greetings': 'program!'}\nresponse.headers['Content-Type'] = 'floober/blah'\n", filename="foo.json.spt", body=False).headers['Content-Type'] assert actual == expected
def test_json_defaults_to_application_json_for_dynamic_json(): expected = 'application/json' actual = check( "response.body = {'Greetings': 'program!'}" , filename="foo.json" , body=False ).headers['Content-Type'] assert actual == expected, actual
def test_charset_dynamic_barely_working(): response = check( "^LGreetings, program!", 'index.html', False , argv=['--charset_dynamic=CHEESECODE'] ) expected = 'text/html; charset=CHEESECODE' actual = response.headers['Content-Type'] assert actual == expected, actual
def test_json_basically_works(): expected = '''{ "Greetings": "program!" }''' actual = check("[---]\nresponse.body = {'Greetings': 'program!'}", filename="foo.json.spt") assert actual == expected
def test_json_handles_time(): expected = '''{ "seen": "19:30:00" }''' actual = check("import datetime\n" + "[---------------]\n" + "response.body = {'seen': datetime.time(19, 30)}", filename="foo.json.spt") assert actual == expected
def test_json_content_type_is_configurable_from_the_command_line(): expected = 'floober/blah' actual = check( '{"Greetings": "program!"}' , filename="foo.json" , body=False , argv=['--media_type_json=floober/blah'] ).headers['Content-Type'] assert actual == expected, actual
def test_json_handles_date(): expected = '''{ "created": "2011-05-09" }''' actual = check("import datetime\n" + "[---------------]\n" + "response.body = {'created': datetime.date(2011, 5, 9)}", filename="foo.json.spt") assert actual == expected
def test_json_handles_date(): expected = '{"created": "2011-05-09"}' actual = check( "import datetime" + "" + "response.body = {'created': datetime.date(2011, 5, 9)}" , filename="foo.json" ) assert actual == expected, actual
def test_json_handles_unicode(): expected = b'''{ "Greetings": "\u00b5" }''' actual = check( "[---]\nresponse.body = {'Greetings': unichr(181)}" , filename="foo.json.spt" ) assert actual == expected, actual
def test_json_basically_works(): expected = '''{ "Greetings": "program!" }''' actual = check( "[---]\nresponse.body = {'Greetings': 'program!'}" , filename="foo.json.spt" ) assert actual == expected, actual
def test_unknown_mimetype_yields_default_mimetype(): response = check( "Greetings, program!" , body=False , filename="foo.flugbaggity" ) expected = "text/plain" actual = response.headers['Content-Type'] assert actual == expected, actual
def test_website_is_in_context(): expected = "It worked." actual = check("""\ assert website.__class__.__name__ == 'Website', website It worked.""") assert actual == expected, actual
def test_json_content_type_is_per_file_configurable(): expected = "floober/blah" actual = check( "[---]\nresponse.body = {'Greetings': 'program!'}\nresponse.headers['Content-Type'] = 'floober/blah'\n", filename="foo.json.spt", body=False, ).headers["Content-Type"] assert actual == expected
def test_json_handles_time(): expected = '{"seen": "19:30:00"}' actual = check( "import datetime" + "" + "response.body = {'seen': datetime.time(19, 30)}" , filename="foo.json" ) assert actual == expected, actual
def test_resources_dont_leak_whitespace(): """This aims to resolve https://github.com/whit537/aspen/issues/8. """ actual = check(dedent(""" foo = [1,2,3,4] {{repr(foo)}}""")) expected = "[1, 2, 3, 4]" assert actual == expected, repr(actual)
def test_json_handles_datetime(): expected = '''{ "timestamp": "2011-05-09T00:00:00" }''' actual = check("import datetime\n" + "[---------------]\n" + "response.body = { 'timestamp'" + " : datetime.datetime(2011, 5, 9, 0, 0)}", filename="foo.json.spt") assert actual == expected
def test_json_content_type_is_configurable_for_dynamic_json(): configure_aspen_py = 'website.media_type_json = "floober/blah"' expected = 'floober/blah' actual = check( "[---]\nresponse.body = {'Greetings': 'program!'}", filename="foo.json.spt", body=False, configure_aspen_py=configure_aspen_py).headers['Content-Type'] assert actual == expected
def test_json_handles_time(): expected = """{ "seen": "19:30:00" }""" actual = check( "import datetime\n" + "[---------------]\n" + "response.body = {'seen': datetime.time(19, 30)}", filename="foo.json.spt", ) assert actual == expected
def test_templating_without_script_works(): response = Response() expected = "index.html" # I want a slash on the front of index.html but it's an artifact of # StubRequest that we don't get one. actual = check("[-----] via stdlib_format\n{request.line.uri.path.raw}", response=response) assert actual == expected, actual
def test_json_content_type_is_configurable_for_dynamic_json(): configure_aspen_py = 'website.media_type_json = "floober/blah"' expected = 'floober/blah' actual = check( "response.body = {'Greetings': 'program!'}" , filename="foo.json" , body=False , configure_aspen_py=configure_aspen_py ).headers['Content-Type'] assert actual == expected, actual
def test_templating_without_script_works(): response = Response() expected = "index.html" # I want a slash on the front of index.html but it's an artifact of # StubRequest that we don't get one. actual = check("[-----] via stdlib_format\n{request.line.uri.path.raw}", response=response) assert actual == expected
def test_json_content_type_is_configurable_for_dynamic_json(): aspenconf = '[aspen]\njson_content_type: floober/blah' expected = 'floober/blah' actual = check( "response.body = {'Greetings': 'program!'}" , filename="foo.json" , body=False , aspenconf=aspenconf ).headers.one('Content-Type') assert actual == expected, actual
def test_json_handles_date(): expected = """{ "created": "2011-05-09" }""" actual = check( "import datetime\n" + "[---------------]\n" + "response.body = {'created': datetime.date(2011, 5, 9)}", filename="foo.json.spt", ) assert actual == expected
def test_json_content_type_is_configurable_for_static_json(): aspenconf = '[aspen]\njson_content_type: floober/blah' expected = 'floober/blah' actual = check( '{"Greetings": "program!"}' , filename="foo.json" , body=False , aspenconf=aspenconf ).headers.one('Content-Type') assert actual == expected, actual
def test_json_content_type_is_configurable_for_static_json(): configure_aspen_py = 'website.media_type_json = "floober/blah"' expected = 'floober/blah' actual = check( '{"Greetings": "program!"}' , filename="foo.json" , body=False , configure_aspen_py=configure_aspen_py ).headers['Content-Type'] assert actual == expected, actual
def test_json_handles_datetime(): expected = '{"timestamp": "2011-05-09T00:00:00"}' actual = check( "import datetime" + "" + "response.body = { 'timestamp'" + " : datetime.datetime(2011, 5, 9, 0, 0)}" , filename="foo.json" ) assert actual == expected, actual
def test_website_is_in_namespace(): expected = "It worked." actual = check( """\ assert website.__class__.__name__ == 'Configurable', website It worked.""" ) assert actual == expected, actual
def test_utf8(): expected = unichr(1758).encode('utf8') actual = check(""" "empty first page" ^L text = unichr(1758) ^L {{ text }} """).strip() assert actual == expected, actual
def test_resource_templating_set(): expected = "1, 2, 3, 4" actual = check(dedent(""" foo = [1,2,3,4] nfoo = len(foo) {% set i = 0 %} {% for x in foo %}{% set i += 1 %}{{ x }}{% if i < nfoo %}, {% end %}{% end %} """)).strip() assert actual == expected, actual
def test_utf8(): expected = unichr(1758).encode('utf8') expected = unichr(1758) actual = check(""" "#empty first page" [------------------] text = unichr(1758) [------------------] %(text)s """).strip() assert actual == expected, repr(actual) + " != expected " + repr(expected)
def test_utf8(): expected = unichr(1758).encode('utf8') expected = unichr(1758) actual = check(""" "#empty first page" [------------------] text = unichr(1758) [------------------] %(text)s """).strip() assert actual == expected
def test_json_handles_datetime(): expected = """{ "timestamp": "2011-05-09T00:00:00" }""" actual = check( "import datetime\n" + "[---------------]\n" + "response.body = { 'timestamp'" + " : datetime.datetime(2011, 5, 9, 0, 0)}", filename="foo.json.spt", ) assert actual == expected
def test_negotiated_resource_doesnt_break(): expected = "Greetings, bar!\n" actual = check(""" [-----------] foo = 'bar' [-----------] text/plain Greetings, %(foo)s! [-----------] text/html <h1>Greetings, %(foo)s!</h1> """ , filename='index.spt') assert actual == expected
def test_negotiated_resource_doesnt_break(): expected = "Greetings, bar!\n" actual = check(""" ^L foo = 'bar' ^L text/plain Greetings, {{ foo }}! ^L text/html <h1>Greetings, {{ foo }}!</h1> """ , filename='index') assert actual == expected, actual
def test_json_handles_complex(): expected = """{ "complex": [ 1.0, 2.0 ] }""" actual = check("[---]\nresponse.body = {'complex': complex(1,2)}", filename="foo.json.spt") # The json module puts trailing spaces after commas, but simplejson # does not. Normalize the actual input to work around that. actual = "\n".join([line.rstrip() for line in actual.split("\n")]) assert actual == expected
def test_negotiated_resource_doesnt_break(): expected = "Greetings, bar!\n" actual = check(""" [-----------] foo = 'bar' [-----------] text/plain Greetings, %(foo)s! [-----------] text/html <h1>Greetings, %(foo)s!</h1> """ , filename='index.spt') assert actual == expected, actual
def test_json_handles_complex(): expected = '''{ "complex": [ 1.0, 2.0 ] }''' actual = check("[---]\nresponse.body = {'complex': complex(1,2)}", filename="foo.json.spt") # The json module puts trailing spaces after commas, but simplejson # does not. Normalize the actual input to work around that. actual = '\n'.join([line.rstrip() for line in actual.split('\n')]) assert actual == expected
def test_content_type_is_right_in_template_doc_unicode_example(): response = check(eg, body=False) expected = "text/plain; charset=latin1" actual = response.headers['Content-Type'] assert actual == expected, actual
def test_body_is_right_in_template_doc_unicode_example(): expected = chr(181) actual = check(eg).strip() assert actual == expected, actual
def test_barely_working(): response = check("Greetings, program!", 'index.html', False) expected = 'text/html' actual = response.headers['Content-Type'] assert actual == expected, actual
def test_resource_pages_work_with_caret_L(): expected = "Greetings, bar!" actual = check("foo = 'bar'^LGreetings, {{ foo }}!") assert actual == expected, actual
def test_templating_skipped_without_script(): response = Response() expected = "{{ foo }}" actual = check("{{ foo }}", response=response) assert actual == expected, actual
def test_resource_pages_work(): expected = "Greetings, bar!" actual = check("foo = 'bar'\n[--------]\nGreetings, %(foo)s!") assert actual == expected
def test_exception_location_preserved_for_response_raised_in_page_2(): # https://github.com/gittip/aspen-python/issues/153 expected = ('index.html.spt', 1) try: check("from aspen import Response; raise Response(404)\n[---]\n") except Response, response: actual = response.whence_raised() assert actual == expected
def test_json_defaults_to_application_json_for_dynamic_json(): expected = 'application/json' actual = check("[---]\nresponse.body = {'Greetings': 'program!'}", filename="foo.json.spt", body=False).headers['Content-Type'] assert actual == expected