''' Tests for the root resource ''' import pytest from pyramid.testing import DummyRequest, DummyResource def test_base_child_init(): from ordr.resources.helpers import BaseChildResource resource = BaseChildResource( request='some request', name='a name', parent='the parent' ) assert resource.__name__ == 'a name' assert resource.__parent__ == 'the parent' assert resource.request == 'some request' def test_base_child_acl(): from ordr.resources.helpers import BaseChildResource resource = BaseChildResource( request='some request', name='a name', parent='the parent' ) with pytest.raises(NotImplementedError): resource.__acl__() def test_base_child_prepare_form(): from ordr.resources.helpers import BaseChildResource from ordr.schemas.account import RegistrationSchema import deform parent = DummyResource() request = DummyRequest() resource = BaseChildResource(request, 'a name', parent) form = resource._prepare_form(RegistrationSchema) assert isinstance(form, deform.Form) assert form.action == 'http://example.com//' assert len(form.buttons) == 0 def test_base_child_prepare_form_url(): from ordr.resources.helpers import BaseChildResource from ordr.schemas.account import RegistrationSchema parent = DummyResource() request = DummyRequest() resource = BaseChildResource(request, 'a name', parent) form = resource._prepare_form(RegistrationSchema, action='/foo') assert form.action == '/foo' def test_base_child_prepare_form_settings(): from ordr.resources.helpers import BaseChildResource from ordr.schemas.account import RegistrationSchema import deform parent = DummyResource() request = DummyRequest() resource = BaseChildResource(request, 'a name', parent) settings = {'buttons': ('ok', 'cancel')} form = resource._prepare_form(RegistrationSchema, **settings) assert len(form.buttons) == 2 assert isinstance(form.buttons[0], deform.Button) assert isinstance(form.buttons[1], deform.Button) def test_base_child_prepare_form_prefill(): from ordr.resources.helpers import BaseChildResource from ordr.schemas.account import RegistrationSchema parent = DummyResource() request = DummyRequest() resource = BaseChildResource(request, 'a name', parent) prefill = { 'first_name': 'John', 'last_name': 'Doe', 'email': 'johndoe@example.com' } form = resource._prepare_form(RegistrationSchema, prefill=prefill) assert form['first_name'].cstruct == 'John' assert form['last_name'].cstruct == 'Doe' assert form['email'].cstruct == 'johndoe@example.com'