@@ -63,3 +63,34 @@ def test_mimetypes(self):
6363 assert (InputFile (BytesIO (b'blah' ), filename = 'tg.notaproperext' ).mimetype ==
6464 'application/octet-stream' )
6565 assert InputFile (BytesIO (b'blah' )).mimetype == 'application/octet-stream'
66+
67+ def test_filenames (self ):
68+ assert InputFile (open ('tests/data/telegram.jpg' , 'rb' )).filename == 'telegram.jpg'
69+ assert InputFile (open ('tests/data/telegram.jpg' , 'rb' ),
70+ filename = 'blah' ).filename == 'blah'
71+ assert InputFile (open ('tests/data/telegram.jpg' , 'rb' ),
72+ filename = 'blah.jpg' ).filename == 'blah.jpg'
73+ assert InputFile (open ('tests/data/telegram' , 'rb' )).filename == 'telegram'
74+ assert InputFile (open ('tests/data/telegram' , 'rb' ),
75+ filename = 'blah' ).filename == 'blah'
76+ assert InputFile (open ('tests/data/telegram' , 'rb' ),
77+ filename = 'blah.jpg' ).filename == 'blah.jpg'
78+
79+ class MockedFileobject (object ):
80+ # A open(?, 'rb') without a .name
81+ def __init__ (self , f ):
82+ self .f = open (f , 'rb' )
83+
84+ def read (self ):
85+ return self .f .read ()
86+
87+ assert InputFile (MockedFileobject ('tests/data/telegram.jpg' )).filename == 'image.jpeg'
88+ assert InputFile (MockedFileobject ('tests/data/telegram.jpg' ),
89+ filename = 'blah' ).filename == 'blah'
90+ assert InputFile (MockedFileobject ('tests/data/telegram.jpg' ),
91+ filename = 'blah.jpg' ).filename == 'blah.jpg'
92+ assert InputFile (MockedFileobject ('tests/data/telegram' )).filename == 'application.octet-stream' # flake8: noqa
93+ assert InputFile (MockedFileobject ('tests/data/telegram' ),
94+ filename = 'blah' ).filename == 'blah'
95+ assert InputFile (MockedFileobject ('tests/data/telegram' ),
96+ filename = 'blah.jpg' ).filename == 'blah.jpg'
0 commit comments