family: add placeholders for anonymous and unlinked user cases (#19827)

This commit is contained in:
Serghei Mihai 2017-10-31 15:37:19 +01:00
parent 3014a634ea
commit 872e23a659
3 changed files with 53 additions and 13 deletions

View File

@ -1,23 +1,20 @@
{% load i18n %}
{% load i18n combo %}
<h2>{% trans "Informations related to your family" %}</h2>
{% trans "Top content for unlinked users" as top_content %}
{% placeholder "family_unlinked_user" name=top_content render=False %}
<div>
{% if not user.is_authenticated %}
<p>{% trans "You have to connect and link your account to a family." %}</p>
{% placeholder "family_unlinked_user" %}
{% elif error %}
<p>{{error}}</p>
{% elif not family.data %}
<p>{% trans "No family linked to your account." %}</p>
{% url 'family-link' as link_url %}
<p>
{% blocktrans %}
If you have family credentials, please
<a href="{{ link_url }}" rel="popup">click here</a> to link your personal
account to it.
{% endblocktrans %}
</p>
{% placeholder "family_unlinked_user" %}
<div class="family-link">
<a href="{{ link_url }}" rel="popup">{% trans "Link to your family" %}</a>
</div>
{% else %}
<div class="family_unlink">
<a href="{% url 'family-unlink' %}" rel="popup">{% trans "Unlink" %}</a>

View File

@ -20,6 +20,7 @@ from webtest import Upload
from combo.wsgi import application
from combo.data.models import Page, CellBase, TextCell, LinkCell, ConfigJsonCell, JsonCell
from combo.apps.family.models import FamilyInfosCell
from combo.apps.search.models import SearchCell
pytestmark = pytest.mark.django_db
@ -630,6 +631,19 @@ def test_page_cell_placeholder(app, admin_user):
assert re.findall('<h2>(.*)</h2>', resp.body) == [
'Page - One', 'Parameters', 'Content', 'JSON Feed / Foobar', 'Footer']
def test_page_familycell_placeholder(app, admin_user):
page = Page(title='My family', slug='my-family', template_name='standard')
page.save()
cell = FamilyInfosCell(page=page, placeholder='content', order=0)
cell.save()
app = login(app)
resp = app.get('/manage/pages/%s/' % page.id)
assert re.findall('data-placeholder-key="(.*)">', resp.body) == ['content', "family_unlinked_user", "footer"]
assert re.findall('<h2>(.*)</h2>', resp.body) == [
'Page - My family', 'Parameters', 'Content',
'Family Information Cell / Top content for unlinked users', 'Footer']
def test_page_discover_placeholder_with_error_cells(app, admin_user):
page = Page(title='One', slug='one', template_name='standard')
page.save()

View File

@ -14,6 +14,7 @@ from django.test import override_settings
from combo.wsgi import application
from combo.data.models import (Page, CellBase, TextCell, ParentContentCell,
FeedCell, LinkCell, ConfigJsonCell)
from combo.apps.family.models import FamilyInfosCell
pytestmark = pytest.mark.django_db
@ -386,3 +387,31 @@ def test_post_cell(app):
'url': 'http://test-post-cell/[value]/delete'}
resp2 = resp.form.submit()
assert requests_post.call_args[0][0] == 'http://test-post-cell/plop/delete'
def test_familyinfos_cell_with_placeholders(app, admin_user):
Page.objects.all().delete()
page = Page(title='Family', slug='index', template_name='standard')
page.save()
family_cell = FamilyInfosCell(page=page, placeholder='content', order=0)
family_cell.save()
TextCell(page=page, placeholder='family_unlinked_user', text='<p>Hello anonymous user</p>', order=0,
restricted_to_unlogged=True, public=True).save()
TextCell(page=page, placeholder='family_unlinked_user', text='<p>You are not linked</p>',
order=1, public=False, restricted_to_unlogged=False).save()
resp = app.get(reverse('combo-public-ajax-page-cell',
kwargs={'page_pk': page.pk, 'cell_reference': family_cell.get_reference()}))
assert "<p>Hello anonymous user</p>" in resp.content
assert "<p>You are not linked</p>" not in resp.content
app = login(app)
with override_settings(FAMILY_SERVICE={'root': '/family/'}):
with mock.patch('combo.utils.requests.get') as requests_get:
mocked_response = mock.Mock()
mocked_response.status_code = 200
mocked_response.json.return_value = {'err': 0, 'data': None}
requests_get.return_value = mocked_response
resp = app.get(reverse('combo-public-ajax-page-cell',
kwargs={'page_pk': page.pk, 'cell_reference': family_cell.get_reference()}))
assert "<p>Hello anonymous user</p>" not in resp.content
assert "<p>You are not linked</p>" in resp.content