Exemple #1
0
 def test_add(self, req, redirect):
     item = Redirect()
     item.state = 1
     assert isinstance(item.add(req), EmptySrc)
     item.src = '/'
     assert isinstance(item.add(req), EmptyDst)
     item.dst = '/root'
     assert isinstance(item.add(req), BadCode)
     item.code = 301
     assert item.add(req) is None
Exemple #2
0
def redirect(req):
    item = Redirect()
    form = Form((('src', '/'),
                 ('dst', '/test'),
                 ('code', 301)))
    item.bind(form)
    assert item.add(req) is not None
    return item
Exemple #3
0
def admin_redirects_add_update(req, id=None):
    check_login(req)
    check_right(req, module_right)
    check_token(req, req.form.get('token'), uri='/admin/redirects')

    item = Redirect(id)
    item.bind(req.form)
    rv = item.mod(req) if id else item.add(req)

    if isinstance(rv, Redirect):
        return send_json(req, {})

    req.status = state.HTTP_BAD_REQUEST
    if isinstance(rv, ErrorValue):
        return send_json(req, rv, cls=ObjectEncoder)

    return send_json(req, {'reason': 'src_exist'})