Ejemplo n.º 1
0
 def test_validate_raises_ValidationError_if_no_group_authority(self):
     schema = CreateGroupAPISchema(default_authority='hypothes.is')
     with pytest.raises(ValidationError, match="groupid may only be set on groups oustide of the default authority"):
         schema.validate({
             'name': 'Blustery',
             'groupid': 'group:[email protected]'
         })
Ejemplo n.º 2
0
 def test_validate_raises_ValidationError_if_no_group_authority(self):
     schema = CreateGroupAPISchema(default_authority="hypothes.is")
     with pytest.raises(
         ValidationError,
         match="groupid may only be set on groups oustide of the default authority",
     ):
         schema.validate(
             {"name": "Blustery", "groupid": "group:[email protected]"}
         )
Ejemplo n.º 3
0
 def test_validate_raises_ValidationError_if_no_group_authority(self):
     schema = CreateGroupAPISchema(default_authority="hypothes.is")
     with pytest.raises(
         ValidationError,
         match="groupid may only be set on groups oustide of the default authority",
     ):
         schema.validate(
             {"name": "Blustery", "groupid": "group:[email protected]"}
         )
Ejemplo n.º 4
0
 def test_it_raises_if_description_too_long(self):
     schema = CreateGroupAPISchema()
     with pytest.raises(ValidationError) as exc:
         schema.validate({
             'name':
             'Name not the Problem',
             'description':
             'o' * (GROUP_DESCRIPTION_MAX_LENGTH + 1)
         })
     assert "description:" in str(exc.value)
     assert "is too long" in str(exc.value)
Ejemplo n.º 5
0
    def test_it_validates_with_valid_description(self):
        schema = CreateGroupAPISchema()

        appstruct = schema.validate({
            'name':
            'This Seems Fine',
            'description':
            'This description seems adequate'
        })

        assert 'description' in appstruct
Ejemplo n.º 6
0
def create(request):
    """Create a group from the POST payload."""
    schema = CreateGroupAPISchema()

    appstruct = schema.validate(_json_payload(request))
    group_properties = {
        'name': appstruct['name'],
        'description': appstruct.get('description', None),
    }

    group_service = request.find_service(name='group')

    group = group_service.create_private_group(
        group_properties['name'],
        request.user.userid,
        description=group_properties['description'],
    )

    group_context = GroupContext(group, request)
    return GroupJSONPresenter(group_context).asdict(expand=['organization'])
Ejemplo n.º 7
0
def create(request):
    """Create a group from the POST payload."""
    schema = CreateGroupAPISchema()

    appstruct = schema.validate(_json_payload(request))
    group_properties = {
        'name': appstruct['name'],
        'description': appstruct.get('description', None),
    }

    group_service = request.find_service(name='group')

    group = group_service.create_private_group(
        group_properties['name'],
        request.user.userid,
        description=group_properties['description'],
    )

    group_context = GroupContext(group, request)
    return GroupJSONPresenter(group_context).asdict(expand=['organization'])
Ejemplo n.º 8
0
def create(request):
    """Create a group from the POST payload."""
    # @TODO Temporary: Remove this check once private groups supported at other authorities
    if request.authority != request.user.authority:
        raise HTTPBadRequest(
            _('Group creation currently only supported for default authority'))

    schema = CreateGroupAPISchema()

    appstruct = schema.validate(_json_payload(request))
    group_properties = {
        'name': appstruct['name'],
        'description': appstruct.get('description', None),
    }

    group_service = request.find_service(name='group')

    group = group_service.create_private_group(
        group_properties['name'],
        request.user.userid,
        description=group_properties['description'],
    )
    group_context = GroupContext(group, request)
    return GroupJSONPresenter(group_context).asdict(expand=['organization'])
Ejemplo n.º 9
0
    def test_it_validates_with_valid_name(self):
        schema = CreateGroupAPISchema()

        appstruct = schema.validate({'name': 'Perfectly Fine'})

        assert 'name' in appstruct
Ejemplo n.º 10
0
 def test_it_raises_if_name_too_long(self):
     schema = CreateGroupAPISchema()
     with pytest.raises(ValidationError) as exc:
         schema.validate({'name': 'o' * (GROUP_NAME_MAX_LENGTH + 1)})
     assert "name:" in str(exc.value)
     assert "is too long" in str(exc.value)
Ejemplo n.º 11
0
 def test_it_raises_if_name_missing(self):
     schema = CreateGroupAPISchema()
     with pytest.raises(ValidationError,
                        match=".*is a required property.*"):
         schema.validate({})