def testCreateHttpConn_Basic(self, mockAuth): mockAuth.get().get_auth_header.return_value = None conn = gerrit_util.CreateHttpConn('host.example.com', 'foo/bar') self.assertEqual('host.example.com', conn.req_host) self.assertEqual( { 'uri': 'https://host.example.com/foo/bar', 'method': 'GET', 'headers': {}, 'body': None, }, conn.req_params)
def createProject(cls, name, description='Test project', owners=None, submit_type='CHERRY_PICK'): """Create a project on the test gerrit server.""" if owners is None: owners = ['Administrators'] body = { 'description': description, 'submit_type': submit_type, 'owners': owners, } path = 'projects/%s' % urllib.quote(name, '') conn = gerrit_util.CreateHttpConn( cls.gerrit_instance.gerrit_host, path, reqtype='PUT', body=body) jmsg = gerrit_util.ReadHttpJsonResponse(conn, accept_statuses=[200, 201]) assert jmsg['name'] == name
def testCreateHttpConn_Authenticated(self, mockAuth): mockAuth.get().get_auth_header.return_value = 'Bearer token' conn = gerrit_util.CreateHttpConn('host.example.com', 'foo/bar', headers={'header': 'value'}) self.assertEqual('host.example.com', conn.req_host) self.assertEqual( { 'uri': 'https://host.example.com/a/foo/bar', 'method': 'GET', 'headers': { 'Authorization': 'Bearer token', 'header': 'value' }, 'body': None, }, conn.req_params)
def testCreateHttpConn_Body(self, mockAuth): mockAuth.get().get_auth_header.return_value = None conn = gerrit_util.CreateHttpConn('host.example.com', 'foo/bar', body={ 'l': [1, 2, 3], 'd': { 'k': 'v' } }) self.assertEqual('host.example.com', conn.req_host) self.assertEqual( { 'uri': 'https://host.example.com/foo/bar', 'method': 'GET', 'headers': { 'Content-Type': 'application/json' }, 'body': '{"d": {"k": "v"}, "l": [1, 2, 3]}', }, conn.req_params)