|
| 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