Ejemplo n.º 1
0
def test_make_response_ordered():
    formatter = CSVFormatter(PersonCSVSchema())

    response = formatter(
        dict(items=[dict(
            firstName="First",
            lastName="Last",
            id="me",
        )]))

    assert_that(response.data,
                is_(equal_to(b"id,firstName,lastName\r\nme,First,Last\r\n")))
    assert_that(response.content_type,
                is_(equal_to("text/csv; charset=utf-8")))
    assert_that(
        response.headers,
        contains_inanyorder(
            ("Content-Disposition", "attachment; filename=\"response.csv\""),
            ("Content-Type", "text/csv; charset=utf-8"),
            ("ETag",
             etag_for(
                 md5_hash='"4480bd6748cf93740490ebeee7eae1fe"',
                 spooky_hash='"0a7f40b47efb0a197b180444c4911b17"',
             )),
        ))
Ejemplo n.º 2
0
def test_make_response():
    formatter = HTMLFormatter()

    response = formatter("<blink>Hello World!</blink>")
    assert_that(response.data, is_(equal_to(b"<blink>Hello World!</blink>")))
    assert_that(response.content_type, is_(equal_to("text/html; charset=utf-8")))
    assert_that(response.headers, contains_inanyorder(
        ("Content-Length", "27"),
        ("Content-Type", "text/html; charset=utf-8"),
        ("ETag", etag_for(
            md5_hash='"016a5a134aceb7391754f03893d30e06"',
            spooky_hash='"1a639cef905e11904ac33817c37997dd"',
        )),
    ))
def test_make_response():
    formatter = TextFormatter()

    response = formatter("Hello World!")
    assert_that(response.data, is_(equal_to(b"Hello World!")))
    assert_that(response.content_type, is_(equal_to("text/plain; charset=utf-8")))
    assert_that(response.headers, contains_inanyorder(
        ("Content-Length", "12"),
        ("Content-Type", "text/plain; charset=utf-8"),
        ("ETag", etag_for(
            md5_hash='"ed076287532e86365e841e92bfc50d8c"',
            spooky_hash='"79aa5e0a1f595e330d662c97a7763cdc"',
        )),
    ))
Ejemplo n.º 4
0
def test_make_response():
    formatter = TextFormatter()

    response = formatter("Hello World!")
    assert_that(response.data, is_(equal_to(b"Hello World!")))
    assert_that(response.content_type,
                is_(equal_to("text/plain; charset=utf-8")))
    assert_that(
        response.headers,
        contains_inanyorder(
            ("Content-Length", "12"),
            ("Content-Type", "text/plain; charset=utf-8"),
            ("ETag",
             etag_for(
                 md5_hash='"ed076287532e86365e841e92bfc50d8c"',
                 spooky_hash='"79aa5e0a1f595e330d662c97a7763cdc"',
             )),
        ))
Ejemplo n.º 5
0
def test_make_response_list():
    formatter = CSVFormatter()

    response = formatter(dict(items=[
        ["a", "b", "c"],
        ["d", "e", "f"],
    ]))

    assert_that(response.data, is_(equal_to(b"a,b,c\r\nd,e,f\r\n")))
    assert_that(response.content_type, is_(equal_to("text/csv; charset=utf-8")))
    assert_that(response.headers, contains_inanyorder(
        ("Content-Disposition", "attachment; filename=\"response.csv\""),
        ("Content-Type", "text/csv; charset=utf-8"),
        ("ETag", etag_for(
            md5_hash='"eb8bde290633452402b37aa580ca30e9"',
            spooky_hash='"63b989eb36315937ef68206fb9fc3104"',
        )),
    ))
Ejemplo n.º 6
0
def test_make_response():
    formatter = CSVFormatter()

    response = formatter(dict(items=[
        dict(foo="bar"),
        dict(foo="baz"),
    ]))

    assert_that(response.data, is_(equal_to(b"foo\r\nbar\r\nbaz\r\n")))
    assert_that(response.content_type, is_(equal_to("text/csv; charset=utf-8")))
    assert_that(response.headers, contains_inanyorder(
        ("Content-Disposition", "attachment; filename=\"response.csv\""),
        ("Content-Type", "text/csv; charset=utf-8"),
        ("ETag", etag_for(
            md5_hash='"a2ead3516dd1be4a3c7f45716c0a0eb7"',
            spooky_hash='"02dee263db4f9326a3fbee9135939717"',
        )),
    ))
def test_make_response_list():
    formatter = CSVFormatter()

    response = formatter(dict(items=[
        ["a", "b", "c"],
        ["d", "e", "f"],
    ]))

    assert_that(response.data, is_(equal_to(b"a,b,c\r\nd,e,f\r\n")))
    assert_that(response.content_type, is_(equal_to("text/csv; charset=utf-8")))
    assert_that(response.headers, contains_inanyorder(
        ("Content-Disposition", "attachment; filename=\"response.csv\""),
        ("Content-Type", "text/csv; charset=utf-8"),
        ("ETag", etag_for(
            md5_hash='"eb8bde290633452402b37aa580ca30e9"',
            spooky_hash='"63b989eb36315937ef68206fb9fc3104"',
        )),
    ))
def test_make_response():
    formatter = CSVFormatter()

    response = formatter(dict(items=[
        dict(foo="bar"),
        dict(foo="baz"),
    ]))

    assert_that(response.data, is_(equal_to(b"foo\r\nbar\r\nbaz\r\n")))
    assert_that(response.content_type, is_(equal_to("text/csv; charset=utf-8")))
    assert_that(response.headers, contains_inanyorder(
        ("Content-Disposition", "attachment; filename=\"response.csv\""),
        ("Content-Type", "text/csv; charset=utf-8"),
        ("ETag", etag_for(
            md5_hash='"a2ead3516dd1be4a3c7f45716c0a0eb7"',
            spooky_hash='"02dee263db4f9326a3fbee9135939717"',
        )),
    ))
Ejemplo n.º 9
0
def test_make_response():
    graph = create_object_graph(name="example", testing=True)
    formatter = JSONFormatter()

    with graph.app.test_request_context():
        response = formatter(dict(foo="bar"))

    assert_that(response.data, is_(equal_to(b'{"foo":"bar"}\n')))
    assert_that(response.content_type, is_(equal_to("application/json")))
    assert_that(
        response.headers,
        contains_inanyorder(
            ("Content-Type", "application/json"),
            ("Content-Length", "14"),
            ("ETag",
             etag_for(
                 md5_hash='"2f8acf3fe5e5c2839a04b7677d9399b8"',
                 spooky_hash='"af072b51e1eb2a8d7b2ab84dab972674"',
             )),
        ))
def test_make_response_ordered():
    formatter = CSVFormatter(PersonCSVSchema())

    response = formatter(dict(items=[
        dict(
            firstName="First",
            lastName="Last",
            id="me",
        )
    ]))

    assert_that(response.data, is_(equal_to(b"id,firstName,lastName\r\nme,First,Last\r\n")))
    assert_that(response.content_type, is_(equal_to("text/csv; charset=utf-8")))
    assert_that(response.headers, contains_inanyorder(
        ("Content-Disposition", "attachment; filename=\"response.csv\""),
        ("Content-Type", "text/csv; charset=utf-8"),
        ("ETag", etag_for(
            md5_hash='"4480bd6748cf93740490ebeee7eae1fe"',
            spooky_hash='"0a7f40b47efb0a197b180444c4911b17"',
        )),
    ))
Ejemplo n.º 11
0
def test_make_response_tuples():
    formatter = CSVFormatter()

    response = formatter(dict(items=[
        ("a", "b", "c"),
        ("d", "e", "f"),
    ]))

    assert_that(response.data, is_(equal_to(b"a,b,c\r\nd,e,f\r\n")))
    assert_that(response.content_type,
                is_(equal_to("text/csv; charset=utf-8")))
    assert_that(
        response.headers,
        contains_inanyorder(
            ("Content-Disposition", "attachment; filename=\"response.csv\""),
            ("Content-Type", "text/csv; charset=utf-8"),
            ("ETag",
             etag_for(
                 md5_hash='"eb8bde290633452402b37aa580ca30e9"',
                 spooky_hash='"02dee263db4f9326a3fbee9135939717"',
             )),
        ))