Exemplo n.º 1
0
    def test_post(self):
        response = self.app._handle_request(Request.POST, Url(path='/items'), body='"banana"')
        assert http.HTTPStatus.CREATED == response.status_code
        assert '"banana"' == response.body

        response = self.app._handle_request(Request.GET, Url(path='/items'))
        assert http.HTTPStatus.OK == response.status_code
        assert '["pizza","cheese","ice-cream","butter","banana"]' == response.body
Exemplo n.º 2
0
def test_for_request_matcher():
    r = Request(Request.GET, Url(path='/items/5'))

    with is_set() as flag:
        for _ in r / 'items':
            flag.set()

    with is_set(False) as flag:
        for _ in r / 'books':
            flag.set()

    with is_set() as flag:
        for item_id in r / 'items' / Integer():
            assert 5 == item_id
            flag.set()

    with is_set() as flag:
        for item_id in r / 'items' / Integer():
            assert 5 == item_id
            flag.set()

    with is_set(False) as flag:
        for item_id in r / 'items' / None:
            assert 5 == item_id
            flag.set()

    with is_set() as flag:
        for book_id in r / 'items' / Integer / None:
            assert 5 == book_id
            flag.set()
Exemplo n.º 3
0
def test_with_multiple_request_matcher():
    r = Request(Request.GET, Url(path='/books/1/pages/2'))

    with is_set() as flag:
        with r / 'books':
            flag.set()

    with is_set() as flag:
        with r / 'books' / Integer as book_id:
            assert 1 == book_id
            flag.set()

    with is_set() as flag:
        with r / 'books' / Integer / 'pages' as book_id:
            assert 1 == book_id
            flag.set()

    with is_set() as flag:
        with r / 'books' / Integer / 'pages' / Integer as [book_id, page]:
            assert 1 == book_id
            assert 2 == page
            flag.set()

    with is_set() as flag:
        with r / 'books' / Integer / 'pages' / Integer / None as [
                book_id, page
        ]:
            assert 1 == book_id
            assert 2 == page
            flag.set()
Exemplo n.º 4
0
def test_with_request_matcher():
    r = Request(Request.GET, Url(path='/items/5'))

    with is_set() as flag:
        with r / 'items':
            flag.set()

    with is_set(False) as flag:
        with r / 'books':
            flag.set()

    with is_set() as flag:
        with r / 'items' / Integer() as item_id:
            assert 5 == item_id
            flag.set()

    with is_set() as flag:
        with r / 'items' / Integer as item_id:
            assert 5 == item_id
            flag.set()

    with is_set(False) as flag:
        with r / 'items' / None as item_id:
            assert 5 == item_id
            flag.set()

    with is_set() as flag:
        with r / 'items' / Integer / None as item_id:
            assert 5 == item_id
            flag.set()
Exemplo n.º 5
0
def test_for_multiple_request_matcher():
    r = Request(Request.GET, Url(path='/books/1/pages/2'))

    with is_set() as flag:
        for _ in r / 'books':
            flag.set()

    with is_set() as flag:
        for book_id in r / 'books' / Integer:
            assert 1 == book_id
            flag.set()

    with is_set() as flag:
        for book_id in r / 'books' / Integer / 'pages':
            assert 1 == book_id
            flag.set()

    with is_set() as flag:
        for book_id, page in r / 'books' / Integer / 'pages' / Integer:
            assert 1 == book_id
            assert 2 == page
            flag.set()

    with is_set() as flag:
        for book_id, page in r / 'books' / Integer / 'pages' / Integer / None:
            assert 1 == book_id
            assert 2 == page
            flag.set()
Exemplo n.º 6
0
def test_raw_request_matcher():
    request = Request(Request.GET, Url(path='/items/5'))
    assert (request / 'items').is_match is True
    assert (request / 'books').is_match is False
    assert (request / 'items' / Integer()).is_match is True
    assert (request / 'items' / Integer).is_match is True
    assert (request / 'items' / None).is_match is False
    assert (request / 'items' / Integer / None).is_match is True
Exemplo n.º 7
0
def test_raw_multiple_request_matcher():
    request = Request(Request.GET, Url(path='/books/1/pages/2'))
    assert (request / 'books').is_match is True
    assert (request / 'books' / Integer).is_match is True
    assert (request / 'books' / Integer / 'pages').is_match is True
    assert (request / 'books' / Integer / 'pages' / Integer).is_match is True
Exemplo n.º 8
0
def test_entity_without_path(test_input, obj_type, expected):
    r = Request(Request.POST,
                Url(path='/path'),
                content=test_input,
                unmarshaller=JSONUnmarshaller().unmarshall)
    assert expected == r.entity(obj_type)
Exemplo n.º 9
0
 def test_get_one(self):
     response = self.app._handle_request(Request.GET, Url(path='/items/1'))
     assert http.HTTPStatus.OK == response.status_code
     assert '"cheese"' == response.body
Exemplo n.º 10
0
 def test_get_all(self):
     response = self.app._handle_request(Request.GET, Url(path='/items'))
     assert http.HTTPStatus.OK == response.status_code
     assert '["pizza","cheese","ice-cream","butter"]' == response.body
Exemplo n.º 11
0
def test_simple_with():
    app = App(MyRouter())
    response = app._handle_request(Request.GET, Url(path='/items'))
    assert http.HTTPStatus.OK == response.status_code