Exemplo n.º 1
0
    def test_source(self):
        req = Mock(['args', 'headers', 'values'])
        req.args = {'foo': 'bar'}
        req.headers = {'baz': 'bat'}
        arg = Argument('foo', location=['args'])
        self.assertEqual(arg.source(req), req.args)

        arg = Argument('foo', location=['headers'])
        self.assertEqual(arg.source(req), req.headers)
class TestStringArgument(unittest.TestCase):
    def setUp(self):
        self.target = Argument('test', type=SafeStringArgument())

    def testUnicodeValue(self):
        ustr = u'M·A·C'

        result = self.target.convert(ustr)
        self.assertEqual(result, ustr.encode('ascii', 'ignore'))

    def testRegularString(self):
        s = "test123"
        result = self.target.convert(s)
        self.assertEqual(result, s)
Exemplo n.º 3
0
 def test_source_default_location(self):
     req = Mock(['params'])
     req._get_child_mock = lambda **kwargs: NonCallableMock(**kwargs)
     arg = Argument('foo')
     self.assertEqual(arg.source(req), req.params)
Exemplo n.º 4
0
 def test_source_bad_location(self):
     req = Mock(['params'])
     arg = Argument('foo', location=['foo'])
     self.assertTrue(len(arg.source(req)) == 0) # yes, basically you don't find it
Exemplo n.º 5
0
 def test_convert_default_type_with_null_input(self):
     """convert() should properly handle case where input is None"""
     arg = Argument('foo')
     self.assertEquals(arg.convert(None), None)
 def setUp(self):
     self.target = Argument('test', type=SafeStringArgument())