<s> from rest_framework import test , status <EOL> from nodeconductor . openstack . tests import factories <EOL> from nodeconductor . structure import models <EOL> from nodeconductor . structure . tests import factories as structure_factories <EOL> class FloatingIPListRetreiveTestCase ( test . APITransactionTestCase ) : <EOL> def setUp ( self ) : <EOL> self . customer = structure_factories . CustomerFactory ( ) <EOL> self . project = structure_factories . ProjectFactory ( customer = self . customer ) <EOL> self . service = factories . OpenStackServiceFactory ( customer = self . customer ) <EOL> self . service_project_link = factories . OpenStackServiceProjectLinkFactory ( service = self . service , project = self . project ) <EOL> self . active_ip = factories . FloatingIPFactory ( status = '<STR_LIT>' , service_project_link = self . service_project_link ) <EOL> self . down_ip = factories . FloatingIPFactory ( status = '<STR_LIT>' , service_project_link = self . service_project_link ) <EOL> self . other_ip = factories . FloatingIPFactory ( status = '<STR_LIT>' ) <EOL> self . staff = structure_factories . UserFactory ( is_staff = True ) <EOL> self . owner = structure_factories . UserFactory ( ) <EOL> self . customer . add_user ( self . owner , models . CustomerRole . OWNER ) <EOL> self . admin = structure_factories . UserFactory ( ) <EOL> self . project . add_user ( self . admin , models . ProjectRole . ADMINISTRATOR ) <EOL> self . user = structure_factories . UserFactory ( ) <EOL> def test_floating_ip_list_can_be_filtered_by_project ( self ) : <EOL> data = { <EOL> '<STR_LIT>' : self . project . uuid . hex , <EOL> } <EOL> self . client . force_authenticate ( self . staff ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_list_url ( ) , data ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> response_ip_uuids = [ ip [ '<STR_LIT>' ] for ip in response . data ] <EOL> expected_ip_uuids = [ ip . uuid . hex for ip in ( self . active_ip , self . down_ip ) ] <EOL> self . assertItemsEqual ( response_ip_uuids , expected_ip_uuids ) <EOL> def test_floating_ip_list_can_be_filtered_by_service ( self ) : <EOL> data = { <EOL> '<STR_LIT>' : self . service . uuid . hex , <EOL> } <EOL> self . client . force_authenticate ( self . staff ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_list_url ( ) , data ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> response_ip_uuids = [ ip [ '<STR_LIT>' ] for ip in response . data ] <EOL> expected_ip_uuids = [ ip . uuid . hex for ip in ( self . active_ip , self . down_ip ) ] <EOL> self . assertItemsEqual ( response_ip_uuids , expected_ip_uuids ) <EOL> def test_floating_ip_list_can_be_filtered_by_status ( self ) : <EOL> data = { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> } <EOL> self . client . force_authenticate ( self . staff ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_list_url ( ) , data ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> response_ip_uuids = [ ip [ '<STR_LIT>' ] for ip in response . data ] <EOL> expected_ip_uuids = [ self . active_ip . uuid . hex ] <EOL> self . assertItemsEqual ( response_ip_uuids , expected_ip_uuids ) <EOL> def test_admin_receive_only_ips_from_his_project ( self ) : <EOL> self . client . force_authenticate ( self . admin ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_list_url ( ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> response_ip_uuids = [ ip [ '<STR_LIT>' ] for ip in response . data ] <EOL> expected_ip_uuids = [ ip . uuid . hex for ip in ( self . active_ip , self . down_ip ) ] <EOL> self . assertItemsEqual ( response_ip_uuids , expected_ip_uuids ) <EOL> def test_owner_receive_only_ips_from_his_customer ( self ) : <EOL> self . client . force_authenticate ( self . owner ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_list_url ( ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> response_ip_uuids = [ ip [ '<STR_LIT>' ] for ip in response . data ] <EOL> expected_ip_uuids = [ ip . uuid . hex for ip in ( self . active_ip , self . down_ip ) ] <EOL> self . assertItemsEqual ( response_ip_uuids , expected_ip_uuids ) <EOL> def test_regular_user_does_not_receive_any_ips ( self ) : <EOL> self . client . force_authenticate ( self . user ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_list_url ( ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> response_ip_uuids = [ ip [ '<STR_LIT>' ] for ip in response . data ] <EOL> expected_ip_uuids = [ ] <EOL> self . assertItemsEqual ( response_ip_uuids , expected_ip_uuids ) <EOL> def test_admin_can_retreive_floating_ip_from_his_project ( self ) : <EOL> self . client . force_authenticate ( self . admin ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_url ( self . active_ip ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertItemsEqual ( response . data [ '<STR_LIT>' ] , self . active_ip . uuid . hex ) <EOL> def test_owner_can_not_retreive_floating_ip_not_from_his_customer ( self ) : <EOL> self . client . force_authenticate ( self . owner ) <EOL> response = self . client . get ( factories . FloatingIPFactory . get_url ( self . other_ip ) ) <EOL> self . assertEqual ( response . status_code , status . HTTP_404_NOT_FOUND ) </s>
