diff --git a/django_th/forms/base.py b/django_th/forms/base.py index d097277..e789b25 100644 --- a/django_th/forms/base.py +++ b/django_th/forms/base.py @@ -1,3 +1,4 @@ +# coding: utf-8 from django import forms from django.forms import TextInput, PasswordInput from django.utils.translation import ugettext_lazy as _ diff --git a/django_th/forms/services.py b/django_th/forms/services.py index b3ca3b6..8d6ae3d 100644 --- a/django_th/forms/services.py +++ b/django_th/forms/services.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 from django import forms from django.conf import settings from django_th.models import ServicesActivated diff --git a/django_th/forms/wizard.py b/django_th/forms/wizard.py index 79bdc1a..31edfb5 100644 --- a/django_th/forms/wizard.py +++ b/django_th/forms/wizard.py @@ -1,6 +1,7 @@ +# coding: utf-8 from django import forms -from django_th.models import UserService from django.utils.translation import ugettext_lazy as _ +from django_th.models import UserService class ServiceChoiceForm(forms.Form): diff --git a/django_th/html_entities.py b/django_th/html_entities.py index 8bf6bd3..0436d03 100644 --- a/django_th/html_entities.py +++ b/django_th/html_entities.py @@ -1,6 +1,6 @@ # coding: utf-8 -import re import html.entities as htmlentities +import re class HtmlEntities: diff --git a/django_th/management/commands/publish.py b/django_th/management/commands/publish.py index ad480af..6f9ec04 100644 --- a/django_th/management/commands/publish.py +++ b/django_th/management/commands/publish.py @@ -1,16 +1,16 @@ #!/usr/bin/env python # coding: utf-8 from __future__ import unicode_literals -from multiprocessing import Pool, TimeoutError # django -from django.core.management.base import BaseCommand from django.conf import settings -from logging import getLogger +from django.core.management.base import BaseCommand from django.db.models import Q # trigger happy from django_th.models import TriggerService from django_th.publish import Pub +from logging import getLogger +from multiprocessing import Pool, TimeoutError # create logger logger = getLogger('django_th.trigger_happy') diff --git a/django_th/management/commands/read.py b/django_th/management/commands/read.py index f48d9db..74bdc0f 100644 --- a/django_th/management/commands/read.py +++ b/django_th/management/commands/read.py @@ -1,16 +1,16 @@ #!/usr/bin/env python # coding: utf-8 from __future__ import unicode_literals -from multiprocessing import Pool, TimeoutError # django -from django.core.management.base import BaseCommand from django.conf import settings -from logging import getLogger +from django.core.management.base import BaseCommand from django.db.models import Q # trigger happy from django_th.models import TriggerService from django_th.read import Read +from logging import getLogger +from multiprocessing import Pool, TimeoutError # create logger logger = getLogger('django_th.trigger_happy') diff --git a/django_th/management/commands/read_n_pub.py b/django_th/management/commands/read_n_pub.py index e4ac851..63656ad 100644 --- a/django_th/management/commands/read_n_pub.py +++ b/django_th/management/commands/read_n_pub.py @@ -1,17 +1,17 @@ #!/usr/bin/env python # coding: utf-8 from __future__ import unicode_literals -from multiprocessing import Pool, TimeoutError # django -from django.core.management.base import BaseCommand from django.conf import settings -from logging import getLogger +from django.core.management.base import BaseCommand from django.core.cache import caches # trigger happy from django_th.models import TriggerService from django_th.read import Read from django_th.publish import Pub +from logging import getLogger +from multiprocessing import Pool, TimeoutError # create logger logger = getLogger('django_th.trigger_happy') cache = caches['django_th'] @@ -48,4 +48,4 @@ def handle(self, *args, **options): cache.delete('django_th' + '_fire_trigger_' + str(trigger_id)) except TimeoutError as e: - logger.warn(e) + logger.warning(e) diff --git a/django_th/models/__init__.py b/django_th/models/__init__.py index 669978d..8902577 100644 --- a/django_th/models/__init__.py +++ b/django_th/models/__init__.py @@ -10,11 +10,11 @@ from django.utils.timezone import now from django.utils.translation import ugettext_lazy as _ -from logging import getLogger - from django_th.signals import digest_event from django_th.tools import warn_user_and_admin +from logging import getLogger + logger = getLogger('django_th.trigger_happy') diff --git a/django_th/publish.py b/django_th/publish.py index 71d3d17..efb93dc 100644 --- a/django_th/publish.py +++ b/django_th/publish.py @@ -6,12 +6,12 @@ # django from django.conf import settings -from logging import getLogger # trigger happy from django_th.services import default_provider from django_th.models import TriggerService, update_result +from logging import getLogger logger = getLogger('django_th.trigger_happy') diff --git a/django_th/read.py b/django_th/read.py index ccd47cf..ae52498 100644 --- a/django_th/read.py +++ b/django_th/read.py @@ -4,7 +4,6 @@ import arrow # django -from logging import getLogger from django.conf import settings from django.utils.timezone import now @@ -13,6 +12,8 @@ from django_th.models import TriggerService from django_th.tools import warn_user_and_admin +from logging import getLogger + logger = getLogger('django_th.trigger_happy') diff --git a/django_th/recycle.py b/django_th/recycle.py index 6bdcde1..dffbb1d 100644 --- a/django_th/recycle.py +++ b/django_th/recycle.py @@ -5,11 +5,12 @@ # django from django.conf import settings from django.core.cache import caches -from logging import getLogger # trigger happy from django_th.my_services import MyService +from logging import getLogger + logger = getLogger('django_th.trigger_happy') diff --git a/django_th/service_provider.py b/django_th/service_provider.py index bc3bd57..5af59c4 100644 --- a/django_th/service_provider.py +++ b/django_th/service_provider.py @@ -1,6 +1,6 @@ # coding: utf-8 -from django.conf import settings from collections import OrderedDict +from django.conf import settings class ServiceProvider(OrderedDict): diff --git a/django_th/services/services.py b/django_th/services/services.py index c5bb01e..3ad6972 100644 --- a/django_th/services/services.py +++ b/django_th/services/services.py @@ -1,11 +1,8 @@ # coding: utf-8 -# Using OAuth1Session -from requests_oauthlib import OAuth1Session, OAuth2Session - # django stuff +from django.conf import settings from django.core.cache import caches from django.core.urlresolvers import reverse -from django.conf import settings try: from django.apps import apps @@ -18,6 +15,8 @@ from django_th.models import UserService, ServicesActivated, TriggerService from django_th.publishing_limit import PublishingLimit from django_th.html_entities import HtmlEntities +# Using OAuth(12)Session +from requests_oauthlib import OAuth1Session, OAuth2Session class ServicesMgr(object): diff --git a/django_th/tests/test_views.py b/django_th/tests/test_views.py index 0329449..5468fd8 100644 --- a/django_th/tests/test_views.py +++ b/django_th/tests/test_views.py @@ -4,11 +4,11 @@ from django_th.models import TriggerService from django_th.views import TriggerEditedTemplateView -from django_th.views import TriggerDeletedTemplateView, TriggerListView +from django_th.views import TriggerDeletedTemplateView, TriggerListView, TriggerUpdateView from django_th.views_fbv import can_modify_trigger, trigger_on_off, \ trigger_edit, trigger_switch_all_to, list_services, \ service_related_triggers_switch_to, fire_trigger -from django_th.tests.test_main import MainTest, setup_view +from django_th.tests.test_main import MainTest from th_rss.models import Rss @@ -55,38 +55,33 @@ def setUp(self): # Every test needs access to the request factory. self.factory = RequestFactory() - def test_context_data(self): - """ - TriggerListView.get_context_data() sets - 'triggers_enabled', 'triggers_disabled', 'services_activated' - in context. - """ - # Setup name. - triggers_enabled = triggers_disabled = services_activated = 0 - queryset = TriggerService.objects.all() - + def test_get(self): + template = "home.html" # Setup request and view. - request = self.factory.get('/') + request = RequestFactory().get('th/') request.user = self.user - - view = TriggerListView( - template_name='home.html', object_list=queryset) - view = setup_view(view, request) + view = TriggerListView.as_view(template_name=template) # Run. - if request.user.is_authenticated(): - triggers_enabled = 3 - triggers_disabled = 1 - services_activated = 5 + response = view(request, user=request.user) + # Check. + self.assertEqual(response.status_code, 200) + self.assertEqual(response.template_name[0], "home.html") + - context = view.get_context_data() - context['nb_triggers'] = { - 'enabled': triggers_enabled, 'disabled': triggers_disabled} - context['nb_services'] = services_activated +class TriggerUpdateViewTestCase(MainTest): + def test_get(self): + template_name = "triggers/edit_description_trigger.html" + t = self.create_triggerservice() + # Setup request and view. + request = RequestFactory().get('th/trigger/edit/') + request.user = self.user + view = TriggerUpdateView.as_view(template_name=template_name) + # Run. + response = view(request, user=request.user, pk=t.id) # Check. - self.assertEqual(context['nb_triggers']['enabled'], triggers_enabled) - self.assertEqual(context['nb_triggers']['disabled'], triggers_disabled) - self.assertEqual(context['nb_services'], services_activated) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.template_name[0], template_name) class ViewFunction(MainTest): diff --git a/django_th/tests/test_views_userservices.py b/django_th/tests/test_views_userservices.py index 92d24c7..6399994 100644 --- a/django_th/tests/test_views_userservices.py +++ b/django_th/tests/test_views_userservices.py @@ -3,9 +3,8 @@ from django.test import RequestFactory from django_th.models import UserService -from django_th.tests.test_views import setup_view -from django_th.tests.test_main import MainTest -from django_th.views_userservices import UserServiceListView +from django_th.tests.test_main import MainTest, setup_view +from django_th.views_userservices import UserServiceListView, UserServiceCreateView, UserServiceUpdateView class UserServiceListViewTestCase(MainTest): @@ -35,61 +34,32 @@ def test_context_data(self): self.assertIn('service_list_remaining', context) -""" class UserServiceCreateViewTestCase(MainTest): - def setUp(self): - super(UserServiceCreateViewTestCase, self).setUp() - # Every test needs access to the request factory. - self.factory = RequestFactory() - - def test_context_data(self): - # Setup request and view - request = self.factory.get(reverse('add_service', args=['ServiceRss'])) + def test_get(self): + template_name = 'services/service_form.html' + # Setup request and view. + request = RequestFactory().get('th/service/add/') request.user = self.user - - view = UserServiceCreateView( - template_name='services/service_form.html', - form_class=UserServiceForm) - - kwargs = dict() - kwargs['service_name'] = 'ServiceRss' - - view = setup_view(view, request, **kwargs) - context = view.get_context_data() - - self.assertIn('service_name_alone', context) - self.assertIn('service_name', context) - self.assertIn('SERVICES_AUTH', context) - self.assertIn('SERVICES_HOSTED_WITH_AUTH', context) - self.assertIn('SERVICES_NEUTRAL', context) + view = UserServiceCreateView.as_view(template_name=template_name) + # Run. + response = view(request, user=request.user, service_name="ServiceRss") + # Check. + self.assertEqual(response.status_code, 200) + self.assertEqual(response.template_name[0], template_name) class UserServiceUpdateViewTestCase(MainTest): - def setUp(self): - super(UserServiceUpdateViewTestCase, self).setUp() - # Every test needs access to the request factory. - self.factory = RequestFactory() - - def test_context_data(self): - # Setup request and view - request = self.factory.get(reverse('edit_service', args=[1])) + def test_get(self): + template_name = 'services/service_form.html' + t = self.create_triggerservice() + # Setup request and view. + request = RequestFactory().get('th/service/edit/') request.user = self.user - - view = UserServiceUpdateView( - template_name='services/service_form.html', - form_class=UserServiceForm) - - kwargs = dict() - kwargs['pk'] = 1 - - view = setup_view(view, request, **kwargs) - context = view.get_context_data() - - self.assertIn('service_name_alone', context) - self.assertIn('service_name', context) - self.assertIn('SERVICES_AUTH', context) - self.assertIn('SERVICES_HOSTED_WITH_AUTH', context) - self.assertIn('SERVICES_NEUTRAL', context) -""" + view = UserServiceUpdateView.as_view(template_name=template_name) + # Run. + response = view(request, user=request.user, pk=t.id) + # Check. + self.assertEqual(response.status_code, 200) + self.assertEqual(response.template_name[0], template_name) diff --git a/django_th/tests/test_xcmd.py b/django_th/tests/test_xcmd.py index c2eaad4..90479af 100644 --- a/django_th/tests/test_xcmd.py +++ b/django_th/tests/test_xcmd.py @@ -11,3 +11,5 @@ def test_run(self): management.call_command('recycle', verbosity=0, interactive=False) management.call_command('read', verbosity=0, interactive=False) management.call_command('publish', verbosity=0, interactive=False) + management.call_command('read_n_pub', trigger_id=1, verbosity=0, interactive=False) + # management.call_command('send_digest', verbosity=0, interactive=False) diff --git a/django_th/tools.py b/django_th/tools.py index cc134cf..45e1153 100644 --- a/django_th/tools.py +++ b/django_th/tools.py @@ -1,7 +1,7 @@ # coding: utf-8 import arrow -import importlib import datetime +import importlib import time from django.conf import settings diff --git a/django_th/views.py b/django_th/views.py index 03a2a13..3658738 100644 --- a/django_th/views.py +++ b/django_th/views.py @@ -3,19 +3,16 @@ from django.core.cache import caches from django.conf import settings - from django.contrib.auth.decorators import login_required -from django.http import HttpResponseRedirect -from django.views.generic import TemplateView, UpdateView, ListView, DeleteView from django.db.models import Q +from django.http import HttpResponseRedirect from django.utils.decorators import method_decorator - from django.urls import reverse, reverse_lazy +from django.views.generic import TemplateView, UpdateView, ListView, DeleteView # trigger_happy -from django_th.models import TriggerService, UserService - from django_th.forms.base import TriggerServiceForm +from django_th.models import TriggerService, UserService from django_th.views_fbv import can_modify_trigger import logging diff --git a/django_th/views_fbv.py b/django_th/views_fbv.py index f931c8a..d605e9d 100644 --- a/django_th/views_fbv.py +++ b/django_th/views_fbv.py @@ -5,16 +5,11 @@ from django.core.cache import caches from django.core import management from django.conf import settings - from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth import logout from django.utils.translation import ugettext as _ from django.http import HttpResponseRedirect - -try: - from django.urls import reverse -except ImportError: # Django 1.9 and earlier - from django.core.urlresolvers import reverse +from django.urls import reverse # django_th from django_th.tools import get_service diff --git a/django_th/views_userservices.py b/django_th/views_userservices.py index f5e1781..ba06852 100644 --- a/django_th/views_userservices.py +++ b/django_th/views_userservices.py @@ -1,13 +1,14 @@ +# coding: utf-8 from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib import messages from django.core.urlresolvers import reverse_lazy, reverse from django.http import HttpResponseRedirect from django.shortcuts import redirect, get_object_or_404 -from django.views.generic import CreateView, DeleteView, UpdateView -from django.views.generic import ListView from django.utils.translation import ugettext_lazy as _ from django.utils.decorators import method_decorator +from django.views.generic import CreateView, DeleteView, UpdateView +from django.views.generic import ListView from django_th.models import UserService, ServicesActivated from django_th.forms.base import UserServiceForm diff --git a/django_th/views_wizard.py b/django_th/views_wizard.py index 46e8f2b..50f5a07 100644 --- a/django_th/views_wizard.py +++ b/django_th/views_wizard.py @@ -1,14 +1,14 @@ -from django.shortcuts import render_to_response -from formtools.wizard.views import SessionWizardView +# coding: utf-8 from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect +from django.shortcuts import render_to_response from django_th.models import TriggerService, UserService from django_th.forms.wizard import ConsumerForm from django_th.tools import get_service, class_for_name from django_th.services import default_provider - +from formtools.wizard.views import SessionWizardView """ Part III : Service Wizard """ diff --git a/th_evernote/__init__.py b/th_evernote/__init__.py index c7616ba..e69de29 100644 --- a/th_evernote/__init__.py +++ b/th_evernote/__init__.py @@ -1,2 +0,0 @@ -VERSION = (0, 4, 0) # PEP 386 -__version__ = ".".join([str(x) for x in VERSION]) diff --git a/th_evernote/evernote_mgr.py b/th_evernote/evernote_mgr.py index 683b670..e03ce7c 100644 --- a/th_evernote/evernote_mgr.py +++ b/th_evernote/evernote_mgr.py @@ -1,15 +1,15 @@ # coding: utf-8 +from django.core.cache import caches +from django.utils.translation import ugettext as _ + +from django_th.models import update_result + import evernote.edam.type.ttypes as Types from evernote.edam.error.ttypes import EDAMSystemException, EDAMUserException from evernote.edam.error.ttypes import EDAMErrorCode from evernote.edam.notestore import NoteStore -from django.utils.translation import ugettext as _ from logging import getLogger -from django.core.cache import caches - -from django_th.models import update_result - logger = getLogger('django_th.trigger_happy') cache = caches['django_th'] diff --git a/th_evernote/my_evernote.py b/th_evernote/my_evernote.py index 7e3a7fc..3c25385 100644 --- a/th_evernote/my_evernote.py +++ b/th_evernote/my_evernote.py @@ -18,8 +18,8 @@ from logging import getLogger -from th_evernote.models import Evernote from th_evernote.evernote_mgr import EvernoteMgr +from th_evernote.models import Evernote from th_evernote.sanitize import sanitize """ diff --git a/th_evernote/tests.py b/th_evernote/tests.py index f5240f6..42a7253 100644 --- a/th_evernote/tests.py +++ b/th_evernote/tests.py @@ -1,18 +1,22 @@ # coding: utf-8 -from unittest.mock import patch - from django.conf import settings from django.core.cache import caches from django_th.tests.test_main import MainTest + +from evernote.api.client import EvernoteClient + from th_evernote.models import Evernote from th_evernote.forms import EvernoteProviderForm, EvernoteConsumerForm from th_evernote.my_evernote import ServiceEvernote from th_evernote.evernote_mgr import EvernoteMgr from th_evernote.sanitize import sanitize -from evernote.api.client import EvernoteClient + +from unittest.mock import patch + try: from unittest import mock + except ImportError: import mock diff --git a/th_github/__init__.py b/th_github/__init__.py index be05340..e69de29 100644 --- a/th_github/__init__.py +++ b/th_github/__init__.py @@ -1,2 +0,0 @@ -VERSION = (0, 0, 1) # PEP 386 -__version__ = ".".join([str(x) for x in VERSION]) diff --git a/th_github/my_github.py b/th_github/my_github.py index 30c5151..bd2a969 100644 --- a/th_github/my_github.py +++ b/th_github/my_github.py @@ -1,16 +1,17 @@ # coding: utf-8 -# github -from github3 import GitHub - # django classes from django.conf import settings -from logging import getLogger from django.core.cache import caches from django.utils.translation import ugettext as _ # django_th classes -from django_th.services.services import ServicesMgr from django_th.models import update_result +from django_th.services.services import ServicesMgr + +# github +from github3 import GitHub + +from logging import getLogger from th_github.models import Github """ diff --git a/th_github/tests.py b/th_github/tests.py index 315e210..d68dcbf 100644 --- a/th_github/tests.py +++ b/th_github/tests.py @@ -1,14 +1,15 @@ # coding: utf-8 -from unittest.mock import patch, PropertyMock -from github3 import GitHub - from django.conf import settings from django.core.cache import caches +from django_th.tests.test_main import MainTest + +from github3 import GitHub from th_github.models import Github from th_github.forms import GithubProviderForm, GithubConsumerForm from th_github.my_github import ServiceGithub -from django_th.tests.test_main import MainTest + +from unittest.mock import patch, PropertyMock cache = caches['django_th'] diff --git a/th_instapush/my_instapush.py b/th_instapush/my_instapush.py index 9628bef..6d8a850 100644 --- a/th_instapush/my_instapush.py +++ b/th_instapush/my_instapush.py @@ -1,7 +1,8 @@ # coding: utf-8 +from django_th.services.services import ServicesMgr + from instapush import Instapush, App -from django_th.services.services import ServicesMgr from th_instapush.models import Instapush as InstapushModel """ diff --git a/th_instapush/tests.py b/th_instapush/tests.py index d6c55d7..c5e4e01 100644 --- a/th_instapush/tests.py +++ b/th_instapush/tests.py @@ -1,12 +1,14 @@ # coding: utf-8 -from unittest.mock import patch -from instapush import App from django_th.tests.test_main import MainTest +from instapush import App + from th_instapush.models import Instapush as InstapushModel from th_instapush.forms import InstapushConsumerForm from th_instapush.my_instapush import ServiceInstapush +from unittest.mock import patch + class InstapushTest(MainTest): diff --git a/th_mastodon/my_mastodon.py b/th_mastodon/my_mastodon.py index 6feb0f0..ccaf9e6 100644 --- a/th_mastodon/my_mastodon.py +++ b/th_mastodon/my_mastodon.py @@ -1,8 +1,5 @@ # coding: utf-8 import arrow -from logging import getLogger - -from mastodon import Mastodon as MastodonAPI # django classes from django.conf import settings @@ -12,9 +9,14 @@ from django.utils.translation import ugettext as _ # django_th classes -from django_th.services.services import ServicesMgr from django_th.models import update_result, UserService +from django_th.services.services import ServicesMgr from django_th.tools import download_image + +from logging import getLogger + +from mastodon import Mastodon as MastodonAPI + from th_mastodon.models import Mastodon import re diff --git a/th_mastodon/tests.py b/th_mastodon/tests.py index ce31103..9658443 100644 --- a/th_mastodon/tests.py +++ b/th_mastodon/tests.py @@ -7,9 +7,9 @@ from mastodon import Mastodon as MastodonAPI +from th_mastodon.forms import MastodonProviderForm, MastodonConsumerForm from th_mastodon.models import Mastodon from th_mastodon.my_mastodon import ServiceMastodon -from th_mastodon.forms import MastodonProviderForm, MastodonConsumerForm from unittest.mock import patch diff --git a/th_pelican/my_pelican.py b/th_pelican/my_pelican.py index 261e44c..efaba13 100644 --- a/th_pelican/my_pelican.py +++ b/th_pelican/my_pelican.py @@ -1,16 +1,13 @@ # coding: utf-8 import arrow - -from slugify import slugify - # django classes from django.conf import settings -from logging import getLogger - # django_th classes from django_th.services.services import ServicesMgr from django_th.tools import to_datetime +from logging import getLogger +from slugify import slugify """ TH_SERVICES = ( ... diff --git a/th_pelican/tests.py b/th_pelican/tests.py index 292ea1e..00309fb 100644 --- a/th_pelican/tests.py +++ b/th_pelican/tests.py @@ -2,8 +2,9 @@ from django.conf import settings from django_th.tests.test_main import MainTest -from th_pelican.models import Pelican + from th_pelican.forms import PelicanProviderForm, PelicanConsumerForm +from th_pelican.models import Pelican from th_pelican.my_pelican import ServicePelican diff --git a/th_pocket/my_pocket.py b/th_pocket/my_pocket.py index 2e20946..ed4a884 100644 --- a/th_pocket/my_pocket.py +++ b/th_pocket/my_pocket.py @@ -1,18 +1,17 @@ # coding: utf-8 import arrow - -# pocket API -from pocket import Pocket, AuthException, RateLimitException - # django classes from django.conf import settings -from logging import getLogger from django.core.cache import caches # django_th classes +from django_th.html_entities import HtmlEntities from django_th.models import update_result, UserService from django_th.services.services import ServicesMgr -from django_th.html_entities import HtmlEntities + +from logging import getLogger +# pocket API +from pocket import Pocket, AuthException, RateLimitException """ handle process with pocket diff --git a/th_pocket/tests.py b/th_pocket/tests.py index f57cbbc..f1ea67f 100644 --- a/th_pocket/tests.py +++ b/th_pocket/tests.py @@ -1,14 +1,17 @@ # coding: utf-8 import arrow -from unittest.mock import patch import datetime -from pocket import Pocket from django.conf import settings -from th_pocket.models import Pocket as PocketModel +from django_th.tests.test_main import MainTest + +from pocket import Pocket + from th_pocket.forms import PocketProviderForm, PocketConsumerForm +from th_pocket.models import Pocket as PocketModel from th_pocket.my_pocket import ServicePocket -from django_th.tests.test_main import MainTest + +from unittest.mock import patch class PocketTest(MainTest): diff --git a/th_pushbullet/my_pushbullet.py b/th_pushbullet/my_pushbullet.py index a33f9fb..afbd383 100644 --- a/th_pushbullet/my_pushbullet.py +++ b/th_pushbullet/my_pushbullet.py @@ -1,16 +1,16 @@ # coding: utf-8 import arrow -# Pushbullet -from pushbullet import Pushbullet as Pushb - # django classes from django.conf import settings -from logging import getLogger from django.core.cache import caches # django_th classes -from django_th.services.services import ServicesMgr from django_th.models import update_result +from django_th.services.services import ServicesMgr + +from logging import getLogger +from pushbullet import Pushbullet as Pushb + from th_pushbullet.models import Pushbullet diff --git a/th_pushbullet/tests.py b/th_pushbullet/tests.py index fd40dcf..70830e0 100644 --- a/th_pushbullet/tests.py +++ b/th_pushbullet/tests.py @@ -2,8 +2,12 @@ from django.conf import settings from django_th.tests.test_main import MainTest -from th_pushbullet.models import Pushbullet +from pushbullet import Pushbullet as Pushb from th_pushbullet.forms import PushbulletProviderForm, PushbulletConsumerForm +from th_pushbullet.models import Pushbullet +from th_pushbullet.my_pushbullet import ServicePushbullet + +from unittest.mock import patch class PushbulletTest(MainTest): @@ -17,8 +21,7 @@ def create_pushb(self, type='note'): """ trigger = self.create_triggerservice(consumer_name="ServicePushbullet") status = True - return Pushbullet.objects.create(trigger=trigger, type=type, - status=status) + return Pushbullet.objects.create(trigger=trigger, type=type, status=status) def test_pushbullet(self): """ @@ -55,3 +58,94 @@ def test_get_config_th(self): does this settings exists ? """ self.assertTrue(settings.TH_PUSHBULLET_KEY) + + +class ServicePushbulletTest(PushbulletTest): + """ + ServicePushbulletTest + """ + def test_init(self): + with patch.object(Pushb, '__init__') as mock_pushb: + mock_pushb.return_value = None + ServicePushbullet(token='AZERTY123') + mock_pushb.assert_called_once() + + def test_read_data(self): + pushb_data = self.create_pushb() + kwargs = dict({'date_triggered': '2013-05-11 13:23:58+00:00', + 'trigger_id': pushb_data.trigger_id}) + with patch.object(Pushb, '__init__') as mock_pushb1: + mock_pushb1.return_value = None + with patch.object(Pushb, 'get_pushes') as mock_pushb2: + se = ServicePushbullet(token='AZERTY123') + se.read_data(**kwargs) + mock_pushb2.assert_called_once() + mock_pushb1.assert_called_once() + + def test_save_data_no_token(self): + pushb_data = self.create_pushb() + data = {'link': 'http://foo.bar/some/thing/else/what/else', + 'title': 'what else', + 'content': 'A nice content with a nice ' + 'foobar link', + 'summary_detail': 'summary foobar', + 'description': 'description foobar'} + se = ServicePushbullet(token=None) + result = se.save_data(trigger_id=pushb_data.trigger_id, **data) + self.assertFalse(result) + + def test_save_data_unknown_type(self): + data = {'link': 'http://foo.bar/some/thing/else/what/else', + 'title': 'what else', + 'content': 'A nice content with a nice ' + 'foobar link', + 'summary_detail': 'summary foobar', + 'description': 'description foobar'} + with patch.object(Pushb, '__init__') as mock_pushb1: + mock_pushb1.return_value = None + # push_note case + pushb_data = self.create_pushb(type='fake') + se = ServicePushbullet(token='AZERTY123') + result = se.save_data(trigger_id=pushb_data.trigger_id, **data) + self.assertFalse(result) + mock_pushb1.assert_called_once() + + def test_save_data_note(self): + data = {'link': 'http://foo.bar/some/thing/else/what/else', + 'title': 'what else', + 'content': 'A nice content with a nice ' + 'foobar link', + 'summary_detail': 'summary foobar', + 'description': 'description foobar'} + with patch.object(Pushb, '__init__') as mock_pushb1: + mock_pushb1.return_value = None + # push_note case + pushb_data = self.create_pushb() + with patch.object(Pushb, 'push_note') as mock_pushb2: + se = ServicePushbullet(token='AZERTY123') + se.save_data(trigger_id=pushb_data.trigger_id, **data) + mock_pushb2.assert_called_once() + mock_pushb1.assert_called_once() + + def test_save_data_link(self): + data = {'link': 'http://foo.bar/some/thing/else/what/else', + 'title': 'what else', + 'content': 'A nice content with a nice ' + 'foobar link', + 'summary_detail': 'summary foobar', + 'description': 'description foobar'} + with patch.object(Pushb, '__init__') as mock_pushb1: + mock_pushb1.return_value = None + # push_link case + pushb_data = self.create_pushb(type='link') + with patch.object(Pushb, 'push_link') as mock_pushb2: + se = ServicePushbullet(token='AZERTY123') + se.save_data(trigger_id=pushb_data.trigger_id, **data) + mock_pushb2.assert_called_once() + mock_pushb1.assert_called_once() + + def test_auth(self): + pass + + def test_callback(self): + pass diff --git a/th_reddit/my_reddit.py b/th_reddit/my_reddit.py index 7f5b15b..57f2c93 100644 --- a/th_reddit/my_reddit.py +++ b/th_reddit/my_reddit.py @@ -5,11 +5,12 @@ from django.conf import settings from django.core.cache import caches from django.core.urlresolvers import reverse -from logging import getLogger # django_th classes -from django_th.services.services import ServicesMgr from django_th.models import update_result, UserService +from django_th.services.services import ServicesMgr + +from logging import getLogger from praw import Reddit as RedditApi diff --git a/th_reddit/tests.py b/th_reddit/tests.py index 7efadab..faf7473 100644 --- a/th_reddit/tests.py +++ b/th_reddit/tests.py @@ -5,9 +5,9 @@ from django_th.models import TriggerService, UserService, ServicesActivated +from th_reddit.forms import RedditProviderForm, RedditConsumerForm from th_reddit.models import Reddit from th_reddit.my_reddit import ServiceReddit -from th_reddit.forms import RedditProviderForm, RedditConsumerForm class RedditTest(TestCase): diff --git a/th_rss/tests.py b/th_rss/tests.py index 3c7d841..99ee063 100644 --- a/th_rss/tests.py +++ b/th_rss/tests.py @@ -1,16 +1,17 @@ # coding: utf-8 -import uuid import arrow from django.conf import settings from django.test import RequestFactory -from th_rss.models import Rss +from django_th.tests.test_main import MainTest, setup_view +import django_th + from th_rss.forms import RssProviderForm +from th_rss.models import Rss from th_rss.views import MyRssFeed -import django_th -from django_th.tests.test_main import MainTest, setup_view +import uuid class RssTest(MainTest): diff --git a/th_rss/views.py b/th_rss/views.py index 2fb6e88..f0a4d80 100644 --- a/th_rss/views.py +++ b/th_rss/views.py @@ -1,13 +1,13 @@ # coding: utf-8 -from django.views.generic import TemplateView, ListView -from django.core.cache import caches from django.conf import settings +from django.core.cache import caches +from django.views.generic import TemplateView, ListView -from th_rss.models import Rss from django_th.models import TriggerService - import django_th +from th_rss.models import Rss + class MyRssFeed(TemplateView): """ diff --git a/th_slack/my_slack.py b/th_slack/my_slack.py index 58bee28..1edee1c 100644 --- a/th_slack/my_slack.py +++ b/th_slack/my_slack.py @@ -1,13 +1,15 @@ # coding: utf-8 -import requests - # django classes -from logging import getLogger from django.core.cache import caches # django_th classes from django_th.services.services import ServicesMgr from django_th.models import TriggerService + +from logging import getLogger + +import requests + from th_slack.models import Slack logger = getLogger('django_th.trigger_happy') diff --git a/th_slack/tests.py b/th_slack/tests.py index 59d5807..1245a69 100644 --- a/th_slack/tests.py +++ b/th_slack/tests.py @@ -1,13 +1,15 @@ # coding: utf-8 from django.conf import settings -from th_slack.models import Slack +from django_th.tests.test_main import MainTest + +import requests + from th_slack.forms import SlackConsumerForm +from th_slack.models import Slack from th_slack.my_slack import ServiceSlack -from django_th.tests.test_main import MainTest from unittest.mock import patch -import requests class SlackTest(MainTest): diff --git a/th_taiga/my_taiga.py b/th_taiga/my_taiga.py index 68c3c66..c0abb51 100644 --- a/th_taiga/my_taiga.py +++ b/th_taiga/my_taiga.py @@ -1,13 +1,12 @@ # coding: utf-8 -from taiga import TaigaAPI - # django classes -from logging import getLogger from django.core.cache import caches - # django_th classes -from django_th.services.services import ServicesMgr from django_th.models import UserService +from django_th.services.services import ServicesMgr + +from logging import getLogger +from taiga import TaigaAPI from th_taiga.models import Taiga logger = getLogger('django_th.trigger_happy') diff --git a/th_taiga/tests.py b/th_taiga/tests.py index 3f9c635..b2ff404 100644 --- a/th_taiga/tests.py +++ b/th_taiga/tests.py @@ -1,12 +1,13 @@ # coding: utf-8 from django.conf import settings +from django_th.tests.test_main import MainTest + from th_taiga.models import Taiga from th_taiga.forms import TaigaProviderForm from th_taiga.my_taiga import ServiceTaiga from unittest.mock import patch -from django_th.tests.test_main import MainTest class TaigaTest(MainTest): diff --git a/th_todoist/my_todoist.py b/th_todoist/my_todoist.py index 82e7a29..abbb563 100644 --- a/th_todoist/my_todoist.py +++ b/th_todoist/my_todoist.py @@ -1,13 +1,11 @@ # coding: utf-8 import arrow -# TodoistAPI -from todoist.api import TodoistAPI - # django classes from django.conf import settings -from logging import getLogger from django.core.cache import caches - +from logging import getLogger +# TodoistAPI +from todoist.api import TodoistAPI # django_th classes from django_th.services.services import ServicesMgr diff --git a/th_todoist/tests.py b/th_todoist/tests.py index dba0570..6e3e4c5 100644 --- a/th_todoist/tests.py +++ b/th_todoist/tests.py @@ -1,14 +1,14 @@ # coding: utf-8 -from unittest.mock import patch -from todoist.api import TodoistAPI - from django.conf import settings - from django_th.tests.test_main import MainTest + from th_todoist.models import Todoist from th_todoist.forms import TodoistProviderForm, TodoistConsumerForm from th_todoist.my_todoist import ServiceTodoist +from todoist.api import TodoistAPI +from unittest.mock import patch + class TodoistTest(MainTest): diff --git a/th_trello/my_trello.py b/th_trello/my_trello.py index 3f34a9b..bd0d48c 100644 --- a/th_trello/my_trello.py +++ b/th_trello/my_trello.py @@ -1,18 +1,16 @@ # coding: utf-8 -# Trello API -from trello import TrelloClient, ResourceUnavailable - # django classes from django.conf import settings -from django.utils.translation import ugettext as _ -from logging import getLogger from django.core.cache import caches - +from django.utils.translation import ugettext as _ # django_th classes from django_th.apps import DjangoThConfig -from django_th.services.services import ServicesMgr from django_th.models import update_result, UserService +from django_th.services.services import ServicesMgr +from logging import getLogger +# Trello API +from trello import TrelloClient, ResourceUnavailable """ handle process with Trello put the following in settings.py diff --git a/th_trello/tests.py b/th_trello/tests.py index 42a7ed5..32c3d98 100644 --- a/th_trello/tests.py +++ b/th_trello/tests.py @@ -1,7 +1,4 @@ # coding: utf-8 -from unittest.mock import patch -from trello import TrelloClient - from django.conf import settings from django_th.tests.test_main import MainTest @@ -10,6 +7,10 @@ from th_trello.forms import TrelloProviderForm, TrelloConsumerForm from th_trello.my_trello import ServiceTrello +from trello import TrelloClient + +from unittest.mock import patch + class TrelloTest(MainTest): diff --git a/th_tumblr/my_tumblr.py b/th_tumblr/my_tumblr.py index 99e5fa8..e889903 100644 --- a/th_tumblr/my_tumblr.py +++ b/th_tumblr/my_tumblr.py @@ -1,13 +1,13 @@ # coding: utf-8 -from pytumblr import TumblrRestClient # django classes from django.conf import settings from django.core.cache import caches +# django_th classes +from django_th.services.services import ServicesMgr from logging import getLogger -# django_th classes -from django_th.services.services import ServicesMgr +from pytumblr import TumblrRestClient """ handle process with tumblr diff --git a/th_tumblr/tests.py b/th_tumblr/tests.py index f38c6d0..c990064 100644 --- a/th_tumblr/tests.py +++ b/th_tumblr/tests.py @@ -1,13 +1,16 @@ # coding: utf-8 -from django.test import TestCase from django.conf import settings from django.contrib.auth.models import User +from django.test import TestCase + from django_th.models import TriggerService, UserService, ServicesActivated + +from pytumblr import TumblrRestClient + from th_tumblr.models import Tumblr from th_tumblr.my_tumblr import ServiceTumblr from th_tumblr.forms import TumblrProviderForm, TumblrConsumerForm -from pytumblr import TumblrRestClient from unittest.mock import patch diff --git a/th_twitter/my_twitter.py b/th_twitter/my_twitter.py index 4c5903f..0182ab9 100644 --- a/th_twitter/my_twitter.py +++ b/th_twitter/my_twitter.py @@ -1,22 +1,21 @@ # coding: utf-8 import arrow - -# Twitter lib -from twython import Twython, TwythonAuthError, TwythonRateLimitError - # django classes from django.conf import settings from django.utils import html from django.utils.translation import ugettext as _ from django.core.cache import caches - # django_th classes from django_th.services.services import ServicesMgr from django_th.models import update_result, UserService -from th_twitter.models import Twitter from logging import getLogger +from th_twitter.models import Twitter +# Twitter lib +from twython import Twython, TwythonAuthError, TwythonRateLimitError + + """ handle process with twitter put the following in settings.py diff --git a/th_twitter/tests.py b/th_twitter/tests.py index 4f8eb7a..f8f8337 100644 --- a/th_twitter/tests.py +++ b/th_twitter/tests.py @@ -2,10 +2,11 @@ from django.conf import settings from django.core.cache import caches +from django_th.tests.test_main import MainTest + from th_twitter.models import Twitter from th_twitter.forms import TwitterProviderForm, TwitterConsumerForm from th_twitter.my_twitter import ServiceTwitter -from django_th.tests.test_main import MainTest from twython import Twython from unittest.mock import patch diff --git a/th_wallabag/my_wallabag.py b/th_wallabag/my_wallabag.py index ec9e081..ab5d2ac 100644 --- a/th_wallabag/my_wallabag.py +++ b/th_wallabag/my_wallabag.py @@ -1,20 +1,21 @@ # coding: utf-8 # add here the call of any native lib of python like datetime etc. import arrow -import requests -from requests import HTTPError -# add the python API here if needed -from wallabag_api.wallabag import Wallabag as Wall # django classes from django.core.urlresolvers import reverse -from logging import getLogger from django.core.cache import caches - # django_th classes from django_th.services.services import ServicesMgr from django_th.html_entities import HtmlEntities from django_th.models import UserService, ServicesActivated, update_result + +from logging import getLogger +import requests +from requests import HTTPError + from th_wallabag.models import Wallabag +# add the python API here if needed +from wallabag_api.wallabag import Wallabag as Wall """ handle process with wallabag