Skip to content

Commit

Permalink
fix: ensure pdf_viewer correctly displays PDFs
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Oct 11, 2023
1 parent 811a7ee commit c955223
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pdf_viewer/pdf_viewer.py
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)

0 comments on commit c955223

Please sign in to comment.