'An ``Application`` running on a given node that has different port
exposures specified in the desired state to the ports exposed by the
application\'s current state is added to the list of applications to
restart.'

def test_app_with_changed_ports_restarted(self):

    api = ApplicationNodeDeployer(u'node1.example.com', docker_client=FakeDockerClient())
    old_postgres_app = Application(name=u'postgres-example', image=DockerImage.from_string(u'clusterhq/postgres:latest'), volume=None, ports=frozenset([Port(internal_port=5432, external_port=50432)]))
    new_postgres_app = Application(name=u'postgres-example', image=DockerImage.from_string(u'clusterhq/postgres:latest'), volume=None, ports=frozenset([Port(internal_port=5433, external_port=50433)]))
    node_state = NodeState(hostname=api.hostname, applications={old_postgres_app})
    desired = Deployment(nodes=frozenset({Node(hostname=api.hostname, applications=frozenset({new_postgres_app}))}))
    result = api.calculate_changes(desired_configuration=desired, current_cluster_state=DeploymentState(nodes={node_state}), local_state=NodeLocalState(node_state=node_state))
    expected = sequentially(changes=[in_parallel(changes=[sequentially(changes=[StopApplication(application=old_postgres_app), StartApplication(application=new_postgres_app, node_state=node_state)])])])
    self.assertEqual(expected, result)
