'An API request to update a named container\'s host to a different host
results in an updated configuration.'

def test_update_new_host(self):

    d = self._create_container()
    d.addCallback((lambda _: self.persistence_service.get()))
    def handle_expected(expected):
        dr = self.assertResponseCode('POST', '/configuration/containers/mycontainer', {u'node_uuid': self.NODE_B}, OK)
        def updated(_):
            deployment = self.persistence_service.get()
            application = Application(name=u'mycontainer', image=DockerImage.from_string(u'busybox'))
            real_expected = expected
            for node in expected.nodes.values():
                if (node.uuid == self.NODE_B_UUID):
                    node = node.transform(['applications'], (lambda s: s.set(application.name, application)))
                else:
                    node = node.transform(['applications'], (lambda s: s.remove(application.name)))
                real_expected = real_expected.update_node(node)
            self.assertEqual(deployment, real_expected)
        dr.addCallback(updated)
        return dr
    d.addCallback(handle_expected)
    return d
