twisted.web.client.FileBodyProducer - python examples

Here are the examples of the python api twisted.web.client.FileBodyProducer taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

26 Examples 7

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume(self):
        name = 'test-create-volume'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": None}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_size_option(self):
        name = 'test-create-volume'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"size": u"50"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_provisioning_option(self):
        name = 'test-create-volume'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"provisioning": u"full"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_invalid_provisioning_option(self):
        name = 'test-create-volume-fake'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"provisioning": u"fake"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({
            u"Err": "Invalid input received: Must specify a valid " +
            "provisioning type ['thin', 'full', " +
            "'dedup'], value 'fake' is invalid."}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def test_hpe_create_volume_invalid_option(self):
        name = 'test-create-volume-fake'
        path = b"/VolumeDriver.Create"
        body = {u"Name": name,
                u"Opts": {u"fake": u"fake"}}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({
            u"Err": "create volume failed, error is: fake is not a valid "
            "option. Valid options are: ['size', 'provisioning', "
            "'flash-cache']"}))
        d.addCallback(self._remove_volume_callback, name)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def _remove_volume(self, name):
        path = b"/VolumeDriver.Remove"
        body = {u"Name": name}

        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def _get_volume_mount_path(self, body, name):
        # NOTE: body arg is the result from last deferred call.
        # Python complains about parameter mis-match if you don't include it
        # In this test, we need it to compare expected results with Path
        # request

        # Compare path returned by mount (body) with Get Path request
        path = b"/VolumeDriver.Path"
        newbody = {u"Name": name}
        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(newbody)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, body)
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def _unmount_the_volume(self, body, name):
        # NOTE: body arg is the result from last deferred call.
        # Python complains about parameter mis-match if you don't include it
        path = b"/VolumeDriver.Unmount"
        newbody = {u"Name": name}
        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(newbody)))

        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
        d.addErrback(self.cbFailed)
        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def _get_volume(self, body, name, expected):
        path = b"/VolumeDriver.Get"
        body = {u"Name": name}

        # Get a volume
        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps(body)))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps(expected))
        d.addErrback(self.cbFailed)

        return d

3 View Complete Implementation : test_hpe_plugin.py
Copyright Apache License 2.0
Author : hpe-storage
    def broken_test_hpe_list_volume_no_volumes(self):
        path = b"/VolumeDriver.List"

        # Create a volume to be mounted
        headers = Headers({b"content-type": [b"application/json"]})
        body_producer = FileBodyProducer(BytesIO(dumps({})))
        agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
        d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
                          body_producer)
        d.addCallback(self.checkResponse, json.dumps({u"Err": '',
                                                      u"Volumes": []}))
        d.addErrback(self.cbFailed)

        return d