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,
                ),
            )
예제 #2
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,
         ),
     )
예제 #3
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,
         ),
     )
예제 #4
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,
         ),
     )
예제 #5
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,
         ),
     )
예제 #6
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,
         ),
     )
예제 #7
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,
         ),
     )
예제 #8
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,
         ),
     )
예제 #9
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 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,
         ),
     )
예제 #11
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,
         ),
     )
예제 #12
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,
         ),
     )
예제 #13
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 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,
         ),
     )
예제 #16
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,
         ),
     )
 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 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 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 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,
         ),
     )
예제 #21
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,
         ),
     )
예제 #22
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 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,
         ),
     )
 def returns_all_elements_if_cursors_are_invalid():
     c = connection_from_array(letters,
                               dict(before="invalid", after="invalid"))
     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 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,
         ),
     )
예제 #28
0
 def provides_deprecated_connection_from_list():
     with deprecated_call():
         # noinspection PyDeprecation
         c = connection_from_list(
             array_abcde[:1],
             args={},
             connection_type=Connection,
             edge_type=Edge,
             pageinfo_type=PageInfo,
         )
     assert c == Connection(
         edges=[edge_a],
         pageInfo=PageInfo(
             startCursor=cursor_a,
             endCursor=cursor_a,
             hasPreviousPage=False,
             hasNextPage=False,
         ),
     )
 def works_with_an_oversized_array_slice_left_side():
     c = connection_from_array_slice(
         letters[0:3],
         dict(first=2, after="YXJyYXljb25uZWN0aW9uOjA="),
         slice_start=0,
         array_length=5,
     )
     assert c == Connection(
         edges=[
             Edge(node="B", cursor="YXJyYXljb25uZWN0aW9uOjE="),
             Edge(node="C", cursor="YXJyYXljb25uZWN0aW9uOjI="),
         ],
         pageInfo=PageInfo(
             startCursor="YXJyYXljb25uZWN0aW9uOjE=",
             endCursor="YXJyYXljb25uZWN0aW9uOjI=",
             hasPreviousPage=False,
             hasNextPage=True,
         ),
     )
예제 #30
0
        def returns_all_elements_if_cursors_are_on_the_outside():
            all_edges = Connection(
                edges=[edge_a, edge_b, edge_c, edge_d, edge_e],
                pageInfo=PageInfo(
                    startCursor=cursor_a,
                    endCursor=cursor_e,
                    hasPreviousPage=False,
                    hasNextPage=False,
                ),
            )

            assert (connection_from_array(
                array_abcde, dict(before=offset_to_cursor(6))) == all_edges)
            assert (connection_from_array(
                array_abcde, dict(before=offset_to_cursor(-1))) == all_edges)
            assert (connection_from_array(
                array_abcde, dict(after=offset_to_cursor(6))) == all_edges)
            assert (connection_from_array(
                array_abcde, dict(after=offset_to_cursor(-1))) == all_edges)