36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import datetime
|
|
import json
|
|
import mock
|
|
import pytest
|
|
|
|
from django.test import override_settings
|
|
|
|
from combo.data.models import Page
|
|
from combo.profile.models import ProfileCell
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
@override_settings(
|
|
KNOWN_SERVICES={'authentic': {'idp': {'title': 'IdP', 'url': 'http://example.org/'}}})
|
|
@mock.patch('combo.utils.requests.get')
|
|
def test_profile_cell(requests_get, app, admin_user):
|
|
page = Page()
|
|
page.save()
|
|
|
|
cell = ProfileCell(page=page, order=0)
|
|
cell.save()
|
|
|
|
data = {'first_name': 'Foo', 'birthdate': '2018-08-10'}
|
|
requests_get.return_value = mock.Mock(
|
|
content=json.dumps(data),
|
|
json=lambda: data,
|
|
status_code=200)
|
|
|
|
admin_user.get_name_id = lambda: '123456'
|
|
|
|
context = cell.get_cell_extra_context({'synchronous': True, 'selected_user': admin_user})
|
|
assert context['profile_fields']['first_name']['value'] == 'Foo'
|
|
assert context['profile_fields']['birthdate']['value'] == datetime.date(2018, 8, 10)
|
|
assert requests_get.call_args[0][0] == 'http://example.org/api/users/123456/'
|