Projet

Général

Profil

0001-add-application-name-and-slug-in-association-context.patch

Josué Kouka, 16 novembre 2017 14:03

Télécharger (3,27 ko)

Voir les différences:

Subject: [PATCH] add application name and slug in association context (#19649)

 mandayejs/applications.py  | 12 ++++++++++++
 mandayejs/mandaye/views.py |  4 ++--
 tests/test_mandayejs.py    | 15 ++++++++++++++-
 3 files changed, 28 insertions(+), 3 deletions(-)
mandayejs/applications.py
24 24
from django.http import Http404
25 25
from django.core.exceptions import ImproperlyConfigured
26 26
from django.core.urlresolvers import resolve
27
from django.utils.text import slugify
27 28

  
28 29

  
29 30
def get_app_settings():
......
75 76
            dct['SITE_LOGIN_PATH'] = os.path.join(dct['SITE_LOGIN_PATH_PREFIX'], parent.SITE_LOGIN_PATH.strip('/'))
76 77
        return super(AppSettingsMeta, cls).__new__(cls, name, bases, dct)
77 78

  
79
    @property
80
    def name(self):
81
        app_name = getattr(settings, 'SITE_APP_NAME', None)
82
        if app_name:
83
            return app_name
84
        return self.__name__
85

  
86
    @property
87
    def slug(self):
88
        return slugify(self.__name__)
89

  
78 90

  
79 91
class AppSettings(object):
80 92
    __metaclass__ = AppSettingsMeta
mandayejs/mandaye/views.py
123 123
            return HttpResponseRedirect(resolve_url('post-login'))
124 124
    else:
125 125
        form = FormFactory()
126

  
126
    app_settings = get_app_settings()
127 127
    response = render(request, 'mandaye/associate.html', {
128
        'form': form,
128
        'form': form, 'appname': app_settings.name, 'appslug': app_settings.slug
129 129
    })
130 130
    return response
131 131

  
tests/test_mandayejs.py
15 15
from mandayejs.mandaye.models import UserCredentials
16 16
from mandayejs.mandaye.utils import exec_phantom
17 17
from mandayejs.mandaye.forms import FormFactory
18
from mandayejs.mandaye.views import post_login_do
18
from mandayejs.mandaye.views import associate, post_login_do
19 19

  
20 20
from utils import create_user, create_credentials, get_uuid, get_user
21 21

  
......
409 409
    request.user = user_john
410 410
    response = post_login_do(request)
411 411
    assert 'window.top.location = "http://example.net/"' in response.content
412

  
413

  
414
@mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS)
415
def test_app_name_slug_in_association_context(settings, user_john):
416
    client = Client()
417
    client.login(username='john', password='john')
418
    response = client.get(reverse('associate'))
419
    assert response.context['appname'] == 'Test'
420
    assert response.context['appslug'] == 'test'
421
    # when overidding the appname in settings
422
    settings.SITE_APP_NAME = 'Test A'
423
    response = client.get(reverse('associate'))
424
    assert response.context['appname'] == 'Test A'
412
-