'A valid API request to create a container including port mappings
results in an updated configuration.'

def test_create_container_with_ports(self):

    saving = self.persistence_service.save(Deployment(nodes={Node(uuid=self.NODE_A_UUID, applications={u'postgres': Application(name=u'postgres', image=DockerImage.from_string('postgres'))}), Node(uuid=self.NODE_B_UUID)}))
    ports = [{'internal': 5432, 'external': 54320}]
    saving.addCallback((lambda _: self.assertResponseCode('POST', '/configuration/containers', {u'node_uuid': self.NODE_A, u'name': u'another_postgres', u'image': u'postgres', u'ports': ports}, CREATED)))
    def created(_):
        application_ports = [Port(internal_port=5432, external_port=54320)]
        deployment = self.persistence_service.get()
        expected = Deployment(nodes={Node(uuid=self.NODE_A_UUID, applications={a.name: a for a in [Application(name=u'postgres', image=DockerImage.from_string('postgres')), Application(name=u'another_postgres', image=DockerImage.from_string('postgres'), ports=frozenset(application_ports))]}), Node(uuid=self.NODE_B_UUID)})
        self.assertEqual(deployment, expected)
    saving.addCallback(created)
    return saving
