'An ``Application`` with ``Environment`` and ``Link`` objects is
discovered from a ``Unit`` with both custom environment variables and
environment variables representing container links. The environment
variables taking the format <ALIAS>_PORT_<PORT>_TCP are separated in
to ``Link`` representations in the ``Application``.'

def test_discover_application_with_environment_and_links(self):

    environment_variables = (('CUSTOM_ENV_A', 'a    value'), ('CUSTOM_ENV_B', 'something    else'))
    link_environment_variables = (('APACHE_PORT_80_TCP', 'tcp://example.com:8080'), ('APACHE_PORT_80_TCP_PROTO', 'tcp'), ('APACHE_PORT_80_TCP_ADDR', 'example.com'), ('APACHE_PORT_80_TCP_PORT', '8080'))
    unit_environment = (environment_variables + link_environment_variables)
    environment = Environment(variables=frozenset(unit_environment))
    unit1 = UNIT_FOR_APP.set('environment', environment)
    units = {unit1.name: unit1}
    links = [Link(local_port=80, remote_port=8080, alias=u'APACHE')]
    applications = [APP.set('links', links).set('environment', dict(environment_variables))]
    self._verify_discover_state_applications(units, applications)
