<s> import uuid <EOL> from ooi . tests import fakes <EOL> from ooi . tests . middleware import test_middleware <EOL> from ooi import utils <EOL> def build_occi_network ( pool_name ) : <EOL> cats = [ ] <EOL> cats . append ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % fakes . application_url ) <EOL> cats . append ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> attrs = [ <EOL> '<STR_LIT>' % pool_name , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % pool_name , <EOL> ] <EOL> links = [ ] <EOL> links . append ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( fakes . application_url , pool_name ) ) <EOL> links . append ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( fakes . application_url , pool_name ) ) <EOL> result = [ ] <EOL> for c in cats : <EOL> result . append ( ( "<STR_LIT>" , c ) ) <EOL> for l in links : <EOL> result . append ( ( "<STR_LIT>" , l ) ) <EOL> for a in attrs : <EOL> result . append ( ( "<STR_LIT>" , a ) ) <EOL> return result <EOL> class TestNetworkController ( test_middleware . TestMiddleware ) : <EOL> """<STR_LIT>""" <EOL> def test_list_pools_empty ( self ) : <EOL> tenant = fakes . tenants [ "<STR_LIT:bar>" ] <EOL> app = self . get_app ( ) <EOL> for url in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> req = self . _build_req ( url , tenant [ "<STR_LIT:id>" ] , method = "<STR_LIT:GET>" ) <EOL> req . environ [ "<STR_LIT>" ] = tenant [ "<STR_LIT:id>" ] <EOL> resp = req . get_response ( app ) <EOL> resp = req . get_response ( app ) <EOL> expected = [ <EOL> ( "<STR_LIT>" , <EOL> utils . join_url ( self . application_url + "<STR_LIT:/>" , "<STR_LIT>" ) ) <EOL> ] <EOL> self . assertDefaults ( resp ) <EOL> self . assertExpectedResult ( expected , resp ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> def test_list_pools ( self ) : <EOL> tenant = fakes . tenants [ "<STR_LIT:foo>" ] <EOL> app = self . get_app ( ) <EOL> for url in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> req = self . _build_req ( url , tenant [ "<STR_LIT:id>" ] , method = "<STR_LIT:GET>" ) <EOL> resp = req . get_response ( app ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> expected = [ <EOL> ( "<STR_LIT>" , <EOL> utils . join_url ( self . application_url + "<STR_LIT:/>" , "<STR_LIT>" ) ) <EOL> ] <EOL> if fakes . pools [ tenant [ "<STR_LIT:id>" ] ] : <EOL> expected . append ( <EOL> ( "<STR_LIT>" , <EOL> utils . join_url ( self . application_url + "<STR_LIT:/>" , <EOL> "<STR_LIT>" ) ) <EOL> ) <EOL> self . assertDefaults ( resp ) <EOL> self . assertExpectedResult ( expected , resp ) <EOL> def test_show_floating_pool ( self ) : <EOL> tenant = fakes . tenants [ "<STR_LIT:foo>" ] <EOL> app = self . get_app ( ) <EOL> for pool in fakes . pools [ tenant [ "<STR_LIT:id>" ] ] : <EOL> req = self . _build_req ( "<STR_LIT>" , tenant [ "<STR_LIT:id>" ] , <EOL> method = "<STR_LIT:GET>" ) <EOL> resp = req . get_response ( app ) <EOL> expected = build_occi_network ( "<STR_LIT>" ) <EOL> self . assertDefaults ( resp ) <EOL> self . assertExpectedResult ( expected , resp ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> def test_show_fixed ( self ) : <EOL> tenant = fakes . tenants [ "<STR_LIT:foo>" ] <EOL> app = self . get_app ( ) <EOL> req = self . _build_req ( "<STR_LIT>" , tenant [ "<STR_LIT:id>" ] , method = "<STR_LIT:GET>" ) <EOL> resp = req . get_response ( app ) <EOL> expected = build_occi_network ( "<STR_LIT>" ) <EOL> self . assertDefaults ( resp ) <EOL> self . assertExpectedResult ( expected , resp ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> def test_pool_not_found ( self ) : <EOL> tenant = fakes . tenants [ "<STR_LIT:foo>" ] <EOL> app = self . get_app ( ) <EOL> req = self . _build_req ( "<STR_LIT>" % uuid . uuid4 ( ) . hex , <EOL> tenant [ "<STR_LIT:id>" ] , method = "<STR_LIT:GET>" ) <EOL> resp = req . get_response ( app ) <EOL> self . assertEqual ( <NUM_LIT> , resp . status_code ) <EOL> class NetworkControllerTextPlain ( test_middleware . TestMiddlewareTextPlain , <EOL> TestNetworkController ) : <EOL> """<STR_LIT>""" <EOL> class NetworkControllerTextOcci ( test_middleware . TestMiddlewareTextOcci , <EOL> TestNetworkController ) : <EOL> """<STR_LIT>""" </s>
