-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(schematic): integration testing (#2398) * changed authenticication so that only endpoints that need it have it * updated schematic * add patch for access token * schema endpoints no longer mockeed * added tests for handle exceptions * added integration tests * marked synapse tests * added error handling for bad schema urls * fix error message * add workflow for end to end testing * fix some test results * add unit mark * add unit mark * add workflow for testing with secrets * rename file * fix synapse test file when secrets file doesnt exists * fix test workflows * turned synapse ids into secrets in workflow * turned synapse ids into secrets in workflow * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * add paging, and split connected noeds into two endpoints * paginated preoject datasets query * paginated preoject datasets query * paginated dataset files endpoint * pagniate project manifests endpoint * paginate get node dependencies * paginate get node dependencies * paginate node properties endpoint * paginate validation rules endpoint * paginate get projects endpoint * unpaginate node properties and validation rules endpoints * unpaginate node properties and validation rules endpoints
- Loading branch information
1 parent
4f9b475
commit 6d5cd01
Showing
87 changed files
with
4,691 additions
and
2,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
"""Functionality to handle paginated endpoints""" | ||
|
||
import math | ||
from typing import TypeVar | ||
|
||
ITEM_TYPE = TypeVar("ITEM_TYPE") | ||
TOTAL_ITEMS_MSG = "total_items must be 0 or greater: " | ||
PAGE_MAX_ITEMS_MSG = "page_max_items must be 1 or greater: " | ||
PAGE_NUMBER_MSG = "page_number must be 1 or greater: " | ||
|
||
|
||
class Page: | ||
"""This represents a page for a generic list of items for a paginated endpoint""" | ||
|
||
def __init__( | ||
self, items: list[ITEM_TYPE], page_number: int = 1, page_max_items: int = 100000 | ||
) -> None: | ||
""" | ||
Args: | ||
items (list[ITEM_TYPE]): A list of all items in the query | ||
page_number (int, optional): The page number the current request is for. Defaults to 1. | ||
page_max_items (int, optional): The maximum number of items per page. Defaults to 100000. | ||
""" | ||
self.page_number = page_number | ||
self.page_max_items = page_max_items | ||
self.total_items = len(items) | ||
self.total_pages = get_page_amount(self.total_items, page_max_items) | ||
self.has_next = page_number < self.total_pages | ||
self.has_previous = page_number > 1 | ||
self.items: list[ITEM_TYPE] = get_item_slice(items, page_max_items, page_number) | ||
|
||
|
||
def get_page_amount(total_items: int, page_max_items: int) -> int: | ||
"""Getes the amount of pages total based on the number of items and page size | ||
Args: | ||
total_items (int): The total number of items in the query | ||
page_max_items (int): The maximum number of items per page | ||
Raises: | ||
ValueError: total_items is less than 0 | ||
ValueError: page_max_items is less than | ||
Returns: | ||
int: The amount of pages | ||
""" | ||
if total_items < 0: | ||
raise ValueError(TOTAL_ITEMS_MSG, total_items) | ||
if page_max_items < 1: | ||
raise ValueError(PAGE_MAX_ITEMS_MSG, page_max_items) | ||
return math.ceil(total_items / page_max_items) | ||
|
||
|
||
def get_item_slice( | ||
items: list[ITEM_TYPE], page_max_items: int, page_number: int | ||
) -> list[ITEM_TYPE]: | ||
"""Gets a list slice based on the paging parameters | ||
Args: | ||
items (list[ITEM_TYPE]): A list of items to be sliced | ||
page_max_items (int): The maximum number of items per page | ||
page_number (int): The page number the current request is for | ||
Returns: | ||
list[ITEM_TYPE]: The slice of items | ||
""" | ||
page_indeces = get_page_indeces(len(items), page_max_items, page_number) | ||
return items[page_indeces[0] : page_indeces[1]] | ||
|
||
|
||
def get_page_indeces( | ||
total_items: int, page_max_items: int, page_number: int | ||
) -> tuple[int, int]: | ||
"""Gets the indces used to slice the list of items | ||
Args: | ||
total_items (int): The total number of items in the query | ||
page_max_items (int): The maximum number of items per page | ||
page_number (int): The page number the current request is for | ||
Raises: | ||
ValueError: total_items is less than 0 | ||
ValueError: page_max_items is less than 1 | ||
ValueError: page_number is less than 1 | ||
Returns: | ||
tuple[int, int]: The two indeces to slice the list of items with | ||
""" | ||
if total_items < 0: | ||
raise ValueError(TOTAL_ITEMS_MSG, total_items) | ||
if page_max_items < 1: | ||
raise ValueError(PAGE_MAX_ITEMS_MSG, page_max_items) | ||
if page_number < 1: | ||
raise ValueError(PAGE_NUMBER_MSG, page_number) | ||
index1 = (page_number - 1) * page_max_items | ||
index2 = min(index1 + page_max_items, total_items) | ||
return (index1, index2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.