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_slice(
                letters[:1],
                slice_start=0,
                array_length=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,
            )
Beispiel #2
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_slice(
                array_abcde[:1],
                slice_start=0,
                array_length=1,
                connection_type=CustomConnection,
            )
            assert isinstance(connection, CustomConnection)
            edge = connection.edges[0]
            assert isinstance(edge, Edge)
            assert len(connection.edges) == 1
            assert edge == edge_a
            page_info = connection.page_info
            assert isinstance(page_info, PageInfo)
            assert page_info == PageInfo(
                startCursor=cursor_a,
                endCursor=cursor_a,
                hasPreviousPage=False,
                hasNextPage=False,
            )
        def uses_array_slice_length_instead_of_len_function():
            class LettersWithoutLen:
                __getitem__ = letters.__getitem__

            letters_without_len = LettersWithoutLen()

            with raises(TypeError):
                len(cast(Sequence, letters_without_len))

            with raises(TypeError):
                connection_from_array_slice(letters_without_len)

            c = connection_from_array_slice(letters_without_len,
                                            array_slice_length=5)
            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,
                ),
            )
Beispiel #4
0
        def accepts_custom_edge_type():
            class CustomEdge:
                def __init__(self, node, cursor):
                    self.node = node
                    self.cursor = cursor

            connection = connection_from_array_slice(array_abcde[:1],
                                                     slice_start=0,
                                                     array_length=1,
                                                     edge_type=CustomEdge)
            assert isinstance(connection, Connection)
            assert isinstance(connection.edges, list)
            assert len(connection.edges) == 1
            edge = connection.edges[0]
            assert isinstance(edge, CustomEdge)
            assert edge.node == "A"
            assert edge.cursor == cursor_a
            page_info = connection.pageInfo
            assert isinstance(page_info, PageInfo)
            assert page_info == PageInfo(
                startCursor=cursor_a,
                endCursor=cursor_a,
                hasPreviousPage=False,
                hasNextPage=False,
            )
Beispiel #5
0
 def does_not_require_args():
     c = connection_from_array(array_abcde)
     assert c == Connection(
         edges=[edge_a, edge_b, edge_c, edge_d, edge_e],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_e,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #6
0
 def returns_all_elements_without_filters():
     c = connection_from_array(array_abcde, {})
     assert c == Connection(
         edges=[edge_a, edge_b, edge_c, edge_d, edge_e],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_e,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #7
0
 def respects_a_smaller_last():
     c = connection_from_array(array_abcde, dict(last=2))
     assert c == Connection(
         edges=[edge_d, edge_e],
         pageInfo=PageInfo(
             startCursor=cursor_d,
             endCursor=cursor_e,
             hasPreviousPage=True,
             hasNextPage=False,
         ),
     )
Beispiel #8
0
 def respects_an_overly_large_last():
     c = connection_from_array(array_abcde, dict(last=10))
     assert c == Connection(
         edges=[edge_a, edge_b, edge_c, edge_d, edge_e],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_e,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #9
0
 def returns_all_elements_if_cursors_are_invalid():
     c = connection_from_array(array_abcde,
                               dict(before="invalid", after="invalid"))
     assert c == Connection(
         edges=[edge_a, edge_b, edge_c, edge_d, edge_e],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_e,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #10
0
 def respects_last_and_before_with_long_last():
     c = connection_from_array(array_abcde,
                               dict(last=10, before=cursor_d))
     assert c == Connection(
         edges=[edge_a, edge_b, edge_c],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_c,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #11
0
 def respects_first_and_after_with_long_first():
     c = connection_from_array(array_abcde,
                               dict(first=10, after=cursor_b))
     assert c == Connection(
         edges=[edge_c, edge_d, edge_e],
         pageInfo=PageInfo(
             startCursor=cursor_c,
             endCursor=cursor_e,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
 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,
         ),
     )
Beispiel #13
0
 def uses_slice_end_as_default_for_array_length():
     c = connection_from_array_slice(array_abcde[:1],
                                     dict(first=1),
                                     slice_start=0)
     assert c == Connection(
         edges=[edge_a],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_a,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
 def respects_a_smaller_last():
     c = connection_from_array(letters, dict(last=2))
     assert c == Connection(
         edges=[
             Edge(node="D", cursor="YXJyYXljb25uZWN0aW9uOjM="),
             Edge(node="E", cursor="YXJyYXljb25uZWN0aW9uOjQ="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjM=",
             endCursor="YXJyYXljb25uZWN0aW9uOjQ=",
             hasPreviousPage=True,
             hasNextPage=False,
         ),
     )
 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,
         ),
     )
Beispiel #16
0
 def respects_last_and_after_and_before_exactly_right():
     c = connection_from_array(
         array_abcde,
         dict(last=3, after=cursor_a, before=cursor_e),
     )
     assert c == Connection(
         edges=[edge_b, edge_c, edge_d],
         pageInfo=PageInfo(
             startCursor=cursor_b,
             endCursor=cursor_d,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #17
0
 def respects_first_and_after_and_before_too_few():
     c = connection_from_array(
         array_abcde,
         dict(first=2, after=cursor_a, before=cursor_e),
     )
     assert c == Connection(
         edges=[edge_b, edge_c],
         pageInfo=PageInfo(
             startCursor=cursor_b,
             endCursor=cursor_c,
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
Beispiel #18
0
 def returns_no_elements_if_cursors_cross():
     c = connection_from_array(
         array_abcde,
         dict(before=cursor_c, after=cursor_e),
     )
     assert c == Connection(
         edges=[],
         pageInfo=PageInfo(
             startCursor=None,
             endCursor=None,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #19
0
 def ignores_len_of_slice_if_array_slice_length_provided():
     c = connection_from_array_slice(array_abcde[:2],
                                     dict(first=2),
                                     array_length=2,
                                     array_slice_length=1)
     assert c == Connection(
         edges=[edge_a],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_a,
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
 def returns_no_elements_if_cursors_cross():
     c = connection_from_array(
         letters,
         dict(before="YXJyYXljb25uZWN0aW9uOjI=",
              after="YXJyYXljb25uZWN0aW9uOjQ="),
     )
     assert c == Connection(
         edges=[],
         pageInfo=PageInfo(
             startCursor=None,
             endCursor=None,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
 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,
     )
Beispiel #22
0
 def uses_default_connection_types():
     connection = connection_from_array(array_abcde[:1])
     assert isinstance(connection, Connection)
     edge = connection.edges[0]
     assert isinstance(edge, Edge)
     assert len(connection.edges) == 1
     assert edge == edge_a
     page_info = connection.pageInfo
     assert isinstance(page_info, PageInfo)
     assert page_info == PageInfo(
         startCursor=cursor_a,
         endCursor=cursor_a,
         hasPreviousPage=False,
         hasNextPage=False,
     )
 def respects_last_and_before():
     c = connection_from_array(
         letters, dict(last=2, before="YXJyYXljb25uZWN0aW9uOjM="))
     assert c == Connection(
         edges=[
             Edge(node="B", cursor="YXJyYXljb25uZWN0aW9uOjE="),
             Edge(node="C", cursor="YXJyYXljb25uZWN0aW9uOjI="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjE=",
             endCursor="YXJyYXljb25uZWN0aW9uOjI=",
             hasPreviousPage=True,
             hasNextPage=False,
         ),
     )
 def respects_first_and_after_with_long_first():
     c = connection_from_array(
         letters, dict(first=10, after="YXJyYXljb25uZWN0aW9uOjE="))
     assert c == Connection(
         edges=[
             Edge(node="C", cursor="YXJyYXljb25uZWN0aW9uOjI="),
             Edge(node="D", cursor="YXJyYXljb25uZWN0aW9uOjM="),
             Edge(node="E", cursor="YXJyYXljb25uZWN0aW9uOjQ="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjI=",
             endCursor="YXJyYXljb25uZWN0aW9uOjQ=",
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
Beispiel #25
0
 def works_with_an_undersized_array_slice_both_sides():
     c = connection_from_array_slice(
         array_abcde[3:4],
         dict(first=3, after=cursor_b),
         slice_start=3,
         array_length=5,
     )
     assert c == Connection(
         edges=[edge_d],
         pageInfo=PageInfo(
             startCursor=cursor_d,
             endCursor=cursor_d,
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
Beispiel #26
0
 def works_with_an_oversized_array_slice_right_side():
     c = connection_from_array_slice(
         array_abcde[2:4],
         dict(first=1, after=cursor_b),
         slice_start=2,
         array_length=5,
     )
     assert c == Connection(
         edges=[edge_c],
         pageInfo=PageInfo(
             startCursor=cursor_c,
             endCursor=cursor_c,
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
 def works_with_an_undersized_array_slice_both_sides():
     c = connection_from_array_slice(
         letters[3:4],
         dict(first=3, after="YXJyYXljb25uZWN0aW9uOjE="),
         slice_start=3,
         array_length=5,
     )
     assert c == Connection(
         edges=[Edge(node="D", cursor="YXJyYXljb25uZWN0aW9uOjM=")],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjM=",
             endCursor="YXJyYXljb25uZWN0aW9uOjM=",
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
 def returns_all_elements_without_filters():
     c = connection_from_array(letters, {})
     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,
         ),
     )
 def does_not_require_args():
     c = connection_from_array(letters)
     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,
         ),
     )
 def respects_an_overly_large_last():
     c = connection_from_array(letters, dict(last=10))
     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,
         ),
     )