コード例 #1
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_external_basic_auth_handler1(self):
     """test external basic auth handler"""
     handler = self._setup_ext_basic_auth_handler('http://localhost', 'foo',
                                                  'bar')
     r = Urllib2HTTPRequest('http://localhost', handlers=[handler])
     resp = r.get('/test')
     self.assertEqual(resp.read(), 'foo')
コード例 #2
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test4(self):
     """simple get with response validation (validation fails)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     self.assertRaises(etree.DocumentInvalid,
                       r.get,
                       '/source',
                       schema=self.fixture_file('directory.xsd'))
コード例 #3
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test19(self):
     """test content type (PUT)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.put('/source/prj/_meta',
                  data='<xml/>',
                  content_type='application/xml')
     self.assertEqual(resp.read(), 'foobar')
コード例 #4
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_basic_auth_handler6(self):
     """send credentials, if the redirect location's host did not change"""
     r = Urllib2HTTPRequest('http://localhost',
                            username='******',
                            password='******')
     resp = r.get('/test')
     self.assertEqual(resp.read(), 'foo')
コード例 #5
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_basic_auth_handler7(self):
     """test a https request"""
     r = Urllib2HTTPRequest('https://localhost',
                            username='******',
                            password='******')
     resp = r.get('/test')
     self.assertEqual(resp.read(), 'foo')
コード例 #6
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_basic_auth_handler5(self):
     """do not send credentials to an arbitrary redirect location"""
     r = Urllib2HTTPRequest('http://localhost',
                            username='******',
                            password='******')
     resp = r.get('/test')
     self.assertEqual(resp.read(), 'foo')
コード例 #7
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_basic_auth_handler4(self):
     """do not send credentials to an arbitrary host"""
     r = Urllib2HTTPRequest('http://localhost',
                            username='******',
                            password='******')
     resp = r.get('/source', apiurl='http://api.opensuse.org')
     self.assertEqual(resp.read(), 'foo')
コード例 #8
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_basic_auth_handler1(self):
     """test the default basic auth handler"""
     r = Urllib2HTTPRequest('http://localhost',
                            username='******',
                            password='******')
     resp = r.get('/test')
     self.assertEqual(resp.read(), 'foo')
コード例 #9
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test11(self):
     """test response object"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.get('source')
     self.assertEqual(resp.url, 'http://localhost/source')
     self.assertEqual(resp.code, 200)
     self.assertEqual(resp.headers.get('header1'), 'foo')
     self.assertEqual(resp.headers['x'], '42')
コード例 #10
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_basic_auth_handler3(self):
     """always send credentials (even if a cookie is used)"""
     r = Urllib2HTTPRequest('http://api.opensuse.org',
                            username='******',
                            password='******',
                            cookie_filename=self.fixture_file('cookie'))
     resp = r.get('/source')
     self.assertEqual(resp.read(), 'foo')
コード例 #11
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test14(self):
     """test exception handling (check exception object)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     with self.assertRaises(HTTPError) as cm:
         r.get('/source')
     self.assertEqual(cm.exception.url, 'http://localhost/source')
     self.assertEqual(cm.exception.code, 403)
     self.assertEqual(cm.exception.headers['foo'], 'bar')
     self.assertIsNotNone(cm.exception.orig_exc)
コード例 #12
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test21(self):
     """test content type and urlencoded (POST)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     self.assertRaises(ValueError,
                       r.post,
                       '/source',
                       data='bar',
                       content_type='foo',
                       urlencoded=True)
コード例 #13
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test6(self):
     """simple put (filename, uses mmap)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False,
                            True, 20)
     resp = r.put('/source/foo/bar/file',
                  filename=self.fixture_file('putfile'),
                  x='foo bar',
                  foo='bar')
     self.assertEqual(resp.read(), 'ok')
     self.assertIsNone(resp._sio)
コード例 #14
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test23(self):
     """test ignore empty query keys"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.get('/test',
                  binary=['', 'foo'],
                  test='4',
                  x='',
                  y=None,
                  z=[''],
                  a=['', None])
     self.assertEqual(resp.read(), 'foo')
コード例 #15
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test9(self):
     """simple post (filename, uses mmap) - validation fails"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False,
                            True, 20)
     self.assertRaises(etree.DocumentInvalid,
                       r.post,
                       '/source/foo/bar/file',
                       filename=self.fixture_file('putfile'),
                       schema=self.fixture_file('directory.xsd'),
                       x='foo bar',
                       foo='bar')
コード例 #16
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test8(self):
     """simple post (filename, uses mmap) - validate response"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False,
                            True, 20)
     resp = r.post('/source/foo/bar/file',
                   filename=self.fixture_file('putfile'),
                   schema=self.fixture_file('directory.xsd'),
                   x='foo bar',
                   foo='bar')
     self.assertEqual(resp.read(), self.read_file('prj_list.xml'))
     self.assertIsNotNone(resp._sio)
コード例 #17
0
ファイル: test_httprequest.py プロジェクト: vikas-lamba/osc2
 def test_external_basic_auth_handler2(self):
     """test external + default basic auth handler (pathological case)"""
     # the default basic auth handler does not override an existing
     # Authorization header
     handler = self._setup_ext_basic_auth_handler('http://localhost', 'foo',
                                                  'foobar')
     r = Urllib2HTTPRequest('http://localhost',
                            username='******',
                            password='******',
                            handlers=[handler])
     resp = r.get('/test')
     self.assertEqual(resp.read(), 'foo')
コード例 #18
0
 def __init__(self,
              apiurl,
              username='',
              password='',
              request_object=None,
              debug=False,
              validate=True):
     super(Osc, self).__init__()
     if username and request_object is not None:
         raise ValueError('either specify username or request_object')
     self.request_object = request_object
     if request_object is None:
         self.request_object = Urllib2HTTPRequest(apiurl,
                                                  username=username,
                                                  password=password,
                                                  validate=validate,
                                                  debug=debug)
     Osc._osc = self
コード例 #19
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test16(self):
     """test optional apiurl (DELETE)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.delete('/source', apiurl='http://api')
     self.assertEqual(resp.read(), 'foobar')
コード例 #20
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test10(self):
     """simple delete"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.delete('/source/project')
     self.assertEqual(resp.read(), 'foobar')
     self.assertIsNone(resp._sio)
コード例 #21
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test7(self):
     """simple post (urlencoded data)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.post('/dummy', data='simple text', urlencoded=True)
     self.assertEqual(resp.read(), 'ok')
     self.assertIsNone(resp._sio)
コード例 #22
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test12(self):
     """test exception handling (get)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     self.assertRaises(HTTPError, r.get, 'source')
コード例 #23
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test5(self):
     """simple put"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.put('/source/foo/bar/file', data='this is a test')
     self.assertEqual(resp.read(), 'ok')
     self.assertIsNone(resp._sio)
コード例 #24
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test2(self):
     """simple get with query"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.get('/source/server:mail', foo='bar', esc='foo&bar')
     self.assertEqual(resp.read(), 'foobar')
     self.assertIsNone(resp._sio)
コード例 #25
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test3(self):
     """simple get with response validation"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.get('/source', schema=self.fixture_file('directory.xsd'))
     self.assertEqual(resp.read(), self.read_file('prj_list.xml'))
     self.assertIsNotNone(resp._sio)
コード例 #26
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test13(self):
     """test exception handling (put)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     self.assertRaises(HTTPError, r.put, 'source', data='foo bar')
コード例 #27
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test22(self):
     """test use same query parameter more than once"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.get('/test', binary=['foo', 'bar', 'foobar'], other='ok')
     self.assertEqual(resp.read(), 'foobar')
コード例 #28
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test_1(self):
     """simple get"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.get('/source')
     self.assertEqual(resp.read(), 'foobar')
     self.assertIsNone(resp._sio)
コード例 #29
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test18(self):
     """test optional apiurl (PUT)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.put('/source', data='foo', apiurl='http://url')
     self.assertEqual(resp.read(), 'foobar')
コード例 #30
0
ファイル: test_httprequest.py プロジェクト: pombreda/osc2
 def test20(self):
     """test content type (POST)"""
     r = Urllib2HTTPRequest('http://localhost', True, '', '', '', False)
     resp = r.put('/source', data='asdf', content_type='foo')
     self.assertEqual(resp.read(), 'foobar')