Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyOTRS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Som Connexió
OTRS
PyOTRS
Commits
e2bff680
Commit
e2bff680
authored
6 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
fix #18 by decoding bytes to str for Attachment.Content
parent
98c54617
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.rst
+1
-0
1 addition, 0 deletions
CHANGELOG.rst
README.rst
+5
-0
5 additions, 0 deletions
README.rst
pyotrs/lib.py
+1
-1
1 addition, 1 deletion
pyotrs/lib.py
tests/test_attachment.py
+5
-0
5 additions, 0 deletions
tests/test_attachment.py
with
12 additions
and
1 deletion
CHANGELOG.rst
+
1
−
0
View file @
e2bff680
...
...
@@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
0.5.x - 2019-xx-yy (unreleased)
--------------------------------
- fix #18: Attachment.create_from_file did not decode "Content"
0.4.1 - 2019-03-09 - Beta
-------------------------
...
...
This diff is collapsed.
Click to expand it.
README.rst
+
5
−
0
View file @
e2bff680
...
...
@@ -168,6 +168,11 @@ Update Tickets
u'TicketID': u'1',
u'TicketNumber': u'2010080210123456'}
>>> att = Attachment.create_from_file("./test_data/asd.txt")
>>> client.ticket_update(ticket_id=1, article=my_article, attachments=[att])
{'ArticleID': '7927', 'TicketID': '1', 'TicketNumber': '2010080210123456'}
>>> df = DynamicField("ExternalTicket", "1234")
>>> client.ticket_update(1, dynamic_fields=[df])
{u'TicketID': u'1', u'TicketNumber': u'2010080210123456'}
...
...
This diff is collapsed.
Click to expand it.
pyotrs/lib.py
+
1
−
1
View file @
e2bff680
...
...
@@ -360,7 +360,7 @@ class Attachment(object):
content_type
=
mimetypes
.
guess_type
(
file_path
)[
0
]
if
not
content_type
:
content_type
=
"
application/octet-stream
"
return
Attachment
({
'
Content
'
:
base64
.
b64encode
(
content
),
return
Attachment
({
'
Content
'
:
base64
.
b64encode
(
content
)
.
decode
(
'
utf-8
'
)
,
'
ContentType
'
:
content_type
,
'
Filename
'
:
os
.
path
.
basename
(
file_path
)})
...
...
This diff is collapsed.
Click to expand it.
tests/test_attachment.py
+
5
−
0
View file @
e2bff680
...
...
@@ -12,6 +12,8 @@ import unittest2 as unittest
import
mock
# from mock import MagicMock, patch
import
json
current_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
sys
.
path
.
append
(
os
.
path
.
join
(
current_path
,
os
.
pardir
))
...
...
@@ -66,6 +68,9 @@ class AttachmentTests(unittest.TestCase):
self
.
assertIsInstance
(
att
,
Attachment
)
self
.
assertEqual
(
att
.
ContentType
,
"
text/plain
"
)
# Catches: TypeError: b'...' is not JSON serializable
self
.
assertEqual
(
json
.
dumps
(
att
.
Content
),
'"
InRoaXMgaXMgdGhlIGNvbnRlbnQgb2YgYSBmaWxlISIK
"'
)
def
test_attachment_create_from_file_no_file_ext
(
self
):
"""
create_from_file test - no file ending -> mime needs to default
"""
att
=
Attachment
.
create_from_file
(
os
.
path
.
join
(
current_path
,
"
fixtures/b_file
"
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment