Exemplo n.º 1
0
def test_sane_inheritance():
    class MyBeanBag(BeanBag):
        def helper(self, param):
            pass

        def encode(self, body):
            return super(~MyBeanBag, self).encode(body)

        def decode(self, response):
            return super(~MyBeanBag, self).decode(response)

    s = FakeSession()
    bb = MyBeanBag("http://www.example.org/path", session=s)

    assert type(bb) is MyBeanBag
    assert type(bb.subpath) is MyBeanBag
    assert type(bb[1]) is MyBeanBag

    assert hasattr(~MyBeanBag, "helper")

    s.expect("GET", "http://www.example.org/path/")
    GET(bb)

    s.expect("POST", "http://www.example.org/path/foo", data={"a": 1})
    r = POST(bb.foo, dict(a=1))
    assert type(r) is AttrDict
    assert r.data == '{"a": 1}' and r.method == 'POST'
Exemplo n.º 2
0
def test_sane_inheritance():
    class MyBeanBag(BeanBag):
        def helper(self, param):
            pass

        def encode(self, body):
            return super(~MyBeanBag, self).encode(body)

        def decode(self, response):
            return super(~MyBeanBag, self).decode(response)

    s = FakeSession()
    bb = MyBeanBag("http://www.example.org/path", session=s)

    assert type(bb) is MyBeanBag
    assert type(bb.subpath) is MyBeanBag
    assert type(bb[1]) is MyBeanBag

    assert hasattr(~MyBeanBag, "helper")

    s.expect("GET", "http://www.example.org/path/")
    GET(bb)

    s.expect("POST", "http://www.example.org/path/foo", data={"a": 1})
    r = POST(bb.foo, dict(a=1))
    assert type(r) is AttrDict
    assert r.data == '{"a": 1}' and r.method == 'POST'
Exemplo n.º 3
0
def test_bb():
    s = FakeSession()
    b = beanbag.BeanBag("http://www.example.org/path/", session=s)

    assert str(b) == "http://www.example.org/path/"

    s.expect("GET", "http://www.example.org/path/")
    q = b()

    s.expect("GET", "http://www.example.org/path/", params=dict(a=1, b=2))
    q = b(a=1, b=2)

    s.expect("PUT", "http://www.example.org/path/")
    b._ = None

    s.expect("PATCH", "http://www.example.org/path/")
    b._ += None

    s.expect("DELETE", "http://www.example.org/path/")
    del b._

    s.expect("POST", "http://www.example.org/path/foo", data={"a": 1})
    q = b.foo(dict(a=1))

    s.expect("GET",
             "http://www.example.org/path/foo",
             params={"result": "/*INVALID*/"})
    try:
        q = b.foo(result="/*INVALID*/")
        assert False, "should have raised exception"
    except beanbag.BeanBagException as e:
        assert e.msg == "Could not decode response"
Exemplo n.º 4
0
def test_bb():
    s = FakeSession()
    b = BeanBag("http://www.example.org/path/", session=s)

    assert str(b) == "http://www.example.org/path/"

    s.expect("GET", "http://www.example.org/path/")
    GET(b)

    s.expect("GET", "http://www.example.org/path/", params=dict(a=1, b=2))
    GET(b(a=1, b=2))

    s.expect("PUT", "http://www.example.org/path/")
    PUT(b._, None)

    s.expect("PATCH", "http://www.example.org/path/")
    PATCH(b._, None)

    s.expect("DELETE", "http://www.example.org/path/")
    DELETE(b._)

    s.expect("POST", "http://www.example.org/path/foo", data={"a": 1})
    POST(b.foo, dict(a=1))

    s.expect("GET", "http://www.example.org/path/", params=dict(status=300))
    with pytest.raises(BeanBagException) as e:
        GET(b(status=300))
    assert "Bad response code: 300" == e.value.msg

    s.expect("GET", "http://www.example.org/path/", params=dict(result="BAD"))
    with pytest.raises(BeanBagException) as e:
        GET(b(result="BAD"))
    assert "Could not decode response" == e.value.msg
Exemplo n.º 5
0
def test_bb():
    s = FakeSession()
    b = BeanBag("http://www.example.org/path/", session=s)

    assert str(b) == "http://www.example.org/path/"

    s.expect("GET", "http://www.example.org/path/")
    GET(b)

    s.expect("GET", "http://www.example.org/path/", params=dict(a=1, b=2))
    GET(b(a=1, b=2))

    s.expect("PUT", "http://www.example.org/path/")
    PUT(b._, None)

    s.expect("PATCH", "http://www.example.org/path/")
    PATCH(b._, None)

    s.expect("DELETE", "http://www.example.org/path/")
    DELETE(b._)

    s.expect("POST", "http://www.example.org/path/foo", data={"a": 1})
    POST(b.foo, dict(a=1))

    s.expect("GET", "http://www.example.org/path/", params=dict(status=300))
    with pytest.raises(BeanBagException) as e:
        GET(b(status=300))
    assert "Bad response code: 300" == e.value.msg

    s.expect("GET", "http://www.example.org/path/", params=dict(result="BAD"))
    with pytest.raises(BeanBagException) as e:
        GET(b(result="BAD"))
    assert "Could not decode response" == e.value.msg
Exemplo n.º 6
0
def test_bb():
    s = FakeSession()
    b = beanbag.BeanBag("http://www.example.org/path/", session=s)

    assert str(b) == "http://www.example.org/path/"

    s.expect("GET", "http://www.example.org/path/")
    q = b()

    s.expect("GET", "http://www.example.org/path/", params=dict(a=1, b=2))
    q = b(a=1, b=2)

    s.expect("PUT", "http://www.example.org/path/")
    b._ = None

    s.expect("PATCH", "http://www.example.org/path/")
    b._ += None

    s.expect("DELETE", "http://www.example.org/path/")
    del b._

    s.expect("POST", "http://www.example.org/path/foo", data={"a": 1})
    q = b.foo(dict(a=1))

    s.expect("GET", "http://www.example.org/path/foo", params={"result": "/*INVALID*/"})
    try:
        q = b.foo(result="/*INVALID*/")
        assert False, "should have raised exception"
    except beanbag.BeanBagException as e:
        assert e.msg == "Could not decode response"