Esempio n. 1
0
def test_operation_href_for():
    """
    Operations can resolve themselves as fully expanded hrefs.

    """
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(subject="foo")

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Search)
        assert_that(url, is_(equal_to("http://localhost/api/foo")))
def test_operation_href_for():
    """
    Operations can resolve themselves as fully expanded hrefs.

    """
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(subject="foo")

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Search)
        assert_that(url, is_(equal_to("http://localhost/api/foo")))
Esempio n. 3
0
def test_operation_href_for_qs():
    """
    Operations can resolve themselves as fully expanded hrefs with
    custom query string parameter.

    """
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(subject="foo")

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Search, offset=0, limit=10, qs=dict(foo="bar"))
        assert_that(url, matches_uri("http://localhost/api/foo?offset=0&limit=10&foo=bar"))
def test_operation_href_for_qs():
    """
    Operations can resolve themselves as fully expanded hrefs with
    custom query string parameter.

    """
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(subject="foo")

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Search, offset=0, limit=10, qs=dict(foo="bar"))
        assert_that(url, matches_uri("http://localhost/api/foo?offset=0&limit=10&foo=bar"))
Esempio n. 5
0
def test_qualified_operation_href_for():
    """
    Qualified operations add to the URI.

    """
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(subject="foo", qualifier="bar", version="v1")

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    @graph.route(ns.instance_path, Operation.Retrieve, ns)
    def get_foo(foo_id):
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Retrieve, foo_id="baz")
        assert_that(url, is_(equal_to("http://localhost/api/v1/bar/foo/baz")))
Esempio n. 6
0
def test_namespace_accepts_controller():
    """
    Namespaces may optionally contain a controller.

    """
    graph = create_object_graph(name="example", testing=True)
    controller = Mock()
    ns = Namespace(subject="foo", controller=controller)

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Search)
        assert_that(url, is_(equal_to("http://localhost/api/foo")))
        url = ns.url_for(Operation.Search)
        assert_that(url, is_(equal_to("http://localhost/api/foo")))
        assert_that(ns.controller, is_(equal_to(controller)))
def test_qualified_operation_href_for():
    """
    Qualified operations add to the URI.

    """
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(subject="foo", qualifier="bar", version="v1")

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    @graph.route(ns.instance_path, Operation.Retrieve, ns)
    def get_foo(foo_id):
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Retrieve, foo_id="baz")
        assert_that(url, is_(equal_to("http://localhost/api/v1/bar/foo/baz")))
def test_namespace_accepts_controller():
    """
    Namespaces may optionally contain a controller.

    """
    graph = create_object_graph(name="example", testing=True)
    controller = Mock()
    ns = Namespace(subject="foo", controller=controller)

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    with graph.app.test_request_context():
        url = ns.href_for(Operation.Search)
        assert_that(url, is_(equal_to("http://localhost/api/foo")))
        url = ns.url_for(Operation.Search)
        assert_that(url, is_(equal_to("http://localhost/api/foo")))
        assert_that(ns.controller, is_(equal_to(controller)))