Projet

Général

Profil

0001-theme-check-we-post-a-value-on-theme-selection-41079.patch

Nicolas Roche, 29 mars 2020 13:34

Télécharger (3,22 ko)

Voir les différences:

Subject: [PATCH] theme: check we post a value on theme selection (#41079)

 hobo/theme/views.py | 6 +++---
 tests/test_theme.py | 9 ++++++++-
 2 files changed, 11 insertions(+), 4 deletions(-)
hobo/theme/views.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import colorsys
18 18
import random
19 19

  
20 20
from django.contrib import messages
21 21
from django.core.urlresolvers import reverse
22
from django.shortcuts import redirect
23 22
from django.utils.translation import ugettext as _
24 23
from django.views.generic import RedirectView, TemplateView
25 24

  
26 25
from hobo.environment.forms import VariablesFormMixin
27 26
from .forms import ThemeOptionsForm
28 27
from .utils import (get_themes, get_selected_theme, set_theme)
29 28

  
30 29

  
......
52 51

  
53 52
home = HomeView.as_view()
54 53

  
55 54

  
56 55
class SelectView(RedirectView):
57 56
    permanent = False
58 57

  
59 58
    def get_redirect_url(self):
60
        set_theme(self.request.POST['theme'])
61
        messages.info(self.request, _('The theme has been changed, it will soon be visible on the sites.'))
59
        if self.request.method == 'POST':
60
            set_theme(self.request.POST['theme'])
61
            messages.info(self.request, _('The theme has been changed, it will soon be visible on the sites.'))
62 62
        return reverse('theme-home')
63 63

  
64 64
select = SelectView.as_view()
65 65

  
66 66

  
67 67
class OptionsView(VariablesFormMixin, TemplateView):
68 68
    template_name = 'hobo/theme_options.html'
69 69
    variables = ['global_title']
tests/test_theme.py
32 32
    assert Variable.objects.filter(name='foo')[0].value == ''
33 33

  
34 34
    # easter egg, sometimes it gets sorted by colour
35 35
    mocked_random.return_value = 0.09
36 36
    resp = app.get('/theme').follow()
37 37
    assert [x['value'] for x in resp.html.findAll('input', {'type': 'radio'})] == ['publik', 'alfortville']
38 38

  
39 39

  
40
def test_thme_view_empty(app, admin_user, settings):
40
def test_theme_view_empty(app, admin_user, settings):
41 41
    del settings.THEMES_DIRECTORY
42 42
    app = login(app)
43 43
    resp = app.get('/theme').follow()
44 44
    assert 'Theme' in resp.text
45 45

  
46 46

  
47 47
def test_theme_option_view(app, admin_user):
48 48
    app = login(app)
......
52 52
    resp.form['global_title'] = 'foo'
53 53
    resp = resp.form.submit()
54 54
    assert Variable.objects.all()[0].name == 'global_title'
55 55
    assert Variable.objects.all()[0].value == 'foo'
56 56

  
57 57
    assert resp.location == '.'
58 58
    resp = resp.follow()
59 59
    assert resp.html.find('li').text == 'foo'
60

  
61

  
62
def test_theme_select_view_without_theme_selected(app, admin_user, fake_themes):
63
    assert Variable.objects.filter(name='theme').count() == 0
64
    app = login(app)
65
    resp = app.get('/theme/select')
66
    assert resp.location == '/theme/'
60
-