Skip to content

Commit

Permalink
Issue #61: [FEATURE] Upload as album (fix tests).
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Mar 3, 2021
1 parent 6c51f99 commit 3833db7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions telegram_upload/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def file_attributes(self):
if self.force_file:
return [DocumentAttributeFilename(self.file_name)]
else:
return get_file_attributes(self.path) or self.path
return get_file_attributes(self.path)


class SplitFile(File, FileIO):
Expand All @@ -209,7 +209,7 @@ def readall(self) -> bytes:

@property
def file_name(self):
return self.path
return self._name

@property
def file_size(self):
Expand Down
9 changes: 6 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from telegram_upload.client import Client, parse_proxy_string, phone_match
from telegram_upload.exceptions import TelegramUploadDataLoss, TelegramUploadNoSpaceError, TelegramProxyError
from telegram_upload.files import File

CONFIG_DATA = {'api_hash': '', 'api_id': ''}

Expand Down Expand Up @@ -69,17 +70,19 @@ def setUp(self, m1) -> None:

def test_send_files(self):
entity = 'foo'
self.client.send_files(entity, [self.upload_file_path])
file = File(self.upload_file_path)
self.client.send_files(entity, [file])
self.client.send_file.assert_called_once_with(
entity, self.upload_file_path, thumb=None, file_size=None,
entity, file, thumb=None, file_size=file.file_size,
caption=os.path.basename(self.upload_file_path).split('.')[0], force_document=False,
progress_callback=AnyArg(), attributes=[],
)

def test_send_files_data_loss(self):
file = File(self.upload_file_path)
self.client.send_file.return_value.media.document.size = 200
with self.assertRaises(TelegramUploadDataLoss):
self.client.send_files('foo', [self.upload_file_path])
self.client.send_files('foo', [file])

def test_download_files(self):
m = Mock()
Expand Down
10 changes: 6 additions & 4 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def test_directory(self, m):

class TestNoLargeFiles(unittest.TestCase):
@patch('telegram_upload.files.os.path.getsize', return_value=MAX_FILE_SIZE - 1)
def test_small_file(self, m):
self.assertEqual(list(NoLargeFiles(['foo'])), ['foo'])
@patch('telegram_upload.files.File')
def test_small_file(self, m1, m2):
self.assertEqual(len(list(NoLargeFiles(['foo']))), 1)

@patch('telegram_upload.files.os.path.getsize', return_value=MAX_FILE_SIZE + 1)
def test_big_file(self, m):
Expand All @@ -84,8 +85,9 @@ def test_file(self):

class TestSplitFiles(unittest.TestCase):
@patch('telegram_upload.files.os.path.getsize', return_value=MAX_FILE_SIZE - 1)
def test_small_file(self, m):
self.assertEqual(list(SplitFiles(['foo'])), ['foo'])
@patch('telegram_upload.files.File')
def test_small_file(self, m1, m2):
self.assertEqual(len(list(SplitFiles(['foo']))), 1)

@patch('telegram_upload.files.os.path.getsize', return_value=MAX_FILE_SIZE + 1000)
@patch('telegram_upload.files.SplitFile.__init__', return_value=None)
Expand Down

0 comments on commit 3833db7

Please sign in to comment.