Exemplo n.º 1
0
    def test_request_NoUsername_AuthenticationNotSet(self):

        expectedResult = ("text", 123)
        arguments = {'something': 'whatever'}
        postData = 'blah blah'
        server = Server('host', '', 'password anyway')

        mocks = mox.Mox()
        urlBuilder = mocks.CreateMock(IUrlBuilder)
        urlBuilderFactory = mocks.CreateMock(IUrlBuilderFactory)
        request = mocks.CreateMock(IRequest)
        requestFactory = mocks.CreateMock(IRequestFactory)

        urlBuilderFactory.create().AndReturn(urlBuilder)
        urlBuilder.build('host', 'path', arguments).AndReturn('full url')

        requestFactory.create('full url').AndReturn(request)
        request.request(postData).AndReturn(expectedResult)

        mocks.ReplayAll()

        http = Http(server, urlBuilderFactory, requestFactory)
        http.request('path', arguments, postData)

        mox.Verify(request)
Exemplo n.º 2
0
    def test_request_WellBehavedFactories_ReturnRequestOpenResult(self):

        expectedResult = ("text", 123)
        arguments = {'something': 'whatever'}
        postData = 'blah blah'
        server = Server('host', 'blah', 'blah')

        mocks = mox.Mox()
        urlBuilder = mocks.CreateMock(IUrlBuilder)
        urlBuilderFactory = mocks.CreateMock(IUrlBuilderFactory)
        request = mocks.CreateMock(IRequest)
        requestFactory = mocks.CreateMock(IRequestFactory)

        urlBuilderFactory.create().AndReturn(urlBuilder)
        urlBuilder.build('host', 'path', arguments).AndReturn('full url')

        requestFactory.create('full url').AndReturn(request)
        request.setBasicAuthorisation(mox.IgnoreArg(), mox.IgnoreArg()).InAnyOrder()
        request.request(postData).InAnyOrder().AndReturn(expectedResult)

        mocks.ReplayAll()

        http = Http(server, urlBuilderFactory, requestFactory)
        result = http.request('path', arguments, postData)

        self.assertEqual(expectedResult, result)
Exemplo n.º 3
0
    def test_request_NoUsername_AuthenticationNotSet(self):

        expectedResult = ("text", 123)
        arguments = {'something': 'whatever'}
        postData = 'blah blah'
        server = Server('host', '', 'password anyway')

        mocks = mox.Mox()
        urlBuilder = mocks.CreateMock(IUrlBuilder)
        urlBuilderFactory = mocks.CreateMock(IUrlBuilderFactory)
        request = mocks.CreateMock(IRequest)
        requestFactory = mocks.CreateMock(IRequestFactory)

        urlBuilderFactory.create().AndReturn(urlBuilder)
        urlBuilder.build('host', 'path', arguments).AndReturn('full url')

        requestFactory.create('full url').AndReturn(request)
        request.request(postData).AndReturn(expectedResult)

        mocks.ReplayAll()

        http = Http(server, urlBuilderFactory, requestFactory)
        http.request('path', arguments, postData)

        mox.Verify(request)
Exemplo n.º 4
0
    def test_request_WellBehavedFactories_ReturnRequestOpenResult(self):

        expectedResult = ("text", 123)
        arguments = {'something': 'whatever'}
        postData = 'blah blah'
        server = Server('host', 'blah', 'blah')

        mocks = mox.Mox()
        urlBuilder = mocks.CreateMock(IUrlBuilder)
        urlBuilderFactory = mocks.CreateMock(IUrlBuilderFactory)
        request = mocks.CreateMock(IRequest)
        requestFactory = mocks.CreateMock(IRequestFactory)

        urlBuilderFactory.create().AndReturn(urlBuilder)
        urlBuilder.build('host', 'path', arguments).AndReturn('full url')

        requestFactory.create('full url').AndReturn(request)
        request.setBasicAuthorisation(mox.IgnoreArg(),
                                      mox.IgnoreArg()).InAnyOrder()
        request.request(postData).InAnyOrder().AndReturn(expectedResult)

        mocks.ReplayAll()

        http = Http(server, urlBuilderFactory, requestFactory)
        result = http.request('path', arguments, postData)

        self.assertEqual(expectedResult, result)
Exemplo n.º 5
0
 def create(self, server):
     """
     @type server: pyjenkins.server.Server
     @rtype: pyjenkins.jenkins.Jenkins
     """
     return Jenkins(Http(server))