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, ), )
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_slice( letters[:1], slice_start=0, array_length=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
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, )
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 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, )
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_slice( array_abcde[:1], slice_start=0, array_length=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_a page_info = connection.pageInfo assert isinstance(page_info, CustomPageInfo) assert page_info.startCursor == cursor_a assert page_info.endCursor == cursor_a assert page_info.hasPreviousPage is False assert page_info.hasNextPage is False
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 does_not_require_args(): c = connection_from_array_slice(array_abcde, slice_start=0, array_length=5) 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, ), )
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, ), )
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 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, ), )
def uses_array_slice_length_instead_of_len_function(): class LettersWithoutLen: __getitem__ = array_abcde.__getitem__ letters_without_len = cast(Sequence, LettersWithoutLen()) with raises(TypeError): len(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_a, edge_b, edge_c, edge_d, edge_e], pageInfo=PageInfo( startCursor=cursor_a, endCursor=cursor_e, hasPreviousPage=False, hasNextPage=False, ), )
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, ), )
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 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 uses_default_connection_types(): connection = connection_from_array_slice(letters[:1], slice_start=0, array_length=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, )
def uses_default_connection_types(): connection = connection_from_array_slice(array_abcde[:1], slice_start=0, array_length=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 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, ), )
def does_not_require_args(): c = connection_from_array_slice(letters, slice_start=0, array_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, ), )