Skip to content

Commit

Permalink
Transform project into module
Browse files Browse the repository at this point in the history
Add codecov action
  • Loading branch information
fabiosangregorio committed Apr 11, 2020
1 parent 9de902a commit 9df08d2
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 65 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@master

- name: Git-Crypt Unlock
- name: Unlock git-crypt files
uses: zemuldo/git-crypt-unlock@master
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
Expand All @@ -38,9 +38,13 @@ jobs:
- name: Install dependencies
run: pip install -r requirements.txt

- name: Run tests
- name: Run tests and generate report
run: |
cd telereddit
python -m unittest
pip install coverage
coverage run -m unittest
coverage xml
env:
TELEREDDIT_MACHINE: 'GITHUB'
TELEREDDIT_MACHINE: 'GITHUB'

- name: Upload reports to codecov.io
uses: codecov/codecov-action@v1
1 change: 1 addition & 0 deletions telereddit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 5 additions & 0 deletions telereddit/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import telereddit.telereddit as telereddit


if __name__ == "__main__":
telereddit.main()
4 changes: 2 additions & 2 deletions telereddit/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Dynamic environment secret configuration
env_key = os.environ.get('TELEREDDIT_MACHINE')
if env_key is not None:
secret = importlib.import_module(f'config.secret_{env_key.lower()}').secret_config
secret = importlib.import_module(f'telereddit.config.secret_{env_key.lower()}').secret_config
else:
secret = importlib.import_module('config.secret_generic').secret_config
secret = importlib.import_module('telereddit.config.secret_generic').secret_config


def _edit_keyboard(edit_text):
Expand Down
Binary file modified telereddit/config/secret_dev.py
Binary file not shown.
2 changes: 1 addition & 1 deletion telereddit/config/secret_generic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from config.secret import Secret
from telereddit.config.secret import Secret


secret_config = Secret(
Expand Down
Binary file modified telereddit/config/secret_github.py
Binary file not shown.
Binary file modified telereddit/config/secret_prod.py
Binary file not shown.
2 changes: 1 addition & 1 deletion telereddit/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import requests

from config.config import MAX_TITLE_LENGTH
from telereddit.config.config import MAX_TITLE_LENGTH


def get_random_post_url(subreddit):
Expand Down
12 changes: 5 additions & 7 deletions telereddit/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

from telegram import InputMediaPhoto, InputMediaVideo, InputMediaDocument
from sentry_sdk import capture_exception
from config.config import MAX_TRIES, EDIT_KEYBOARD, EDIT_FAILED_KEYBOARD, NO_EDIT_KEYBOARD

import reddit
import helpers

from media import ContentType

from exceptions import SubredditError, TeleredditError, MediaTooBigError, PostSendError
from telereddit.config.config import MAX_TRIES, EDIT_KEYBOARD, EDIT_FAILED_KEYBOARD, NO_EDIT_KEYBOARD
import telereddit.reddit as reddit
import telereddit.helpers as helpers
from telereddit.media import ContentType
from telereddit.exceptions import SubredditError, TeleredditError, MediaTooBigError, PostSendError


class Linker:
Expand Down
2 changes: 1 addition & 1 deletion telereddit/media.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from content_type import ContentType
from telereddit.content_type import ContentType


class Media:
Expand Down
2 changes: 1 addition & 1 deletion telereddit/post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from content_type import ContentType
from telereddit.content_type import ContentType


class Post():
Expand Down
14 changes: 6 additions & 8 deletions telereddit/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

from sentry_sdk import capture_exception

import helpers
from config.config import MAX_POST_LENGTH, secret

from post import Post
from content_type import ContentType
from exceptions import RequestError, SubredditPrivateError, SubredditDoesntExistError, PostRetrievalError

from services.services_wrapper import ServicesWrapper
import telereddit.helpers as helpers
from telereddit.config.config import MAX_POST_LENGTH, secret
from telereddit.post import Post
from telereddit.content_type import ContentType
from telereddit.exceptions import RequestError, SubredditPrivateError, SubredditDoesntExistError, PostRetrievalError
from telereddit.services.services_wrapper import ServicesWrapper


def _get_json(post_url):
Expand Down
6 changes: 3 additions & 3 deletions telereddit/services/generic_service.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import requests
from urllib.parse import urlunparse

from services.service import Service
from media import Media
from content_type import ContentType
from telereddit.services.service import Service
from telereddit.media import Media
from telereddit.content_type import ContentType


class Generic(Service):
Expand Down
8 changes: 4 additions & 4 deletions telereddit/services/gfycat_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import requests

from config.config import secret
from telereddit.config.config import secret

from services.service import Service
from media import Media
from content_type import ContentType
from telereddit.services.service import Service
from telereddit.media import Media
from telereddit.content_type import ContentType


class Gfycat(Service):
Expand Down
8 changes: 4 additions & 4 deletions telereddit/services/imgur_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import requests

from config.config import secret
from services.service import Service
from media import Media
from content_type import ContentType
from telereddit.config.config import secret
from telereddit.services.service import Service
from telereddit.media import Media
from telereddit.content_type import ContentType


class Imgur(Service):
Expand Down
10 changes: 5 additions & 5 deletions telereddit/services/services_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from urllib.parse import urlparse

from services.gfycat_service import Gfycat
from services.vreddit_service import Vreddit
from services.imgur_service import Imgur
from services.youtube_service import Youtube
from services.generic_service import Generic
from telereddit.services.gfycat_service import Gfycat
from telereddit.services.vreddit_service import Vreddit
from telereddit.services.imgur_service import Imgur
from telereddit.services.youtube_service import Youtube
from telereddit.services.generic_service import Generic


class ServicesWrapper:
Expand Down
8 changes: 4 additions & 4 deletions telereddit/services/vreddit_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import helpers
import requests
from services.service import Service
from urllib.parse import urlunparse

from media import Media
from content_type import ContentType
from telereddit.services.service import Service
import telereddit.helpers as helpers
from telereddit.media import Media
from telereddit.content_type import ContentType


class Vreddit(Service):
Expand Down
9 changes: 4 additions & 5 deletions telereddit/services/youtube_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from services.service import Service
from media import Media
from content_type import ContentType

from urllib.parse import urlunparse

import helpers
from telereddit.services.service import Service
from telereddit.media import Media
from telereddit.content_type import ContentType
import telereddit.helpers as helpers


class Youtube(Service):
Expand Down
8 changes: 4 additions & 4 deletions telereddit/telereddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from telegram import Update
import logging

from linker import Linker
import helpers
import config.config as config
from telereddit.linker import Linker
import telereddit.helpers as helpers
import telereddit.config.config as config


def on_chat_message(update: Update, context: CallbackContext):
Expand Down Expand Up @@ -47,7 +47,7 @@ def on_callback_query(update: Update, context: CallbackContext):
context.bot.answerCallbackQuery(update.callback_query.id)


if __name__ == "__main__":
def main():
sentry_sdk.init(config.secret.SENTRY_TOKEN)

updater = Updater(token=config.secret.TELEGRAM_TOKEN, use_context=True)
Expand Down
2 changes: 1 addition & 1 deletion telereddit/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from parameterized import parameterized, param

import helpers
import telereddit.helpers as helpers


class TestHelpers(unittest.TestCase):
Expand Down
12 changes: 6 additions & 6 deletions telereddit/tests/test_reddit.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import unittest
from unittest.mock import patch
import reddit
import telereddit.reddit as reddit
import json
import pathlib

from exceptions import SubredditDoesntExistError, SubredditPrivateError
from telereddit.exceptions import SubredditDoesntExistError, SubredditPrivateError

from content_type import ContentType
from telereddit.content_type import ContentType


class TestReddit(unittest.TestCase):
@patch('reddit.requests.get')
@patch('telereddit.reddit.requests.get')
def test_get_json_404(self, mock_get):
mock_get.return_value.ok = False
mock_get.return_value.json = lambda: {"message": "Not Found", "error": 404}
Expand All @@ -19,7 +19,7 @@ def test_get_json_404(self, mock_get):
reddit._get_json,
'https://reddit.com/r/n_o_t_a_n_a_m_e_i_h_ox_p_e/random')

@patch('reddit.requests.get')
@patch('telereddit.reddit.requests.get')
def test_get_json_private(self, mock_get):
mock_get.return_value.ok = False
mock_get.return_value.json = lambda: {"reason": "private", "message": "Forbidden", "error": 403}
Expand All @@ -28,7 +28,7 @@ def test_get_json_private(self, mock_get):
reddit._get_json,
'https://reddit.com/r/n_o_t_a_n_a_m_e_i_h_ox_p_e/random')

@patch('reddit.requests.get')
@patch('telereddit.reddit.requests.get')
def test_get_json_valid(self, mock_get):
with open(pathlib.Path(__file__).parent / 'json/r-funny-my_weather_app_nailed_it_today.json') as f:
mock_json = json.load(f)
Expand Down
6 changes: 3 additions & 3 deletions telereddit/tests/test_services.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import unittest
from services.services_wrapper import ServicesWrapper
from content_type import ContentType

from parameterized import parameterized, param

from telereddit.services.services_wrapper import ServicesWrapper
from telereddit.content_type import ContentType


class TestServices(unittest.TestCase):
@parameterized.expand([
Expand Down

0 comments on commit 9df08d2

Please sign in to comment.