CPI Ordering System (the old version)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 

94 lines
3.1 KiB

''' Tests for the root resource '''
import pytest
from pyramid.testing import DummyRequest, DummyResource
def test_base_child_init():
''' test initilization of BaseChildResource '''
from ordr.resources.helpers import BaseChildResource
parent = DummyResource(request='some request')
resource = BaseChildResource(name='a name', parent=parent)
assert resource.__name__ == 'a name'
assert resource.__parent__ == parent
assert resource.request == 'some request'
def test_base_child_acl():
''' test access controll list of BaseChildResource '''
from ordr.resources.helpers import BaseChildResource
parent = DummyResource(request='some request')
resource = BaseChildResource(name='a name', parent=parent)
with pytest.raises(NotImplementedError):
resource.__acl__()
def test_base_child_prepare_form():
''' test '_prepare_form()' method of BaseChildResource '''
from ordr.resources.helpers import BaseChildResource
from ordr.schemas.account import RegistrationSchema
import deform
request = DummyRequest()
parent = DummyResource(request=request)
resource = BaseChildResource('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():
''' test '_prepare_form()' method sets correct url '''
from ordr.resources.helpers import BaseChildResource
from ordr.schemas.account import RegistrationSchema
request = DummyRequest()
parent = DummyResource(request=request)
resource = BaseChildResource('a name', parent)
form = resource._prepare_form(RegistrationSchema, action='/foo')
assert form.action == '/foo'
def test_base_child_prepare_form_settings():
''' test '_prepare_form()' method uses additional settings '''
from ordr.resources.helpers import BaseChildResource
from ordr.schemas.account import RegistrationSchema
import deform
request = DummyRequest()
parent = DummyResource(request=request)
resource = BaseChildResource('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():
''' test '_prepare_form()' method can prefill a form '''
from ordr.resources.helpers import BaseChildResource
from ordr.schemas.account import RegistrationSchema
request = DummyRequest()
parent = DummyResource(request=request)
resource = BaseChildResource('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'