Skip to content

Commit b6bcc29

Browse files
committed
feat: get_blogs() test
1 parent dc5ae4d commit b6bcc29

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
requests
1+
requests
2+
pytest

src/hytale/http.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
def get(path: str, sub_domain: str = "", **params) -> dict | str:
2323
url = "https://" + sub_domain + BASE_URL + path
24-
25-
print(url)
26-
2724
try:
2825
response = _session.get(
2926
url,

tests/test_blogs.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import unittest
2+
from datetime import datetime
3+
from unittest.mock import patch
4+
5+
from hytale import BlogPostExcerpt, get_blogs
6+
7+
8+
class TestGetBlogs(unittest.TestCase):
9+
@patch("hytale.blogs.get")
10+
def test_get_blogs_with_mock(self, mock_get):
11+
mock_get.return_value = [
12+
{
13+
"_id": "123",
14+
"title": "Test Blog",
15+
"author": "Author",
16+
"featured": True,
17+
"tags": ["test", "hytale"],
18+
"publishedAt": "2025-12-19T12:00:00+00:00",
19+
"coverImage": {
20+
"_id": "cover123",
21+
"variants": ["blog_thumb", "blog_cover"],
22+
"s3Key": "abc.png",
23+
"mimeType": "image/png",
24+
"attached": True,
25+
"createdAt": "2025-12-19T12:00:00+00:00",
26+
"__v": 1,
27+
"contentId": "123",
28+
"contentType": "BlogPost",
29+
},
30+
"createdAt": "2025-12-19T12:00:00+00:00",
31+
"slug": "test-blog",
32+
"bodyExcerpt": "This is a test blog excerpt",
33+
}
34+
]
35+
36+
blogs = get_blogs(1)
37+
38+
assert isinstance(blogs, list)
39+
assert all(isinstance(blog, BlogPostExcerpt) for blog in blogs)
40+
41+
first_blog = blogs[0]
42+
assert first_blog.title == "Test Blog"
43+
assert first_blog.coverImage.s3Key == "abc.png"
44+
assert first_blog.bodyExcerpt == "This is a test blog excerpt"
45+
assert first_blog.publishedAt == datetime.fromisoformat(
46+
"2025-12-19T12:00:00+00:00"
47+
)
48+
assert first_blog.coverImage.createdAt == datetime.fromisoformat(
49+
"2025-12-19T12:00:00+00:00"
50+
)

0 commit comments

Comments
 (0)