~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/server/tests/test_schema.py

  • Committer: Alberto Donato
  • Date: 2013-08-14 10:05:52 UTC
  • Revision ID: alberto.donato@canonical.com-20130814100552-9x3nc2cu27t2o23w
Add a UnicodeLine parameter type (for a single line of text, no newlines). [trivial] [r=free.ekanayaka].

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from txaws.server.exception import APIError
10
10
from txaws.server.schema import (
11
11
    Arguments, Bool, Date, Enum, Integer, Parameter, RawStr, Schema, Unicode,
12
 
    List, Structure,
13
 
    InconsistentParameterError)
 
12
    UnicodeLine, List, Structure, InconsistentParameterError)
14
13
 
15
14
 
16
15
class ArgumentsTestCase(TestCase):
261
260
        self.assertEqual("InvalidParameterValue", error.code)
262
261
 
263
262
 
 
263
class UnicodeLineTestCase(TestCase):
 
264
 
 
265
    def test_parse(self):
 
266
        """L{UnicodeLine.parse} converts the given raw C{value} to
 
267
        C{unicode}."""
 
268
        parameter = UnicodeLine("Test")
 
269
        self.assertEqual(u"foo", parameter.parse("foo"))
 
270
 
 
271
    def test_newlines_in_text(self):
 
272
        """
 
273
        The L{UnicodeLine} parameter returns an error if text contains
 
274
        newlines.
 
275
        """
 
276
        parameter = UnicodeLine("Test")
 
277
        error = self.assertRaises(APIError, parameter.coerce, "Test\nError")
 
278
        self.assertIn(u"Can't contain newlines", error.message)
 
279
        self.assertEqual(400, error.status)
 
280
 
 
281
 
264
282
class RawStrTestCase(TestCase):
265
283
 
266
284
    def test_parse(self):