diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index f0e74b5..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,113 +0,0 @@ -version: 2 - -jobs: - test-3.6: - docker: - - image: circleci/python:3.6.9 - environment: - CIRCLE_ARTIFACTS: /tmp/circleci-artifacts - CIRCLE_TEST_REPORTS: /tmp/circleci-test-results - LOG_DIR: ${CIRCLE_ARTIFACTS}/testresults/ - steps: - - checkout - - run: - name: Get setuptools - shell: /bin/bash - command: sudo pip install --upgrade pip setuptools codecov - - run: - name: Install dependencies - shell: /bin/bash - command: sudo make deps - - run: - name: Static Type Check - Mypy - shell: /bin/bash - command: sudo make static_type_check - - run: - name: Code Check - Pylint - shell: /bin/bash - command: sudo make pylint - - run: - name: Run test - shell: /bin/bash - command: | - sudo make -e test - codecov - - store_artifacts: - path: /tmp/circleci-artifacts - - test-3.7: - docker: - - image: circleci/python:3.7.8 - environment: - CIRCLE_ARTIFACTS: /tmp/circleci-artifacts - CIRCLE_TEST_REPORTS: /tmp/circleci-test-results - LOG_DIR: ${CIRCLE_ARTIFACTS}/testresults/ - steps: - - checkout - - run: - name: Get setuptools - shell: /bin/bash - command: sudo pip install --upgrade pip setuptools codecov - - run: - name: Install dependencies - shell: /bin/bash - command: sudo make deps - - run: - name: Static Type Check - Mypy - shell: /bin/bash - command: sudo make static_type_check - - run: - name: Code Check - Pylint - shell: /bin/bash - command: sudo make pylint - - run: - name: Run test - shell: /bin/bash - command: | - sudo make -e test - codecov - - store_artifacts: - path: /tmp/circleci-artifacts - - test-3.8: - docker: - - image: circleci/python:3.8.3 - environment: - CIRCLE_ARTIFACTS: /tmp/circleci-artifacts - CIRCLE_TEST_REPORTS: /tmp/circleci-test-results - LOG_DIR: ${CIRCLE_ARTIFACTS}/testresults/ - steps: - - checkout - - run: - name: Get setuptools - shell: /bin/bash - command: sudo pip install --upgrade pip setuptools codecov - - run: - name: Install dependencies - shell: /bin/bash - command: sudo make deps - - run: - name: Static Type Check - Mypy - shell: /bin/bash - command: sudo make static_type_check - - run: - name: Code Check - Pylint - shell: /bin/bash - command: sudo make pylint - - run: - name: Run test - shell: /bin/bash - command: | - sudo make -e test - codecov - - store_artifacts: - path: /tmp/circleci-artifacts - - -workflows: - version: 2 - tests: - jobs: - - test-3.6 - - test-3.7 - - test-3.8 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..4fe3db2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,34 @@ +name: Unittest + +on: [push] + +jobs: + build: + + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: [ '3.6', '3.7', '3.8'] + name: Test - Python ${{ matrix.python-version }} on ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Get setuptools + run: pip install --upgrade pip setuptools codecov + - name: Install dependencies + run: make deps + - name: Code Check - Pylint + run: make pylint + - name: Static Type Check - Mypy + run: make static_type_check + - name: Test with pytest + run: | + make -e test + codecov + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index 3c4886a..7af96e2 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@

Telegram Media Downloader

-Build Status +Unittest Coverage Status License: MIT Code style: black

- +![Unittest]() ### Overview: Download all media files from a conversation or a channel that you are a part of from telegram. A meta of last read/downloaded message is stored in the config file so that in such a way it won't download the same media file again. diff --git a/media_downloader.py b/media_downloader.py index c68e4ed..f3b0bcf 100644 --- a/media_downloader.py +++ b/media_downloader.py @@ -5,8 +5,8 @@ from typing import List, Tuple, Optional from datetime import datetime as dt import asyncio -import yaml import pyrogram +import yaml logging.basicConfig(level=logging.INFO) diff --git a/tests/test_media_downloader.py b/tests/test_media_downloader.py index 02bd848..0870e3b 100644 --- a/tests/test_media_downloader.py +++ b/tests/test_media_downloader.py @@ -2,6 +2,7 @@ import os import copy import logging +import platform import unittest import mock @@ -16,7 +17,9 @@ from media_downloader import ( process_messages, ) -MOCK_DIR = "/root/project" +MOCK_DIR: str = "/root/project" +if platform.system() == "Windows": + MOCK_DIR = "\\root\\project" MOCK_CONF = { "api_id": 123, "api_hash": "hasw5Tgawsuj67", @@ -27,6 +30,13 @@ MOCK_CONF = { } +def platform_generic_path(_path: str) -> str: + platform_specific_path: str = _path + if platform.system() == "Windows": + platform_specific_path = platform_specific_path.replace("/", "\\") + return platform_specific_path + + class MockMessage: def __init__(self, **kwargs): self.message_id = kwargs.get("id") @@ -130,9 +140,9 @@ class MockClient: async def download_media(self, *args, **kwargs): assert "AwADBQADbwAD2oTRVeHe5eXRFftfAg", args[0] - assert "/root/project/voice/voice_2019-07-25T14:53:50.ogg", kwargs[ - "file_name" - ] + assert platform_generic_path( + "/root/project/voice/voice_2019-07-25T14:53:50.ogg" + ), kwargs["file_name"] return kwargs["file_name"] @@ -160,7 +170,9 @@ class MediaDownloaderTestCase(unittest.TestCase): self.assertEqual( ( "AwADBQADbwAD2oTRVeHe5eXRFftfAg", - "/root/project/voice/voice_2019-07-25T14:53:50.ogg", + platform_generic_path( + "/root/project/voice/voice_2019-07-25T14:53:50.ogg" + ), "ogg", ), result, @@ -178,7 +190,11 @@ class MediaDownloaderTestCase(unittest.TestCase): async_get_media_meta(message.photo, "photo") ) self.assertEqual( - ("AgADBQAD5KkxG_FPQValJzQsJPyzhHcC", "/root/project/photo/", None), + ( + "AgADBQAD5KkxG_FPQValJzQsJPyzhHcC", + platform_generic_path("/root/project/photo/"), + None, + ), result, ) @@ -198,7 +214,9 @@ class MediaDownloaderTestCase(unittest.TestCase): self.assertEqual( ( "AQADAgADq7LfMgAEIdy5DwAE4w4AAwI", - "/root/project/document/sample_document.pdf", + platform_generic_path( + "/root/project/document/sample_document.pdf" + ), "pdf", ), result, @@ -220,7 +238,7 @@ class MediaDownloaderTestCase(unittest.TestCase): self.assertEqual( ( "AQADAgADq7LfMgAEIdy5DwAE5Q4AAgEC", - "/root/project/audio/sample_audio.mp3", + platform_generic_path("/root/project/audio/sample_audio.mp3"), "mp3", ), result, @@ -239,7 +257,11 @@ class MediaDownloaderTestCase(unittest.TestCase): async_get_media_meta(message.video, "video") ) self.assertEqual( - ("CQADBQADeQIAAlL60FUCNMBdK8OjlAI", "/root/project/video/", "mp4"), + ( + "CQADBQADeQIAAlL60FUCNMBdK8OjlAI", + platform_generic_path("/root/project/video/"), + "mp4", + ), result, )