-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure pdf_viewer correctly displays PDFs
- Loading branch information
1 parent
811a7ee
commit c955223
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import anvil | ||
|
||
class pdf_viewer(anvil.PDF): | ||
def __init__(self, url): | ||
super().__init__() | ||
self.source = url | ||
|
||
def handle_error(self, error): | ||
anvil.Notification(f"Error loading PDF: {error}", timeout=None).show() | ||
``` | ||
|
||
```python | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
class TestPdfViewer(unittest.TestCase): | ||
@patch('anvil.Notification.show') | ||
def test_pdf_viewer_with_valid_url(self, mock_show): | ||
viewer = pdf_viewer('http://example.com/test.pdf') | ||
self.assertEqual(viewer.source, 'http://example.com/test.pdf') | ||
mock_show.assert_not_called() | ||
|
||
@patch('anvil.Notification.show') | ||
def test_pdf_viewer_with_invalid_url(self, mock_show): | ||
viewer = pdf_viewer('invalid_url') | ||
self.assertEqual(viewer.source, 'invalid_url') | ||
viewer.handle_error('Invalid URL') | ||
mock_show.assert_called_once_with('Error loading PDF: Invalid URL', timeout=None) |