diff --git a/Makefile b/Makefile index 21572e0..9883f26 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: integration_tests lint unit_tests +.PHONY: integration_tests lint unit_tests clean_organic_data install: @echo pip install @@ -15,9 +15,11 @@ unit_tests: package_test: ./package_test/run.sh -integration_tests: +clean_organic_data: @echo cleaning organic data... python -m pytest ./integration_tests/clean_organic_data.py + +integration_tests: clean_organic_data @echo integration tests... python -m pytest --ignore=clean_organic_data.py --cov ./pinterest/ --cov-branch ./integration_tests/ --cov-report term-missing diff --git a/integration_tests/organic/test_boards.py b/integration_tests/organic/test_boards.py index 6e8c4b4..98dcc6b 100644 --- a/integration_tests/organic/test_boards.py +++ b/integration_tests/organic/test_boards.py @@ -13,6 +13,7 @@ from pinterest.organic.boards import Board from pinterest.organic.boards import BoardSection from pinterest.organic.pins import Pin +from pinterest.utils.bookmark import Bookmark from integration_tests.base_test import BaseTestCase from integration_tests.config import DEFAULT_BOARD_ID, DEFAULT_BOARD_NAME @@ -318,7 +319,12 @@ def test_list_pins_on_board(self): assert len(created_pin_ids) == NUMBER_OF_PINS_TO_CREATE - pins_list, _ = new_board.list_pins() + pins_list_1, bookmark_1 = new_board.list_pins(page_size=NUMBER_OF_PINS_TO_CREATE//2+1) + assert isinstance(bookmark_1, Bookmark) + + pins_list_2, _ = bookmark_1.get_next() + + pins_list = pins_list_1 + pins_list_2 # delete organic data from prod for pin in pins_list: diff --git a/pinterest/organic/boards.py b/pinterest/organic/boards.py index 083aed5..0b57eee 100644 --- a/pinterest/organic/boards.py +++ b/pinterest/organic/boards.py @@ -520,7 +520,6 @@ def list_pins( section_id:str = None, page_size:int = None, bookmark:str = None, - **kwargs ) -> tuple[list[Pin], Bookmark]: """ Get a list of the Pins on a board owned by the "operation user_account" - or on a group board that has been @@ -562,6 +561,7 @@ def _map_function(obj): api=BoardsApi, list_fn=BoardsApi.boards_list_pins if not section_id else BoardsApi.board_sections_list_pins, map_fn=_map_function, + bookmark_model_cls=self, + bookmark_model_fn=self.list_pins, client=self._client, - **kwargs ) diff --git a/pinterest/utils/base_model.py b/pinterest/utils/base_model.py index 5152a92..31a6889 100644 --- a/pinterest/utils/base_model.py +++ b/pinterest/utils/base_model.py @@ -117,6 +117,8 @@ def _list( api: type = None, list_fn: Callable = None, map_fn: Callable = None, + bookmark_model_cls: object = None, + bookmark_model_fn: Callable = None, client: PinterestSDKClient = None, **kwargs ): @@ -148,13 +150,14 @@ def _list( if bookmark is not None: kwargs["bookmark"] = bookmark - kwargs.update(params) + if not bookmark_model_cls: + kwargs.update(params) bookmark_model = Bookmark( bookmark_token=bookmark, - model=cls, - model_fn='get_all', + model=cls if not bookmark_model_cls else bookmark_model_cls, + model_fn='get_all' if not bookmark_model_fn else bookmark_model_fn.__name__, model_fn_args=kwargs, - client=client, + client=client if not bookmark_model_cls else None, ) if bookmark else None return [map_fn(item) for item in items], bookmark_model diff --git a/pinterest/utils/bookmark.py b/pinterest/utils/bookmark.py index 87364f3..d62f5b1 100644 --- a/pinterest/utils/bookmark.py +++ b/pinterest/utils/bookmark.py @@ -43,7 +43,8 @@ def get_next(self) -> tuple[list[object], Bookmark]: Bookmark: Bookmark Object for pagination if present, else None. """ self.model_fn_args['bookmark'] = self.bookmark_token - self.model_fn_args['client'] = self.client + if self.client: + self.model_fn_args['client'] = self.client if 'kwargs' in self.model_fn_args: kwargs = self.model_fn_args.get('kwargs') del self.model_fn_args['kwargs']