Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug for following bookmark on list_pins in Board model #103

Merged
merged 5 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: integration_tests lint unit_tests
.PHONY: integration_tests lint unit_tests clean_organic_data

install:
@echo pip install
Expand All @@ -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

Expand Down
8 changes: 7 additions & 1 deletion integration_tests/organic/test_boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pinterest/organic/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
11 changes: 7 additions & 4 deletions pinterest/utils/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pinterest/utils/bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down