-
Notifications
You must be signed in to change notification settings - Fork 337
Include attachments in TSV and JSON formatted output #847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shanemcd
wants to merge
3
commits into
insanum:main
Choose a base branch
from
shanemcd:attachments-in-tsv-and-json
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+276
−2
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,219 @@ | ||
| """Tests for detail handlers.""" | ||
|
|
||
| import pytest | ||
| from gcalcli.details import Attachments | ||
| from gcalcli.exceptions import ReadonlyCheckError | ||
|
|
||
|
|
||
| class TestAttachmentsHandler: | ||
| """Tests for Attachments handler.""" | ||
|
|
||
| def test_get_with_no_attachments(self): | ||
| """Test get() returns empty string for events without attachments.""" | ||
| event = {} | ||
| result = Attachments.get(event) | ||
| assert result == [''] | ||
|
|
||
| def test_get_with_single_attachment(self): | ||
| """Test get() returns formatted string for single attachment.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Notes by Gemini', | ||
| 'fileUrl': 'https://docs.google.com/document/d/123/edit' | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.get(event) | ||
| assert result == ['Notes by Gemini|https://docs.google.com/document/d/123/edit'] | ||
|
|
||
| def test_get_with_multiple_attachments(self): | ||
| """Test get() returns formatted string for multiple attachments.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Document 1', | ||
| 'fileUrl': 'https://docs.google.com/document/d/123/edit' | ||
| }, | ||
| { | ||
| 'title': 'Document 2', | ||
| 'fileUrl': 'https://docs.google.com/document/d/456/edit' | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.get(event) | ||
| expected = ( | ||
| 'Document 1|https://docs.google.com/document/d/123/edit\f' | ||
| 'Document 2|https://docs.google.com/document/d/456/edit' | ||
| ) | ||
| assert result == [expected] | ||
|
|
||
| def test_get_with_missing_fields(self): | ||
| """Test get() handles missing title/fileUrl fields gracefully.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Document 1' | ||
| # missing fileUrl | ||
| }, | ||
| { | ||
| 'fileUrl': 'https://docs.google.com/document/d/456/edit' | ||
| # missing title | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.get(event) | ||
| expected = 'Document 1|\f|https://docs.google.com/document/d/456/edit' | ||
| assert result == [expected] | ||
|
|
||
| def test_data_with_no_attachments(self): | ||
| """Test data() returns empty list for events without attachments.""" | ||
| event = {} | ||
| result = Attachments.data(event) | ||
| assert result == [] | ||
|
|
||
| def test_data_with_single_attachment(self): | ||
| """Test data() returns properly formatted dict for single attachment.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Notes by Gemini', | ||
| 'fileUrl': 'https://docs.google.com/document/d/123/edit' | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.data(event) | ||
| expected = [ | ||
| { | ||
| 'attachment_title': 'Notes by Gemini', | ||
| 'attachment_url': 'https://docs.google.com/document/d/123/edit' | ||
| } | ||
| ] | ||
| assert result == expected | ||
|
|
||
| def test_data_with_multiple_attachments(self): | ||
| """Test data() returns formatted dict list for attachments.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Document 1', | ||
| 'fileUrl': 'https://docs.google.com/document/d/123/edit' | ||
| }, | ||
| { | ||
| 'title': 'Document 2', | ||
| 'fileUrl': 'https://docs.google.com/document/d/456/edit' | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.data(event) | ||
| expected = [ | ||
| { | ||
| 'attachment_title': 'Document 1', | ||
| 'attachment_url': 'https://docs.google.com/document/d/123/edit' | ||
| }, | ||
| { | ||
| 'attachment_title': 'Document 2', | ||
| 'attachment_url': 'https://docs.google.com/document/d/456/edit' | ||
| } | ||
| ] | ||
| assert result == expected | ||
|
|
||
| def test_data_with_missing_fields(self): | ||
| """Test data() handles missing title/fileUrl fields gracefully.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Document 1' | ||
| # missing fileUrl | ||
| }, | ||
| { | ||
| 'fileUrl': 'https://docs.google.com/document/d/456/edit' | ||
| # missing title | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.data(event) | ||
| expected = [ | ||
| { | ||
| 'attachment_title': 'Document 1', | ||
| 'attachment_url': '' | ||
| }, | ||
| { | ||
| 'attachment_title': '', | ||
| 'attachment_url': 'https://docs.google.com/document/d/456/edit' | ||
| } | ||
| ] | ||
| assert result == expected | ||
|
|
||
| def test_get_with_semicolons(self): | ||
| """Test get() handles semicolons in titles and URLs correctly.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Meeting Notes; Q4 2025', | ||
| 'fileUrl': 'https://example.com/doc;jsessionid=ABC123' | ||
| }, | ||
| { | ||
| 'title': 'Agenda', | ||
| 'fileUrl': 'https://docs.google.com/document/d/456/edit' | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.get(event) | ||
| # Semicolons should be preserved, form feed used as separator | ||
| expected = 'Meeting Notes; Q4 2025|https://example.com/doc;jsessionid=ABC123\fAgenda|https://docs.google.com/document/d/456/edit' | ||
| assert result == [expected] | ||
|
|
||
| def test_get_with_form_feed_in_data(self): | ||
| """Test get() escapes existing form feed characters in data.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Document\fwith\fformfeeds', | ||
| 'fileUrl': 'https://example.com/doc' | ||
| } | ||
| ] | ||
| } | ||
| result = Attachments.get(event) | ||
| # Form feeds in data should be escaped as r'\f' | ||
| expected = r'Document\fwith\fformfeeds|https://example.com/doc' | ||
| assert result == [expected] | ||
|
|
||
| def test_fieldnames(self): | ||
| """Test fieldnames are correctly defined.""" | ||
| assert Attachments.fieldnames == ['attachments'] | ||
|
|
||
| def test_patch_with_unchanged_value(self): | ||
| """Test patch doesn't error when value hasn't changed.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Notes by Gemini', | ||
| 'fileUrl': 'https://docs.google.com/document/d/123/edit' | ||
| } | ||
| ] | ||
| } | ||
| current_value = 'Notes by Gemini|https://docs.google.com/document/d/123/edit' | ||
| # Should not raise an error when value hasn't changed | ||
| Attachments.patch(None, event, 'attachments', current_value) | ||
|
|
||
| def test_patch_with_changed_value(self): | ||
| """Test patch raises error when trying to change value.""" | ||
| event = { | ||
| 'attachments': [ | ||
| { | ||
| 'title': 'Notes by Gemini', | ||
| 'fileUrl': 'https://docs.google.com/document/d/123/edit' | ||
| } | ||
| ] | ||
| } | ||
| new_value = 'Different|https://example.com' | ||
| # Should raise ReadonlyCheckError when trying to change value | ||
| with pytest.raises(ReadonlyCheckError): | ||
| Attachments.patch(None, event, 'attachments', new_value) | ||
|
|
||
| def test_patch_with_no_attachments(self): | ||
| """Test patch handles events without attachments.""" | ||
| event = {} | ||
| # Should not raise an error for empty value | ||
| Attachments.patch(None, event, 'attachments', '') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.