예제 #1
0
    def test_it_does_not_raise_if_group_type_is_same(self, group_data,
                                                     pyramid_csrf_request):
        group = mock.Mock(type='open')
        group_data['group_type'] = 'open'
        schema = CreateAdminGroupSchema().bind(request=pyramid_csrf_request,
                                               group=group)

        schema.deserialize(group_data)
예제 #2
0
    def test_it_passes_creator_and_authority_to_service(
            self, group_data, pyramid_csrf_request, user_svc, user_validator):
        schema = CreateAdminGroupSchema(validator=user_validator).bind(
            request=pyramid_csrf_request)
        schema.deserialize(group_data)

        user_svc.fetch.assert_called_with(group_data['creator'],
                                          group_data['authority'])
예제 #3
0
    def test_it_raises_when_user_not_found(self, group_data,
                                           pyramid_csrf_request, user_svc,
                                           user_validator):
        user_svc.fetch.return_value = None
        schema = CreateAdminGroupSchema(validator=user_validator).bind(
            request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid, match='.*creator.*'):
            schema.deserialize(group_data)
예제 #4
0
    def test_it_raises_if_group_type_changed(self, group_data,
                                             pyramid_csrf_request):
        group = mock.Mock(type='open')
        group_data['group_type'] = 'restricted'
        schema = CreateAdminGroupSchema().bind(request=pyramid_csrf_request,
                                               group=group)

        with pytest.raises(colander.Invalid, match='Changing group type'):
            schema.deserialize(group_data)
예제 #5
0
    def test_it_does_not_raise_if_group_type_is_same(self, group_data,
                                                     pyramid_csrf_request, org, user_svc):
        group = mock.Mock(type='open')
        group_data['group_type'] = 'open'
        schema = CreateAdminGroupSchema().bind(request=pyramid_csrf_request,
                                               group=group,
                                               user_svc=user_svc,
                                               organizations={org.pubid: org})

        schema.deserialize(group_data)
예제 #6
0
파일: admin_groups.py 프로젝트: welhefna/h
 def __init__(self, request):
     user_svc = request.find_service(name='user')
     list_org_svc = request.find_service(name='list_organizations')
     self.organizations = {o.pubid: o for o in list_org_svc.organizations()}
     self.schema = CreateAdminGroupSchema().bind(
         request=request,
         organizations=self.organizations,
         user_svc=user_svc)
     self.request = request
     self.form = _create_form(self.request, self.schema,
                              (_('Create New Group'), ))
예제 #7
0
파일: admin_groups.py 프로젝트: jmcarp/h
    def __init__(self, request):
        # Look up the group here rather than using traversal in the route
        # definition as that would apply `Group.__acl__` which will not match if
        # the current (admin) user is not the creator of the group.
        try:
            pubid = request.matchdict.get('pubid')
            self.group = GroupFactory(request)[pubid]
        except KeyError:
            raise HTTPNotFound()

        self.request = request
        self.schema = CreateAdminGroupSchema().bind(request=request, group=self.group)
        self.form = request.create_form(self.schema,
                                        buttons=(_('Save'),))
예제 #8
0
파일: admin_groups.py 프로젝트: welhefna/h
    def __init__(self, request):
        # Look up the group here rather than using traversal in the route
        # definition as that would apply `Group.__acl__` which will not match if
        # the current (admin) user is not the creator of the group.
        try:
            pubid = request.matchdict.get('pubid')
            self.group = GroupFactory(request)[pubid]
        except KeyError:
            raise HTTPNotFound()

        list_org_svc = request.find_service(name='list_organizations')
        self.organizations = {
            o.pubid: o
            for o in list_org_svc.organizations(self.group.authority)
        }

        user_svc = request.find_service(name='user')
        self.request = request
        self.schema = CreateAdminGroupSchema().bind(
            request=request,
            group=self.group,
            organizations=self.organizations,
            user_svc=user_svc)
        self.form = _create_form(self.request, self.schema, (_('Save'), ))
예제 #9
0
파일: admin_groups.py 프로젝트: jmcarp/h
 def __init__(self, request):
     user_validator = user_exists_validator_factory(request.find_service(name='user'))
     self.schema = CreateAdminGroupSchema(validator=user_validator).bind(request=request)
     self.request = request
     self.form = request.create_form(self.schema,
                                     buttons=(_('Create New Group'),))
예제 #10
0
 def test_it_allows_when_user_exists_at_authority(self, group_data,
                                                  pyramid_csrf_request,
                                                  user_svc, user_validator):
     schema = CreateAdminGroupSchema(validator=user_validator).bind(
         request=pyramid_csrf_request)
     schema.deserialize(group_data)
예제 #11
0
def bound_schema(pyramid_csrf_request):
    schema = CreateAdminGroupSchema().bind(request=pyramid_csrf_request)
    return schema
예제 #12
0
 def __init__(self, request):
     self.request = request
     self.schema = CreateAdminGroupSchema().bind(request=request)
     self.form = request.create_form(self.schema,
                                     buttons=(_('Create New Group'),))
예제 #13
0
def bound_schema(pyramid_csrf_request, org, user_svc):
    schema = CreateAdminGroupSchema().bind(request=pyramid_csrf_request,
                                           user_svc=user_svc,
                                           organizations={org.pubid: org})
    return schema