Exemplo n.º 1
0
def parse_markup(request):
    post = six.text_type(request.data.get('post', '')).strip()

    try:
        validate_post_length(post)
    except ValidationError as e:
        return Response({'detail': e.args[0]}, status=status.HTTP_400_BAD_REQUEST)

    parsed = common_flavour(request, request.user, post, force_shva=True)['parsed_text']
    finalised = finalise_markup(parsed)

    return Response({'parsed': finalised})
Exemplo n.º 2
0
Arquivo: api.py Projeto: ipein/Misago
 def validate_markup(self, data):
     validate_post_length(data)
     return data
Exemplo n.º 3
0
 def validate(self, data):
     validate_post_length(data.get('post', ''))
     return data
 def validate(self, data):
     validate_post_length(data.get('post', ''))
     return data
Exemplo n.º 5
0
 def test_valid_post(self):
     """valid post passes validation"""
     validate_post_length("Lorem ipsum dolor met sit amet elit.")
Exemplo n.º 6
0
 def test_too_long_post(self):
     """too long post is rejected"""
     with self.assertRaises(ValidationError):
         post = 'a' * settings.post_length_max
         validate_post_length(post * 2)
Exemplo n.º 7
0
 def test_too_short_post(self):
     """too short post is rejected"""
     with self.assertRaises(ValidationError):
         post = 'a' * settings.post_length_min
         validate_post_length(post[1:])
Exemplo n.º 8
0
 def test_empty_post(self):
     """empty post is rejected"""
     with self.assertRaises(ValidationError):
         validate_post_length("")