コード例 #1
0
 def works_with_an_undersized_array_slice_right_side():
     c = connection_from_array_slice(
         letters[2:4],
         dict(first=3, after="YXJyYXljb25uZWN0aW9uOjE="),
         slice_start=2,
         array_length=5,
     )
     assert c == Connection(
         edges=[
             Edge(node="C", cursor="YXJyYXljb25uZWN0aW9uOjI="),
             Edge(node="D", cursor="YXJyYXljb25uZWN0aW9uOjM="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjI=",
             endCursor="YXJyYXljb25uZWN0aW9uOjM=",
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
コード例 #2
0
 def respects_last_and_after_and_before_too_few():
     c = connection_from_array(
         letters,
         dict(
             last=2,
             after="YXJyYXljb25uZWN0aW9uOjA=",
             before="YXJyYXljb25uZWN0aW9uOjQ=",
         ),
     )
     assert c == Connection(
         edges=[
             Edge(node="C", cursor="YXJyYXljb25uZWN0aW9uOjI="),
             Edge(node="D", cursor="YXJyYXljb25uZWN0aW9uOjM="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjI=",
             endCursor="YXJyYXljb25uZWN0aW9uOjM=",
             hasPreviousPage=True,
             hasNextPage=False,
         ),
     )
コード例 #3
0
 def uses_slice_end_as_default_for_array_length():
     c = connection_from_array_slice(letters[:1],
                                     dict(first=1),
                                     slice_start=0)
     assert c == Connection(
         edges=[Edge(node="A", cursor="YXJyYXljb25uZWN0aW9uOjA=")],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjA=",
             endCursor="YXJyYXljb25uZWN0aW9uOjA=",
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
コード例 #4
0
 def respects_first_and_after_and_before_exactly_right():
     c = connection_from_array(
         letters,
         dict(
             first=3,
             after="YXJyYXljb25uZWN0aW9uOjA=",
             before="YXJyYXljb25uZWN0aW9uOjQ=",
         ),
     )
     assert c == Connection(
         edges=[
             Edge(node="B", cursor="YXJyYXljb25uZWN0aW9uOjE="),
             Edge(node="C", cursor="YXJyYXljb25uZWN0aW9uOjI="),
             Edge(node="D", cursor="YXJyYXljb25uZWN0aW9uOjM="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjE=",
             endCursor="YXJyYXljb25uZWN0aW9uOjM=",
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
コード例 #5
0
 def ignores_len_of_slice_if_array_slice_length_provided():
     c = connection_from_array_slice(letters[:2],
                                     dict(first=2),
                                     array_length=2,
                                     array_slice_length=1)
     assert c == Connection(
         edges=[Edge(node="A", cursor="YXJyYXljb25uZWN0aW9uOjA=")],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjA=",
             endCursor="YXJyYXljb25uZWN0aW9uOjA=",
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
コード例 #6
0
 def returns_all_elements_if_cursors_are_on_the_outside():
     c = connection_from_array(
         letters,
         dict(
             before="YXJyYXljb25uZWN0aW9uOjYK",
             after="YXJyYXljb25uZWN0aW9uOi0xCg==",
         ),
     )
     assert c == Connection(
         edges=[
             Edge(node="A", cursor="YXJyYXljb25uZWN0aW9uOjA="),
             Edge(node="B", cursor="YXJyYXljb25uZWN0aW9uOjE="),
             Edge(node="C", cursor="YXJyYXljb25uZWN0aW9uOjI="),
             Edge(node="D", cursor="YXJyYXljb25uZWN0aW9uOjM="),
             Edge(node="E", cursor="YXJyYXljb25uZWN0aW9uOjQ="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjA=",
             endCursor="YXJyYXljb25uZWN0aW9uOjQ=",
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
コード例 #7
0
 def uses_default_connection_types():
     connection = connection_from_array(letters[:1])
     assert isinstance(connection, Connection)
     edge = connection.edges[0]
     assert isinstance(edge, Edge)
     assert len(connection.edges) == 1
     assert edge == Edge(node="A", cursor="YXJyYXljb25uZWN0aW9uOjA=")
     page_info = connection.pageInfo
     assert isinstance(page_info, PageInfo)
     assert page_info == PageInfo(
         startCursor="YXJyYXljb25uZWN0aW9uOjA=",
         endCursor="YXJyYXljb25uZWN0aW9uOjA=",
         hasPreviousPage=False,
         hasNextPage=False,
     )
コード例 #8
0
 def provides_deprecated_connection_from_list():
     with deprecated_call():
         # noinspection PyDeprecation
         c = connection_from_list(
             letters[:1],
             args={},
             connection_type=Connection,
             edge_type=Edge,
             pageinfo_type=PageInfo,
         )
     assert c == Connection(
         edges=[Edge(node="A", cursor="YXJyYXljb25uZWN0aW9uOjA=")],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjA=",
             endCursor="YXJyYXljb25uZWN0aW9uOjA=",
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
コード例 #9
0
        def accepts_custom_connection_type():
            class CustomConnection:
                # noinspection PyPep8Naming
                def __init__(self, edges, pageInfo):
                    self.edges = edges
                    self.page_info = pageInfo

            connection = connection_from_array(
                letters[:1], connection_type=CustomConnection)
            assert isinstance(connection, CustomConnection)
            edge = connection.edges[0]
            assert isinstance(edge, Edge)
            assert len(connection.edges) == 1
            assert edge == Edge(node="A", cursor="YXJyYXljb25uZWN0aW9uOjA=")
            page_info = connection.page_info
            assert isinstance(page_info, PageInfo)
            assert page_info == PageInfo(
                startCursor="YXJyYXljb25uZWN0aW9uOjA=",
                endCursor="YXJyYXljb25uZWN0aW9uOjA=",
                hasPreviousPage=False,
                hasNextPage=False,
            )
コード例 #10
0
        def accepts_custom_page_info_type():
            class CustomPageInfo:
                # noinspection PyPep8Naming
                def __init__(self, startCursor, endCursor, hasPreviousPage,
                             hasNextPage):
                    self.startCursor = startCursor
                    self.endCursor = endCursor
                    self.hasPreviousPage = hasPreviousPage
                    self.hasNextPage = hasNextPage

            connection = connection_from_array(letters[:1],
                                               page_info_type=CustomPageInfo)
            assert isinstance(connection, Connection)
            assert isinstance(connection.edges, list)
            assert len(connection.edges) == 1
            edge = connection.edges[0]
            assert isinstance(edge, Edge)
            assert edge == Edge(node="A", cursor="YXJyYXljb25uZWN0aW9uOjA=")
            page_info = connection.pageInfo
            assert isinstance(page_info, CustomPageInfo)
            assert page_info.startCursor == "YXJyYXljb25uZWN0aW9uOjA="
            assert page_info.endCursor == "YXJyYXljb25uZWN0aW9uOjA="
            assert page_info.hasPreviousPage is False
            assert page_info.hasNextPage is False
コード例 #11
0
    Edge,
    PageInfo,
)

# noinspection PyProtectedMember
from graphql_relay import connection_from_list, connection_from_list_slice

array_abcde = ["A", "B", "C", "D", "E"]

cursor_a = "YXJyYXljb25uZWN0aW9uOjA="
cursor_b = "YXJyYXljb25uZWN0aW9uOjE="
cursor_c = "YXJyYXljb25uZWN0aW9uOjI="
cursor_d = "YXJyYXljb25uZWN0aW9uOjM="
cursor_e = "YXJyYXljb25uZWN0aW9uOjQ="

edge_a = Edge(node="A", cursor=cursor_a)
edge_b = Edge(node="B", cursor=cursor_b)
edge_c = Edge(node="C", cursor=cursor_c)
edge_d = Edge(node="D", cursor=cursor_d)
edge_e = Edge(node="E", cursor=cursor_e)


def describe_connection_from_array():
    def warns_for_deprecated_import():
        from importlib import reload

        with deprecated_call():
            from graphql_relay.connection import arrayconnection as deprecated

            # noinspection PyDeprecation
            reload(deprecated)