def get_links(self, obj):
     links = Links()
     links["self"] = Link.for_(
         Operation.Retrieve,
         Namespace(
             subject=FollowerRelationship,
             version="v1",
         ),
         follower_relationship_id=obj.id,
     )
     links["user"] = Link.for_(
         Operation.Retrieve,
         Namespace(
             subject=User,
             version="v1",
         ),
         user_id=obj.user_id,
     )
     links["follower"] = Link.for_(
         Operation.Retrieve,
         Namespace(
             subject=User,
             version="v1",
         ),
         user_id=obj.follower_id,
     )
     return links.to_dict()
示例#2
0
    def setup(self):
        self.graph = create_object_graph(name="example", testing=True)

        self.ns = Namespace(subject="file")
        self.relation_ns = Namespace(subject=Person, object_="file")

        self.controller = FileController()

        UPLOAD_MAPPINGS = {
            Operation.Upload: EndpointDefinition(
                func=self.controller.upload,
                request_schema=FileExtraSchema(),
            ),
        }

        UPLOAD_FOR_MAPPINGS = {
            Operation.UploadFor: EndpointDefinition(
                func=self.controller.upload_for_person,
                request_schema=FileExtraSchema(),
                response_schema=FileResponseSchema(),
            ),
        }

        configure_upload(self.graph, self.ns, UPLOAD_MAPPINGS)
        configure_upload(self.graph, self.relation_ns, UPLOAD_FOR_MAPPINGS)
        configure_swagger(self.graph)

        self.client = self.graph.flask.test_client()
示例#3
0
 def setup(self):
     self.graph = create_object_graph(name="example", testing=True)
     person_ns = Namespace(subject=Person)
     address_ns = Namespace(subject=Address)
     configure_crud(self.graph, person_ns, PERSON_MAPPINGS)
     configure_crud(self.graph, address_ns, ADDRESS_MAPPINGS)
     self.client = self.graph.flask.test_client()
示例#4
0
    def setup(self):
        self.graph = create_object_graph(name="example", testing=True)

        self.ns = Namespace(subject="file")
        self.relation_ns = Namespace(subject=Person, object_="file")
        configure_upload(self.graph, self.ns, UPLOAD_MAPPINGS)
        configure_upload(self.graph, self.relation_ns, UPLOAD_FOR_MAPPINGS)
        configure_swagger(self.graph)

        self.client = self.graph.flask.test_client()
示例#5
0
 def get_links(self, obj):
     links = Links()
     links["self"] = Link.for_(
         Operation.Retrieve,
         Namespace(subject=Topping, version="v1",),
         topping_id=obj.id,
     )
     links["parent:pizza"] = Link.for_(
         Operation.Search, Namespace(subject=Pizza, version="v1"), id=obj.pizza_id
     )
     return links.to_dict()
示例#6
0
 def get_links(self, obj):
     links = Links()
     links["self"] = Link.for_(
         Operation.Retrieve,
         ns=Namespace(
             subject=Address,
             path=Namespace(subject=Person, ).instance_path,
         ),
         person_id=obj.person_id,
         address_id=obj.id,
     )
     return links.to_dict()
 def setup(self):
     self.graph = create_object_graph(name="example", testing=True)
     self.person_ns = Namespace(subject=Person)
     self.ns = Namespace(subject=PersonSearch)
     # ensure that link hrefs work
     configure_crud(self.graph, self.person_ns, {
         Operation.Retrieve: (person_retrieve, PersonLookupSchema(), PersonSchema()),
     })
     # enable saved search
     configure_saved_search(self.graph, self.ns, {
         Operation.SavedSearch: (person_search, OffsetLimitPageSchema(), PersonSchema()),
     })
     self.client = self.graph.flask.test_client()
示例#8
0
    def __init__(self, graph):
        super().__init__(graph, graph.order_store)

        self.ns = Namespace(
            subject=Order,
            version="v1",
        )
示例#9
0
def test_build_integer_valued_param():
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(
        subject=Person,
        version="v1",
        identifier_type="int",
    )
    configure_crud(graph, ns, PERSON_MAPPINGS)

    with graph.flask.test_request_context():
        operations = list(iter_endpoints(graph, match_function))
        swagger_schema = build_swagger(graph, ns, operations)

        assert_that(
            build_path_for_integer_param(ns, Operation.Update,
                                         set(["person_id"])),
            equal_to("/api/v1/person/{person_id}"),
        )

    assert_that(
        swagger_schema,
        has_entries(paths=has_entries(
            **{
                "/person/{person_id}":
                has_entries(patch=has_entries(parameters=has_items({
                    "required":
                    True,
                    "type":
                    "integer",
                    "name":
                    "person_id",
                    "in":
                    "path",
                }), ), ),
            }, ), ))
    def __init__(self, graph):
        super().__init__(graph, graph.encryptable_store)

        self.ns = Namespace(
            subject="encryptable",
            version="v1",
        )
示例#11
0
    def __init__(self, graph):
        super().__init__(graph, graph.pizza_store)

        self.ns = Namespace(
            subject=Pizza,
            version="v1",
        )
示例#12
0
    def __init__(self, graph):
        super().__init__(graph, graph.topping_store)

        self.ns = Namespace(
            subject=Topping,
            version="v1",
        )
示例#13
0
    def __init__(self, graph):
        super().__init__(graph, graph.customer_event_store)

        self.ns = Namespace(
            subject=CustomerEvent,
            version="v1",
        )
示例#14
0
    def __init__(self, graph):
        super().__init__(graph, graph.example_store)

        self.ns = Namespace(
            subject=Example,
            version="v1",
        )
示例#15
0
 def __init__(self, graph):
     super(TaskEventController, self).__init__(graph,
                                               graph.task_event_store)
     self.ns = Namespace(
         subject=TaskEvent,
         version="v1",
     )
示例#16
0
def test_discovery():
    graph = create_object_graph(name="example", testing=True)
    graph.use("discovery_convention")

    ns = Namespace("foo")

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

    client = graph.flask.test_client()

    response = client.get("/api/")
    assert_that(response.status_code, is_(equal_to(200)))
    data = loads(response.get_data().decode("utf-8"))
    assert_that(
        data,
        is_(
            equal_to({
                "_links": {
                    "search": [{
                        "href": "http://localhost/api/foo?offset=0&limit=20",
                        "type": "foo",
                    }],
                    "self": {
                        "href": "http://localhost/api/?offset=0&limit=20",
                    },
                }
            })))
示例#17
0
    def __init__(self, graph):
        super().__init__(graph, graph.account_store)

        self.ns = Namespace(
            subject=Account,
            version="v1",
        )
示例#18
0
def test_custom_paginated_list():
    graph = create_object_graph(name="example", testing=True)
    ns = Namespace(subject="foo", object_="bar")

    @graph.route(ns.relation_path, Operation.SearchFor, ns)
    def search_foo():
        pass

    uid = uuid4()
    paginated_list = PaginatedList(
        ns,
        Page.from_query_string(
            dict(
                offset=2,
                limit=2,
                baz="baz",
                uid=uid,
                value=MyEnum.ONE,
            )),
        ["1", "2"],
        10,
        operation=Operation.SearchFor,
        foo_id="FOO_ID",
    )

    rest = "baz=baz&uid={}&value=ONE".format(uid)

    with graph.flask.test_request_context():
        assert_that(
            paginated_list.to_dict(),
            is_(
                equal_to({
                    "count": 10,
                    "items": [
                        "1",
                        "2",
                    ],
                    "offset": 2,
                    "limit": 2,
                    "_links": {
                        "self": {
                            "href":
                            "http://localhost/api/foo/FOO_ID/bar?offset=2&limit=2&{}"
                            .format(rest),
                        },
                        "next": {
                            "href":
                            "http://localhost/api/foo/FOO_ID/bar?offset=4&limit=2&{}"
                            .format(rest),
                        },
                        "prev": {
                            "href":
                            "http://localhost/api/foo/FOO_ID/bar?offset=0&limit=2&{}"
                            .format(rest),
                        },
                    },
                    "baz": "baz",
                    "uid": str(uid),
                    "value": "ONE",
                })))
示例#19
0
    def __init__(self, graph):
        super().__init__(graph, graph.follower_relationship_store)

        self.ns = Namespace(
            subject=FollowerRelationship,
            version="v1",
        )
示例#20
0
 def get_links(self, obj):
     links = Links()
     links["self"] = Link.for_(
         Operation.Retrieve,
         Namespace(
             subject=User,
             version="v1",
         ),
         user_id=obj.id,
     )
     links["tweets"] = Link.for_(
         Operation.SearchFor,
         Namespace(
             subject=User,
             object_="tweets",
             version="v1",
         ),
         user_id=obj.id,
     )
     links["followers"] = Link.for_(
         Operation.SearchFor,
         Namespace(
             subject=User,
             object_="followers",
             version="v1",
         ),
         user_id=obj.id,
     )
     links["following"] = Link.for_(
         Operation.SearchFor,
         Namespace(
             subject=User,
             object_="following",
             version="v1",
         ),
         user_id=obj.id,
     )
     links["feed"] = Link.for_(
         Operation.SearchFor,
         Namespace(
             subject=User,
             object_="feed",
             version="v1",
         ),
         user_id=obj.id,
     )
     return links.to_dict()
示例#21
0
def test_operation_naming_relation():
    """
    Complext (subject+object) endpoint naming works.

    """
    ns = Namespace(subject="foo", object_="bar")
    endpoint = ns.endpoint_for(Operation.SearchFor)
    assert_that(endpoint, is_(equal_to("foo.search_for.bar.v1")))
示例#22
0
def test_endpoint_for():
    """
    Simple (subject-only) endpoint naming works.

    """
    ns = Namespace(subject="foo")
    endpoint = ns.endpoint_for(Operation.Search)
    assert_that(endpoint, is_(equal_to("foo.search.v1")))
示例#23
0
    def __init__(self, graph):
        super().__init__(graph, graph.tweet_store)
        self.follower_relationship_store = graph.follower_relationship_store

        self.ns = Namespace(
            subject=Tweet,
            version="v1",
        )
示例#24
0
    def setup(self):
        self.graph = create_object_graph(name="example", testing=True)

        self.ns = Namespace(subject=Person)
        configure_crud(self.graph, self.ns, PERSON_MAPPINGS)
        configure_alias(self.graph, self.ns, PERSON_MAPPINGS)

        self.client = self.graph.flask.test_client()
示例#25
0
 def get_links(self, obj):
     links = Links()
     links["self"] = Link.for_(
         Operation.Retrieve,
         Namespace(subject=Address),
         address_id=obj.id,
     )
     return links.to_dict()
示例#26
0
    def setup(self):
        self.graph = create_object_graph(name="example", testing=True)

        self.ns = Namespace(subject="foo")

        configure_crud(self.graph, self.ns, FOO_MAPPINGS)
        configure_swagger(self.graph)

        self.client = self.graph.flask.test_client()
示例#27
0
    def __init__(self, graph):
        super().__init__(graph, graph.pizza_store)

        self.ns = Namespace(
            subject=Pizza,
            version="v1",
        )
        self.order_event_factory = graph.order_event_factory
        self.sns_producer = graph.sns_producer
示例#28
0
    def get_links(self, obj):
        links = Links()
        links["self"] = Link.for_(
            Operation.Retrieve,
            Namespace(subject=OrderEvent, version="v1",),
            order_event_id=obj.id,
        )

        return links.to_dict()
示例#29
0
def configure_discovery(graph):
    """
    Build a singleton endpoint that provides a link to all search endpoints.

    """
    ns = Namespace(subject=graph.config.discovery_convention.name, )
    convention = DiscoveryConvention(graph)
    convention.configure(ns, discover=tuple())
    return ns.subject
示例#30
0
def configure_build_info(graph):
    """
    Configure the build info endpoint.

    """
    ns = Namespace(subject=BuildInfo, )

    convention = BuildInfoConvention(graph)
    convention.configure(ns, retrieve=tuple())
    return convention.build_info