thirdparty/google_appengine/lib/django/tests/regressiontests/httpwrappers/tests.py
changeset 2866 a04b1e4126c4
parent 2864 2e0b0af889be
child 2868 9f7f269383f7
equal deleted inserted replaced
2864:2e0b0af889be 2866:a04b1e4126c4
     1 """
       
     2 ###################
       
     3 # Empty QueryDict #
       
     4 ###################
       
     5 
       
     6 >>> q = QueryDict('')
       
     7 
       
     8 >>> q['foo']
       
     9 Traceback (most recent call last):
       
    10 ...
       
    11 MultiValueDictKeyError: "Key 'foo' not found in <MultiValueDict: {}>"
       
    12 
       
    13 >>> q['something'] = 'bar'
       
    14 Traceback (most recent call last):
       
    15 ...
       
    16 AttributeError: This QueryDict instance is immutable
       
    17 
       
    18 >>> q.get('foo', 'default')
       
    19 'default'
       
    20 
       
    21 >>> q.getlist('foo')
       
    22 []
       
    23 
       
    24 >>> q.setlist('foo', ['bar', 'baz'])
       
    25 Traceback (most recent call last):
       
    26 ...
       
    27 AttributeError: This QueryDict instance is immutable
       
    28 
       
    29 >>> q.appendlist('foo', ['bar'])
       
    30 Traceback (most recent call last):
       
    31 ...
       
    32 AttributeError: This QueryDict instance is immutable
       
    33 
       
    34 >>> q.has_key('foo')
       
    35 False
       
    36 
       
    37 >>> q.items()
       
    38 []
       
    39 
       
    40 >>> q.lists()
       
    41 []
       
    42 
       
    43 >>> q.keys()
       
    44 []
       
    45 
       
    46 >>> q.values()
       
    47 []
       
    48 
       
    49 >>> len(q)
       
    50 0
       
    51 
       
    52 >>> q.update({'foo': 'bar'})
       
    53 Traceback (most recent call last):
       
    54 ...
       
    55 AttributeError: This QueryDict instance is immutable
       
    56 
       
    57 >>> q.pop('foo')
       
    58 Traceback (most recent call last):
       
    59 ...
       
    60 AttributeError: This QueryDict instance is immutable
       
    61 
       
    62 >>> q.popitem()
       
    63 Traceback (most recent call last):
       
    64 ...
       
    65 AttributeError: This QueryDict instance is immutable
       
    66 
       
    67 >>> q.clear()
       
    68 Traceback (most recent call last):
       
    69 ...
       
    70 AttributeError: This QueryDict instance is immutable
       
    71 
       
    72 >>> q.setdefault('foo', 'bar')
       
    73 Traceback (most recent call last):
       
    74 ...
       
    75 AttributeError: This QueryDict instance is immutable
       
    76 
       
    77 >>> q.urlencode()
       
    78 ''
       
    79 
       
    80 ###################################
       
    81 # Mutable copy of empty QueryDict #
       
    82 ###################################
       
    83 
       
    84 >>> q = q.copy()
       
    85 
       
    86 >>> q['foo']
       
    87 Traceback (most recent call last):
       
    88 ...
       
    89 MultiValueDictKeyError: "Key 'foo' not found in <MultiValueDict: {}>"
       
    90 
       
    91 >>> q['name'] = 'john'
       
    92 
       
    93 >>> q['name']
       
    94 'john'
       
    95 
       
    96 >>> q.get('foo', 'default')
       
    97 'default'
       
    98 
       
    99 >>> q.get('name', 'default')
       
   100 'john'
       
   101 
       
   102 >>> q.getlist('name')
       
   103 ['john']
       
   104 
       
   105 >>> q.getlist('foo')
       
   106 []
       
   107 
       
   108 >>> q.setlist('foo', ['bar', 'baz'])
       
   109 
       
   110 >>> q.get('foo', 'default')
       
   111 'baz'
       
   112 
       
   113 >>> q.getlist('foo')
       
   114 ['bar', 'baz']
       
   115 
       
   116 >>> q.appendlist('foo', 'another')
       
   117 
       
   118 >>> q.getlist('foo')
       
   119 ['bar', 'baz', 'another']
       
   120 
       
   121 >>> q['foo']
       
   122 'another'
       
   123 
       
   124 >>> q.has_key('foo')
       
   125 True
       
   126 
       
   127 >>> q.items()
       
   128 [('foo', 'another'), ('name', 'john')]
       
   129 
       
   130 >>> q.lists()
       
   131 [('foo', ['bar', 'baz', 'another']), ('name', ['john'])]
       
   132 
       
   133 >>> q.keys()
       
   134 ['foo', 'name']
       
   135 
       
   136 >>> q.values()
       
   137 ['another', 'john']
       
   138 
       
   139 >>> len(q)
       
   140 2
       
   141 
       
   142 >>> q.update({'foo': 'hello'})
       
   143 
       
   144 # Displays last value
       
   145 >>> q['foo']
       
   146 'hello'
       
   147 
       
   148 >>> q.get('foo', 'not available')
       
   149 'hello'
       
   150 
       
   151 >>> q.getlist('foo')
       
   152 ['bar', 'baz', 'another', 'hello']
       
   153 
       
   154 >>> q.pop('foo')
       
   155 ['bar', 'baz', 'another', 'hello']
       
   156 
       
   157 >>> q.get('foo', 'not there')
       
   158 'not there'
       
   159 
       
   160 >>> q.setdefault('foo', 'bar')
       
   161 'bar'
       
   162 
       
   163 >>> q['foo']
       
   164 'bar'
       
   165 
       
   166 >>> q.getlist('foo')
       
   167 ['bar']
       
   168 
       
   169 >>> q.urlencode()
       
   170 'foo=bar&name=john'
       
   171 
       
   172 >>> q.clear()
       
   173 
       
   174 >>> len(q)
       
   175 0
       
   176 
       
   177 #####################################
       
   178 # QueryDict with one key/value pair #
       
   179 #####################################
       
   180 
       
   181 >>> q = QueryDict('foo=bar')
       
   182 
       
   183 >>> q['foo']
       
   184 'bar'
       
   185 
       
   186 >>> q['bar']
       
   187 Traceback (most recent call last):
       
   188 ...
       
   189 MultiValueDictKeyError: "Key 'bar' not found in <MultiValueDict: {'foo': ['bar']}>"
       
   190 
       
   191 >>> q['something'] = 'bar'
       
   192 Traceback (most recent call last):
       
   193 ...
       
   194 AttributeError: This QueryDict instance is immutable
       
   195 
       
   196 >>> q.get('foo', 'default')
       
   197 'bar'
       
   198 
       
   199 >>> q.get('bar', 'default')
       
   200 'default'
       
   201 
       
   202 >>> q.getlist('foo')
       
   203 ['bar']
       
   204 
       
   205 >>> q.getlist('bar')
       
   206 []
       
   207 
       
   208 >>> q.setlist('foo', ['bar', 'baz'])
       
   209 Traceback (most recent call last):
       
   210 ...
       
   211 AttributeError: This QueryDict instance is immutable
       
   212 
       
   213 >>> q.appendlist('foo', ['bar'])
       
   214 Traceback (most recent call last):
       
   215 ...
       
   216 AttributeError: This QueryDict instance is immutable
       
   217 
       
   218 >>> q.has_key('foo')
       
   219 True
       
   220 
       
   221 >>> q.has_key('bar')
       
   222 False
       
   223 
       
   224 >>> q.items()
       
   225 [('foo', 'bar')]
       
   226 
       
   227 >>> q.lists()
       
   228 [('foo', ['bar'])]
       
   229 
       
   230 >>> q.keys()
       
   231 ['foo']
       
   232 
       
   233 >>> q.values()
       
   234 ['bar']
       
   235 
       
   236 >>> len(q)
       
   237 1
       
   238 
       
   239 >>> q.update({'foo': 'bar'})
       
   240 Traceback (most recent call last):
       
   241 ...
       
   242 AttributeError: This QueryDict instance is immutable
       
   243 
       
   244 >>> q.pop('foo')
       
   245 Traceback (most recent call last):
       
   246 ...
       
   247 AttributeError: This QueryDict instance is immutable
       
   248 
       
   249 >>> q.popitem()
       
   250 Traceback (most recent call last):
       
   251 ...
       
   252 AttributeError: This QueryDict instance is immutable
       
   253 
       
   254 >>> q.clear()
       
   255 Traceback (most recent call last):
       
   256 ...
       
   257 AttributeError: This QueryDict instance is immutable
       
   258 
       
   259 >>> q.setdefault('foo', 'bar')
       
   260 Traceback (most recent call last):
       
   261 ...
       
   262 AttributeError: This QueryDict instance is immutable
       
   263 
       
   264 >>> q.urlencode()
       
   265 'foo=bar'
       
   266 
       
   267 #####################################################
       
   268 # QueryDict with two key/value pairs with same keys #
       
   269 #####################################################
       
   270 
       
   271 >>> q = QueryDict('vote=yes&vote=no')
       
   272 
       
   273 >>> q['vote']
       
   274 'no'
       
   275 
       
   276 >>> q['something'] = 'bar'
       
   277 Traceback (most recent call last):
       
   278 ...
       
   279 AttributeError: This QueryDict instance is immutable
       
   280 
       
   281 >>> q.get('vote', 'default')
       
   282 'no'
       
   283 
       
   284 >>> q.get('foo', 'default')
       
   285 'default'
       
   286 
       
   287 >>> q.getlist('vote')
       
   288 ['yes', 'no']
       
   289 
       
   290 >>> q.getlist('foo')
       
   291 []
       
   292 
       
   293 >>> q.setlist('foo', ['bar', 'baz'])
       
   294 Traceback (most recent call last):
       
   295 ...
       
   296 AttributeError: This QueryDict instance is immutable
       
   297 
       
   298 >>> q.appendlist('foo', ['bar'])
       
   299 Traceback (most recent call last):
       
   300 ...
       
   301 AttributeError: This QueryDict instance is immutable
       
   302 
       
   303 >>> q.has_key('vote')
       
   304 True
       
   305 
       
   306 >>> q.has_key('foo')
       
   307 False
       
   308 
       
   309 >>> q.items()
       
   310 [('vote', 'no')]
       
   311 
       
   312 >>> q.lists()
       
   313 [('vote', ['yes', 'no'])]
       
   314 
       
   315 >>> q.keys()
       
   316 ['vote']
       
   317 
       
   318 >>> q.values()
       
   319 ['no']
       
   320 
       
   321 >>> len(q)
       
   322 1
       
   323 
       
   324 >>> q.update({'foo': 'bar'})
       
   325 Traceback (most recent call last):
       
   326 ...
       
   327 AttributeError: This QueryDict instance is immutable
       
   328 
       
   329 >>> q.pop('foo')
       
   330 Traceback (most recent call last):
       
   331 ...
       
   332 AttributeError: This QueryDict instance is immutable
       
   333 
       
   334 >>> q.popitem()
       
   335 Traceback (most recent call last):
       
   336 ...
       
   337 AttributeError: This QueryDict instance is immutable
       
   338 
       
   339 >>> q.clear()
       
   340 Traceback (most recent call last):
       
   341 ...
       
   342 AttributeError: This QueryDict instance is immutable
       
   343 
       
   344 >>> q.setdefault('foo', 'bar')
       
   345 Traceback (most recent call last):
       
   346 ...
       
   347 AttributeError: This QueryDict instance is immutable
       
   348 
       
   349 >>> q.urlencode()
       
   350 'vote=yes&vote=no'
       
   351 
       
   352 """
       
   353 
       
   354 from django.http import QueryDict
       
   355 
       
   356 if __name__ == "__main__":
       
   357     import doctest
       
   358     doctest.testmod()