~oubiwann/txaws/920227-fix-pep8-pyflakes-errors

« back to all changes in this revision

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

  • Committer: Free Ekanayaka
  • Date: 2011-12-01 15:43:09 UTC
  • mfrom: (103.1.2 apierror-unicode-fixes)
  • Revision ID: free.ekanayaka@canonical.com-20111201154309-3nmr4f2bmxzz4p7x
Merge apierror-unicode-fixes [a=ack] [r=free.ekanayaka]

This branch does the following:

 - return the Parameter value as unicode in error messages, if possible.
 - convert APIError message to an ASCII string to avoid errors
   with twisted logger.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
1
3
from datetime import datetime
2
4
 
3
5
from pytz import UTC, FixedOffset
102
104
        self.assertEqual("InvalidParameterValue", error.code)
103
105
        self.assertEqual("Invalid integer value foo", error.message)
104
106
 
 
107
    def test_coerce_with_parameter_error_unicode(self):
 
108
        """
 
109
        L{Parameter.coerce} raises an L{APIError} if an invalid value is
 
110
        passed as request argument and parameter value is unicode.
 
111
        """
 
112
        parameter = Parameter("Test")
 
113
        parameter.parse = lambda value: int(value)
 
114
        parameter.kind = "integer"
 
115
        error = self.assertRaises(APIError, parameter.coerce, "citt\xc3\xa1")
 
116
        self.assertEqual(400, error.status)
 
117
        self.assertEqual("InvalidParameterValue", error.code)
 
118
        self.assertEqual(u"Invalid integer value cittá", error.message)
 
119
 
105
120
    def test_coerce_with_empty_strings(self):
106
121
        """
107
122
        L{Parameter.coerce} returns C{None} if the value is an empty string and
180
195
        parameter = Unicode("Test")
181
196
        self.assertEqual(u"foo", parameter.parse("foo"))
182
197
 
 
198
    def test_parse_unicode(self):
 
199
        """L{Unicode.parse} works with unicode input."""
 
200
        parameter = Unicode("Test")
 
201
        self.assertEqual(u"cittá", parameter.parse("citt\xc3\xa1"))
 
202
 
183
203
    def test_format(self):
184
204
        """L{Unicode.format} encodes the given C{unicode} with utf-8."""
185
205
        parameter = Unicode("Test")