示例#1
0
 def test_invalid_root_dict_fromjson(self):
     try:
         parse('["invalid"]', {'a': ArrayType(str)}, False)
         assert False
     except Exception as e:
         assert isinstance(e, ClientSideError)
         assert e.msg == "Request must be a JSON dict"
    def test_from_params_native_array(self):
        class params(dict):
            def getall(self, path):
                return ['1', '2']

        p = params({'a': []})
        assert from_params(ArrayType(int), p, 'a', set()) == [1, 2]
示例#3
0
 def test_invalid_list_fromjson(self):
     jlist = "invalid"
     try:
         parse('{"a": "%s"}' % jlist, {'a': ArrayType(str)}, False)
         assert False
     except Exception as e:
         assert isinstance(e, InvalidInput)
         assert e.fieldname == 'a'
         assert e.value == jlist
         assert e.msg == "Value not a valid list: %s" % jlist
 def test_args_from_args_array_type(self):
     fake_type = ArrayType(MyBaseType)
     fd = FunctionDefinition(FunctionDefinition)
     fd.arguments.append(FunctionArgument('fake-arg', fake_type, True, []))
     try:
         args_from_args(fd, [['invalid-argument']], {})
     except InvalidInput as e:
         assert ArrayType.__name__ in str(e)
     else:
         self.fail('Should have thrown an InvalidInput')
 def test_from_params_empty_array(self):
     assert from_params(ArrayType(int), {}, 'a', set()) is Unset