Revision 33231500 test/ganeti.http_unittest.py

b/test/ganeti.http_unittest.py
87 87
    self.assert_(message_reader_class.START_LINE_LENGTH_MAX > 0)
88 88
    self.assert_(message_reader_class.HEADER_LENGTH_MAX > 0)
89 89

  
90
  def testClientSizeLimits(self):
91
    """Test HTTP client size limits"""
92
    message_reader_class = http.client._HttpServerToClientMessageReader
93
    self.assert_(message_reader_class.START_LINE_LENGTH_MAX > 0)
94
    self.assert_(message_reader_class.HEADER_LENGTH_MAX > 0)
95

  
96 90
  def testFormatAuthHeader(self):
97 91
    self.assertEqual(http.auth._FormatAuthHeader("Basic", {}),
98 92
                     "Basic")
......
330 324
    self.assertEqual(users["user2"].options, ["write", "read"])
331 325

  
332 326

  
327
class TestClientRequest(unittest.TestCase):
328
  def testRepr(self):
329
    cr = http.client.HttpClientRequest("localhost", 1234, "GET", "/version",
330
                                       headers=[], post_data="Hello World")
331
    self.assert_(repr(cr).startswith("<"))
332

  
333
  def testNoHeaders(self):
334
    cr = http.client.HttpClientRequest("localhost", 1234, "GET", "/version",
335
                                       headers=None)
336
    self.assert_(isinstance(cr.headers, list))
337
    self.assertEqual(cr.headers, [])
338
    self.assertEqual(cr.url, "https://localhost:1234/version")
339

  
340
  def testOldStyleHeaders(self):
341
    headers = {
342
      "Content-type": "text/plain",
343
      "Accept": "text/html",
344
      }
345
    cr = http.client.HttpClientRequest("localhost", 16481, "GET", "/vg_list",
346
                                       headers=headers)
347
    self.assert_(isinstance(cr.headers, list))
348
    self.assertEqual(sorted(cr.headers), [
349
      "Accept: text/html",
350
      "Content-type: text/plain",
351
      ])
352
    self.assertEqual(cr.url, "https://localhost:16481/vg_list")
353

  
354
  def testNewStyleHeaders(self):
355
    headers = [
356
      "Accept: text/html",
357
      "Content-type: text/plain; charset=ascii",
358
      "Server: httpd 1.0",
359
      ]
360
    cr = http.client.HttpClientRequest("localhost", 1234, "GET", "/version",
361
                                       headers=headers)
362
    self.assert_(isinstance(cr.headers, list))
363
    self.assertEqual(sorted(cr.headers), sorted(headers))
364
    self.assertEqual(cr.url, "https://localhost:1234/version")
365

  
366
  def testPostData(self):
367
    cr = http.client.HttpClientRequest("localhost", 1234, "GET", "/version",
368
                                       post_data="Hello World")
369
    self.assertEqual(cr.post_data, "Hello World")
370

  
371
  def testNoPostData(self):
372
    cr = http.client.HttpClientRequest("localhost", 1234, "GET", "/version")
373
    self.assertEqual(cr.post_data, "")
374

  
375
  def testIdentity(self):
376
    # These should all use different connections, hence also have a different
377
    # identity
378
    cr1 = http.client.HttpClientRequest("localhost", 1234, "GET", "/version")
379
    cr2 = http.client.HttpClientRequest("localhost", 9999, "GET", "/version")
380
    cr3 = http.client.HttpClientRequest("node1", 1234, "GET", "/version")
381
    cr4 = http.client.HttpClientRequest("node1", 9999, "GET", "/version")
382

  
383
    self.assertEqual(len(set([cr1.identity, cr2.identity,
384
                              cr3.identity, cr4.identity])), 4)
385

  
386
    # But this one should have the same
387
    cr1vglist = http.client.HttpClientRequest("localhost", 1234,
388
                                              "GET", "/vg_list")
389
    self.assertEqual(cr1.identity, cr1vglist.identity)
390

  
391

  
392
class TestClient(unittest.TestCase):
393
  def test(self):
394
    pool = http.client.HttpClientPool(None)
395
    self.assertFalse(pool._pool)
396

  
397

  
333 398
if __name__ == '__main__':
334 399
  testutils.GanetiTestProgram()

Also available in: Unified diff