Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
some refactoring for clearest code
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Demah committed Apr 27, 2015
1 parent 9a68696 commit 88bb1c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
18 changes: 11 additions & 7 deletions django_th/tests/test_models_and_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def create_userservice(self, token="AZERTY12345"):
def test_userservice(self):
u = self.create_userservice()
self.assertTrue(isinstance(u, UserService))
self.assertEqual(u.show(), "User Service %s %s %s" %
(u.user, u.token, u.name))
self.assertEqual(u.show(), "User Service %s %s %s" % (u.user, u.token,
u.name))

"""
Form - works with python 2.7.x - fails with python 3.4.0
Expand All @@ -72,9 +72,11 @@ class ServicesActivatedTest(TestCase):
"""
ServicesActivated Model
"""
def create_servicesactivated(self, name='ServiceRss', status=True,
auth_required=False,
description='RSS Feeds Service'):
def create_servicesactivated(self):
name = 'ServiceRss'
status = True
auth_required = False
description = 'RSS Feeds Service'
return ServicesActivated.objects.create(name=name, status=status,
auth_required=auth_required,
description=description)
Expand Down Expand Up @@ -123,8 +125,10 @@ def create_triggerservice(self, date_created="20130610",
def test_triggerservice(self):
t = self.create_triggerservice()
self.assertTrue(isinstance(t, TriggerService))
self.assertEqual(t.show(), "My Service %s %s %s %s" %
(t.provider, t.consumer, t.description, t.user))
self.assertEqual(t.show(), "My Service %s %s %s %s" % (t.provider,
t.consumer,
t.description,
t.user))

"""
Form
Expand Down
21 changes: 9 additions & 12 deletions django_th/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@
class TriggerEditedTemplateViewTestCase(unittest.TestCase):

def test_get(self):
template_name = "triggers/thanks_trigger.html"
template = "triggers/thanks_trigger.html"
# Setup request and view.
request = RequestFactory().get('/th/trigger/edit/thanks')
view = TriggerEditedTemplateView.as_view(template_name=template_name)
view = TriggerEditedTemplateView.as_view(template_name=template)
sentence = 'Your trigger has been successfully modified'
# Run.
response = view(request)
# Check.
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.template_name[0], 'triggers/thanks_trigger.html')
self.assertEqual(response.template_name[0],
'triggers/thanks_trigger.html')
self.assertEqual(response.context_data['sentence'], sentence)


class TriggerDeletedTemplateViewTestCase(unittest.TestCase):

def test_get(self):
template_name = "triggers/thanks_trigger.html"
template = "triggers/thanks_trigger.html"
# Setup request and view.
request = RequestFactory().get('/th/trigger/delete/thanks')
view = TriggerDeletedTemplateView.as_view(
template_name=template_name)
view = TriggerDeletedTemplateView.as_view(template_name=template)
sentence = 'Your trigger has been successfully deleted'
# Run.
response = view(request)
# Check.
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.template_name[0], 'triggers/thanks_trigger.html')
self.assertEqual(response.template_name[0],
'triggers/thanks_trigger.html')
self.assertEqual(response.context_data['sentence'], sentence)


Expand All @@ -61,9 +60,7 @@ def test_context_data(self):
in context.
"""
# Setup name.
triggers_enabled = 0
triggers_disabled = 0
services_activated = 0
triggers_enabled = triggers_disabled = services_activated = 0
queryset = TriggerService.objects.all()

# Setup request and view.
Expand Down
19 changes: 11 additions & 8 deletions django_th/tests/test_views_userservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from django_th.models import UserService
from django_th.tests.test_views import setup_view


class UserServiceAddedTemplateViewTestCase(unittest.TestCase):

def test_get(self):
template_name = 'services/thanks_service.html'
template = 'services/thanks_service.html'
# Setup request and view.
request = RequestFactory().get('/th/service/add/thanks')
view = UserServiceAddedTemplateView.as_view(
template_name=template_name)
view = UserServiceAddedTemplateView.as_view(template_name=template)
sentence = 'Your service has been successfully created'
# Run.
response = view(request)
Expand All @@ -29,11 +29,10 @@ def test_get(self):
class UserServiceDeletedTemplateViewTestCase(unittest.TestCase):

def test_get(self):
template_name = 'services/thanks_service.html'
template = 'services/thanks_service.html'
# Setup request and view.
request = RequestFactory().get('/th/service/delete/thanks')
view = UserServiceDeletedTemplateView.as_view(
template_name=template_name)
view = UserServiceDeletedTemplateView.as_view(template_name=template)
sentence = 'Your service has been successfully deleted'
# Run.
response = view(request)
Expand Down Expand Up @@ -72,12 +71,16 @@ def test_context_data(self):

if request.user.is_authenticated():
nb_user_service = nb_service = 20
context, action = self.get_action_context(context, nb_user_service, nb_service)
context, action = self.get_action_context(context,
nb_user_service,
nb_service)
self.assertEqual(context['action'], action)

nb_user_service = 19
nb_service = 20
context, action = self.get_action_context(context, nb_user_service, nb_service)
context, action = self.get_action_context(context,
nb_user_service,
nb_service)
self.assertEqual(context['action'], action)

def get_action_context(self, context, nb_user_service, nb_service):
Expand Down

0 comments on commit 88bb1c6

Please sign in to comment.