Nekmo / telegram-upload

Compare 304f5f6 ... +3 ... ea2253d

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -19,12 +19,10 @@
Loading
19 19
        m.assert_called_once()
20 20
        m.return_value.send_files.assert_called_once()
21 21
22 -
    @patch('telegram_upload.management.Client')
23 -
    def test_failed(self, m):
22 +
    def test_missing_file(self):
24 23
        runner = CliRunner()
25 24
        result = runner.invoke(upload, ['missing_file.txt'])
26 25
        self.assertEqual(result.exit_code, 1)
27 -
        m.return_value.send_files.assert_not_called()
28 26
29 27
    @patch('telegram_upload.management.Client')
30 28
    def test_exclusive(self, m):

@@ -14,7 +14,7 @@
Loading
14 14
15 15
from telegram_upload.config import SESSION_FILE
16 16
from telegram_upload.exceptions import ThumbError, TelegramUploadDataLoss, TelegramUploadNoSpaceError, \
17 -
    TelegramProxyError, TelegramInvalidFile
17 +
    TelegramProxyError, TelegramInvalidFile, MissingFileError
18 18
from telegram_upload.files import get_file_attributes, get_file_thumb, File
19 19
from telethon.version import __version__ as telethon_version
20 20
from telethon import TelegramClient
@@ -106,7 +106,9 @@
Loading
106 106
107 107
    def send_files(self, entity, files, delete_on_success=False, print_file_id=False,
108 108
                   force_file=False, forward=(), caption=None, thumbnail=None):
109 +
        has_files = False
109 110
        for file in files:
111 +
            has_files = True
110 112
            if isinstance(file, File):
111 113
                name = file_name = file.file_name
112 114
                file_size = file.file_size
@@ -155,6 +157,8 @@
Loading
155 157
                click.echo('Deleting "{}"'.format(file))
156 158
                os.remove(file)
157 159
            self.forward_to(message, forward)
160 +
        if not has_files:
161 +
            raise MissingFileError('Files do not exist.')
158 162
159 163
    def find_files(self, entity):
160 164
        for message in self.iter_messages(entity):

@@ -19,6 +19,17 @@
Loading
19 19
MAX_FILE_SIZE = 2097152000
20 20
21 21
22 +
def is_valid_file(file, error_logger=None):
23 +
    error_message = None
24 +
    if not os.path.lexists(file):
25 +
        error_message = 'File "{}" does not exist.'.format(file)
26 +
    elif not os.path.getsize(file):
27 +
        error_message = 'File "{}" is empty.'.format(file)
28 +
    if error_message and error_logger is not None:
29 +
        error_logger(error_message)
30 +
    return error_message is None
31 +
32 +
22 33
def get_file_mime(file):
23 34
    return (mimetypes.guess_type(file)[0] or ('')).split('/')[0]
24 35

@@ -28,6 +28,10 @@
Loading
28 28
        return msg
29 29
30 30
31 +
class MissingFileError(TelegramUploadError):
32 +
    pass
33 +
34 +
31 35
class TelegramInvalidFile(TelegramUploadError):
32 36
    error_code = 3
33 37

@@ -6,7 +6,7 @@
Loading
6 6
from telegram_upload.client import Client
7 7
from telegram_upload.config import default_config, CONFIG_FILE
8 8
from telegram_upload.exceptions import catch
9 -
from telegram_upload.files import NoDirectoriesFiles, RecursiveFiles, NoLargeFiles, SplitFiles
9 +
from telegram_upload.files import NoDirectoriesFiles, RecursiveFiles, NoLargeFiles, SplitFiles, is_valid_file
10 10
11 11
DIRECTORY_MODES = {
12 12
    'fail': NoDirectoriesFiles,
@@ -84,6 +84,7 @@
Loading
84 84
    """
85 85
    client = Client(config or default_config(), proxy=proxy)
86 86
    client.start()
87 +
    files = filter(lambda file: is_valid_file(file, lambda message: click.echo(message, err=True)), files)
87 88
    files = DIRECTORY_MODES[directories](files)
88 89
    if directories == 'fail':
89 90
        # Validate now

Learn more Showing 9 files with coverage changes found.

Changes in telegram_upload/management.py
-3
Loading file...
Changes in telegram_upload/files.py
-4
Loading file...
Changes in tests/test_video.py
-5
Loading file...
Changes in tests/test_exceptions.py
-1
Loading file...
Changes in tests/test_management.py
-2
Loading file...
Changes in tests/test_utils.py
-3
Loading file...
Changes in tests/test_config.py
-2
Loading file...
Changes in tests/test_files.py
-9
Loading file...
Changes in tests/test_client.py
-1
Loading file...
Files Coverage
telegram_upload -0.68% 87.21%
tests 100.00%
Project Totals (17 files) 91.92%
Loading