Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_prepend_kind(self):
kind = "kind"
uuid1 = str(uuid.uuid1())
prepended_id = kind + "_" + uuid1
assert prepend_kind(uuid1, kind) == prepended_id
assert prepend_kind(prepended_id, kind) == prepended_id
def test_prepend_kind(self):
kind = "kind"
uuid1 = str(uuid.uuid1())
prepended_id = kind + "_" + uuid1
assert prepend_kind(uuid1, kind) == prepended_id
assert prepend_kind(prepended_id, kind) == prepended_id
def fullname(self):
return prepend_kind(self._data[self.ID_ATTRIBUTE], self.kind) if self.kind else self._data[self.ID_ATTRIBUTE]
Get a `Submission` object based on its ID or URL.
Parameters
----------
id: str
The ID of a submission (with or without kind).
url: str
The URL of a submission.
Returns
-------
submission: Submission
The requested submission.
"""
if id != "":
async for link in self.info(prepend_kind(id, self.link_kind)):
return link
elif url != "":
async for link in self.info(url=url):
return link
return None
Returns
-------
self: Comment
The ``Comment`` model with updated data.
"""
if ("link_id" in self._data and "id" in self._data and "subreddit" in self._data) or "permalink" in self._data:
permalink = self._data["permalink"] if "permalink" in self._data else API_PATH["comment"].format(
sub=self._data["subreddit"], submission=self._data["link_id"].replace(self._reddit.link_kind + "_", ""),
id=self._data["id"])
resp = await self._reddit.get_request(permalink)
from .submission import Submission
self._submission = Submission(self._reddit, resp[0]["data"]["children"][0]["data"])
return self._update(resp[1]["data"]["children"][0]["data"])
elif "id" in self._data:
resp = await self._reddit.get_request(API_PATH["info"],
id=prepend_kind(self._data["id"], self._reddit.comment_kind))
return self._update(resp["data"]["children"][0]["data"])
else:
raise ValueError(f"No data available to make request URL: {self._data}")
async def fetch(self):
"""
Fetch this item's information from a suitable API endpoint.
Returns
-------
self: Submission
The updated model.
"""
if "subreddit" in self._data and "id" in self._data:
resp = await self._reddit.get_request(
API_PATH["submission"].format(sub=self._data["subreddit"], id=self._data["id"]))
self._update(resp)
elif "id" in self._data:
resp = await self._reddit.get_request(API_PATH["info"],
id=prepend_kind(self._data["id"], self._reddit.link_kind))
self._update(resp["data"]["children"][0]["data"])
return self