-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
15 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,44 @@ | ||
"""Primitives for manipulation Pinterest board subsections""" | ||
from friendlypins.utils.base_object import BaseObject | ||
from friendlypins.pin import Pin | ||
|
||
|
||
class Section(BaseObject): | ||
"""Abstraction around a Pinterest board subsection""" | ||
|
||
@staticmethod | ||
def default_url(unique_id): | ||
"""Generates a URL for the REST API endpoint for a section with a given identification number | ||
Args: | ||
unique_id (int): unique ID for the board | ||
Returns: | ||
str: URL for the API endpoint | ||
""" | ||
return "board/sections/{0}".format(unique_id) | ||
|
||
@staticmethod | ||
def default_fields(): | ||
"""list (str): list of fields we pre-populate when loading section data""" | ||
return list() | ||
|
||
@property | ||
def title(self): | ||
"""str: descriptive text associated with this subsection""" | ||
return self._data["title"] | ||
|
||
@property | ||
def pins(self): | ||
"""list (Pin): pins associated with this subsection""" | ||
self._log.debug("Loading pins for board subsection %s...", | ||
self._relative_url) | ||
properties = { | ||
"fields": ','.join(Pin.default_fields()) | ||
} | ||
path = "{0}/pins".format(self._relative_url) | ||
for cur_page in self._io.get_pages(path, properties): | ||
assert "data" in cur_page | ||
|
||
for cur_item in cur_page["data"]: | ||
yield Pin.from_json(cur_item, self._io) |
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
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,30 @@ | ||
import pytest | ||
from friendlypins.api import API | ||
from friendlypins.section import Section | ||
from friendlypins.pin import Pin | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_board_sections(test_env): | ||
obj = API(test_env["key"]) | ||
board = obj.get_board_by_id(test_env["test_board"]["id"]) | ||
sections = list(board.sections) | ||
|
||
assert len(sections) == 1 | ||
assert isinstance(sections[0], Section) | ||
assert sections[0].id == test_env["test_section"]["id"] | ||
assert sections[0].title == test_env["test_section"]["title"] | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_section_pins(test_env): | ||
obj = API(test_env["key"]) | ||
section = obj.get_section_by_id(test_env["test_section"]["id"]) | ||
assert section is not None | ||
pins = list(section.pins) | ||
|
||
assert len(pins) == len(test_env["test_section"]["pins"]) | ||
for cur_pin in pins: | ||
assert isinstance(cur_pin, Pin) | ||
assert cur_pin.unique_id in test_env["test_section"]["pins"] | ||
test_env["test_section"]["pins"].remove(cur_pin.unique_id) |