Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sa-github-api committed Oct 9, 2024
1 parent bdf8424 commit 97a2713
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions release-controller/mock_discourse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from pydiscourse import DiscourseClient


Expand All @@ -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 [
Expand All @@ -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."""
Expand All @@ -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)
]
}
}
Expand Down

0 comments on commit 97a2713

Please sign in to comment.