File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -448,15 +448,25 @@ class Attachment(_Resource):
448448 query_one = '/attachments/{0}.json'
449449
450450 def __str__ (self ):
451- return to_string (self .filename )
451+ try :
452+ return to_string (self .filename )
453+ except ResourceAttrError :
454+ return str (self .id )
452455
453456 def __repr__ (self ):
454- return '<{0}.{1} #{2} "{3}">' .format (
455- self .__class__ .__module__ ,
456- self .__class__ .__name__ ,
457- self .id ,
458- to_string (self .filename )
459- )
457+ try :
458+ return '<{0}.{1} #{2} "{3}">' .format (
459+ self .__class__ .__module__ ,
460+ self .__class__ .__name__ ,
461+ self .id ,
462+ to_string (self .filename )
463+ )
464+ except ResourceAttrError :
465+ return '<{0}.{1} #{2}>' .format (
466+ self .__class__ .__module__ ,
467+ self .__class__ .__name__ ,
468+ self .id
469+ )
460470
461471
462472class IssueJournal (_Resource ):
Original file line number Diff line number Diff line change @@ -566,10 +566,22 @@ def test_attachment_custom_str(self):
566566 self .response .json = json_response (responses ['attachment' ]['get' ])
567567 self .assertEqual (str (self .redmine .attachment .get (1 )), 'foo.jpg' )
568568
569+ def test_attachment_custom_str_without_filename (self ):
570+ self .response .json = json_response (responses ['attachment' ]['get' ])
571+ attachment = self .redmine .attachment .get (1 )
572+ del attachment ['_attributes' ]['filename' ]
573+ self .assertEqual (str (attachment ), '1' )
574+
569575 def test_attachment_custom_repr (self ):
570576 self .response .json = json_response (responses ['attachment' ]['get' ])
571577 self .assertEqual (repr (self .redmine .attachment .get (1 )), '<redmine.resources.Attachment #1 "foo.jpg">' )
572578
579+ def test_attachment_custom_repr_without_subject (self ):
580+ self .response .json = json_response (responses ['attachment' ]['get' ])
581+ attachment = self .redmine .attachment .get (1 )
582+ del attachment ['_attributes' ]['filename' ]
583+ self .assertEqual (repr (attachment ), '<redmine.resources.Attachment #1>' )
584+
573585 def test_attachment_url (self ):
574586 self .response .json = json_response (responses ['attachment' ]['get' ])
575587 self .assertEqual (self .redmine .attachment .get (1 ).url , '{0}/attachments/1' .format (self .url ))
You can’t perform that action at this time.
0 commit comments