|
1 | 1 | """ |
2 | | -Tests for Article class. |
| 2 | +Tests for model classes. |
3 | 3 | """ |
4 | 4 |
|
5 | | -from instaparser.article import Article |
| 5 | +from instaparser.models import PDF, Article, Summary |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class TestArticle: |
@@ -60,3 +60,60 @@ def test_str_returns_empty_when_no_body(self): |
60 | 60 | """Test __str__ returns empty string when body is None.""" |
61 | 61 | article = Article() |
62 | 62 | assert str(article) == "" |
| 63 | + |
| 64 | + |
| 65 | +class TestPDF: |
| 66 | + """Tests for PDF class.""" |
| 67 | + |
| 68 | + def test_inherits_from_article(self): |
| 69 | + """Test that PDF inherits from Article.""" |
| 70 | + assert issubclass(PDF, Article) |
| 71 | + |
| 72 | + def test_forces_is_rtl_false(self): |
| 73 | + """Test that PDF always sets is_rtl to False, even if True is passed.""" |
| 74 | + pdf = PDF(is_rtl=True) |
| 75 | + assert pdf.is_rtl is False |
| 76 | + |
| 77 | + def test_forces_videos_empty(self): |
| 78 | + """Test that PDF always sets videos to [], even if videos are passed.""" |
| 79 | + pdf = PDF(videos=["https://example.com/video.mp4"]) |
| 80 | + assert pdf.videos == [] |
| 81 | + |
| 82 | + def test_repr(self): |
| 83 | + """Test __repr__ includes class name, url, and title.""" |
| 84 | + pdf = PDF(url="https://example.com/doc.pdf", title="Test PDF") |
| 85 | + repr_str = repr(pdf) |
| 86 | + assert "PDF" in repr_str |
| 87 | + assert "https://example.com/doc.pdf" in repr_str |
| 88 | + assert "Test PDF" in repr_str |
| 89 | + |
| 90 | + def test_str_returns_body(self): |
| 91 | + """Test that __str__ is inherited from Article and returns body.""" |
| 92 | + pdf = PDF(html="<p>Content</p>") |
| 93 | + assert str(pdf) == "<p>Content</p>" |
| 94 | + |
| 95 | + |
| 96 | +class TestSummary: |
| 97 | + """Tests for Summary class.""" |
| 98 | + |
| 99 | + def test_repr_truncates_long_overview(self): |
| 100 | + """Test __repr__ truncates overview longer than 50 characters.""" |
| 101 | + summary = Summary( |
| 102 | + key_sentences=["Sentence 1", "Sentence 2"], |
| 103 | + overview="This is a test overview that is longer than 50 characters for truncation", |
| 104 | + ) |
| 105 | + repr_str = repr(summary) |
| 106 | + assert "..." in repr_str |
| 107 | + assert "key_sentences=2" in repr_str |
| 108 | + |
| 109 | + def test_repr_does_not_truncate_short_overview(self): |
| 110 | + """Test __repr__ does not add ellipsis for short overview.""" |
| 111 | + summary = Summary(key_sentences=["Sentence"], overview="Short") |
| 112 | + repr_str = repr(summary) |
| 113 | + assert "..." not in repr_str |
| 114 | + assert "key_sentences=1" in repr_str |
| 115 | + |
| 116 | + def test_str_returns_overview(self): |
| 117 | + """Test __str__ returns the overview.""" |
| 118 | + summary = Summary(key_sentences=["Sentence"], overview="The overview") |
| 119 | + assert str(summary) == "The overview" |
0 commit comments