diff --git a/release-controller/mock_discourse.py b/release-controller/mock_discourse.py index d9efa64a1..5f51231f2 100644 --- a/release-controller/mock_discourse.py +++ b/release-controller/mock_discourse.py @@ -1,3 +1,4 @@ +import re from pydiscourse import DiscourseClient @@ -13,6 +14,18 @@ def __init__(self): self.api_key = "test_api_key" self.timeout = 10 + def _get(self, path, **kwargs): + if not re.search(r"/t/(\d+).json", path): + return super()._get(path, **kwargs) + id = re.search(r"/t/(\d+).json", path).group(1) # type: ignore + + return { + "raw": "bogus text", + "can_edit": True, + "posts_count": 1, + "id": id, + } | self.topic_posts(topic_id=id) + def categories(self, **kwargs): # pylint: disable=unused-argument """Return a list of categories.""" return [ @@ -33,7 +46,10 @@ def categories(self, **kwargs): # pylint: disable=unused-argument def topics_by(self, _: str): """Return a list of topics.""" - return [{"id": i + 1} | t for i, t in enumerate(self.created_topics)] + return [ + {"id": i + 1, "posts_count": 1} | t + for i, t in enumerate(self.created_topics) + ] def topic_posts(self, topic_id: str): """Return a list of posts in a topic.""" @@ -44,7 +60,7 @@ def topic_posts(self, topic_id: str): for p in [ {"id": i + 1} | p for i, p in enumerate(self.created_posts) ] - if p["topic_id"] == topic_id + if str(p["topic_id"]) == str(topic_id) ] } }