2121from openstackclient .tests .unit .identity .v3 import fakes as identity_fakes
2222
2323
24- class TestEndpoint (identity_fakes .TestIdentity ):
25- def setUp (self ):
26- super ().setUp ()
27-
28- # Get a shortcut to the EndpointManager Mock
29- self .endpoints_mock = self .identity_client .endpoints
30- self .endpoints_mock .reset_mock ()
31- self .ep_filter_mock = self .identity_client .endpoint_filter
32- self .ep_filter_mock .reset_mock ()
33-
34- # Get a shortcut to the ServiceManager Mock
35- self .services_mock = self .identity_client .services
36- self .services_mock .reset_mock ()
37-
38- # Get a shortcut to the DomainManager Mock
39- self .domains_mock = self .identity_client .domains
40- self .domains_mock .reset_mock ()
41-
42- # Get a shortcut to the ProjectManager Mock
43- self .projects_mock = self .identity_client .projects
44- self .projects_mock .reset_mock ()
45-
46-
4724class TestEndpointCreate (identity_fakes .TestIdentity ):
4825 columns = (
4926 'enabled' ,
@@ -767,28 +744,21 @@ def setUp(self):
767744 self .cmd = endpoint .ShowEndpoint (self .app , None )
768745
769746
770- class TestAddProjectToEndpoint (TestEndpoint ):
771- project = identity_fakes .FakeProject .create_one_project ()
772- domain = identity_fakes .FakeDomain .create_one_domain ()
773- service = identity_fakes .FakeService .create_one_service ()
774- endpoint = identity_fakes .FakeEndpoint .create_one_endpoint (
775- attrs = {'service_id' : service .id }
776- )
777-
778- new_ep_filter = identity_fakes .FakeEndpoint .create_one_endpoint_filter (
779- attrs = {'endpoint' : endpoint .id , 'project' : project .id }
780- )
781-
747+ class TestAddProjectToEndpoint (identity_fakes .TestIdentity ):
782748 def setUp (self ):
783749 super ().setUp ()
784750
785- # This is the return value for utils.find_resource()
786- self .endpoints_mock .get .return_value = self .endpoint
751+ self .project = sdk_fakes .generate_fake_resource (_project .Project )
752+ self .domain = sdk_fakes .generate_fake_resource (_domain .Domain )
753+ self .service = sdk_fakes .generate_fake_resource (_service .Service )
754+ self .endpoint = sdk_fakes .generate_fake_resource (
755+ _endpoint .Endpoint , service_id = self .service .id
756+ )
757+
758+ self .identity_sdk_client .find_project .return_value = self .project
759+ self .identity_sdk_client .find_domain .return_value = self .domain
760+ self .identity_sdk_client .find_endpoint .return_value = self .endpoint
787761
788- # Update the image_id in the MEMBER dict
789- self .ep_filter_mock .create .return_value = self .new_ep_filter
790- self .projects_mock .get .return_value = self .project
791- self .domains_mock .get .return_value = self .domain
792762 # Get the command object to test
793763 self .cmd = endpoint .AddProjectToEndpoint (self .app , None )
794764
@@ -804,7 +774,7 @@ def test_add_project_to_endpoint_no_option(self):
804774 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
805775
806776 result = self .cmd .take_action (parsed_args )
807- self .ep_filter_mock . add_endpoint_to_project .assert_called_with (
777+ self .identity_sdk_client . associate_endpoint_with_project .assert_called_with (
808778 project = self .project .id , endpoint = self .endpoint .id
809779 )
810780 self .assertIsNone (result )
@@ -824,29 +794,26 @@ def test_add_project_to_endpoint_with_option(self):
824794 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
825795
826796 result = self .cmd .take_action (parsed_args )
827- self .ep_filter_mock . add_endpoint_to_project .assert_called_with (
797+ self .identity_sdk_client . associate_endpoint_with_project .assert_called_with (
828798 project = self .project .id , endpoint = self .endpoint .id
829799 )
830800 self .assertIsNone (result )
831801
832802
833- class TestRemoveProjectEndpoint (TestEndpoint ):
834- project = identity_fakes .FakeProject .create_one_project ()
835- domain = identity_fakes .FakeDomain .create_one_domain ()
836- service = identity_fakes .FakeService .create_one_service ()
837- endpoint = identity_fakes .FakeEndpoint .create_one_endpoint (
838- attrs = {'service_id' : service .id }
839- )
840-
803+ class TestRemoveProjectEndpoint (identity_fakes .TestIdentity ):
841804 def setUp (self ):
842805 super ().setUp ()
843806
844- # This is the return value for utils.find_resource()
845- self .endpoints_mock .get .return_value = self .endpoint
807+ self .project = sdk_fakes .generate_fake_resource (_project .Project )
808+ self .domain = sdk_fakes .generate_fake_resource (_domain .Domain )
809+ self .service = sdk_fakes .generate_fake_resource (_service .Service )
810+ self .endpoint = sdk_fakes .generate_fake_resource (
811+ _endpoint .Endpoint , service_id = self .service .id
812+ )
846813
847- self .projects_mock . get .return_value = self .project
848- self .domains_mock . get .return_value = self .domain
849- self .ep_filter_mock . delete .return_value = None
814+ self .identity_sdk_client . find_project .return_value = self .project
815+ self .identity_sdk_client . find_domain .return_value = self .domain
816+ self .identity_sdk_client . find_endpoint .return_value = self . endpoint
850817
851818 # Get the command object to test
852819 self .cmd = endpoint .RemoveProjectFromEndpoint (self .app , None )
@@ -863,10 +830,8 @@ def test_remove_project_endpoint_no_options(self):
863830 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
864831
865832 result = self .cmd .take_action (parsed_args )
866-
867- self .ep_filter_mock .delete_endpoint_from_project .assert_called_with (
868- project = self .project .id ,
869- endpoint = self .endpoint .id ,
833+ self .identity_sdk_client .disassociate_endpoint_from_project .assert_called_with (
834+ project = self .project .id , endpoint = self .endpoint .id
870835 )
871836 self .assertIsNone (result )
872837
@@ -885,9 +850,7 @@ def test_remove_project_endpoint_with_options(self):
885850 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
886851
887852 result = self .cmd .take_action (parsed_args )
888-
889- self .ep_filter_mock .delete_endpoint_from_project .assert_called_with (
890- project = self .project .id ,
891- endpoint = self .endpoint .id ,
853+ self .identity_sdk_client .disassociate_endpoint_from_project .assert_called_with (
854+ project = self .project .id , endpoint = self .endpoint .id
892855 )
893856 self .assertIsNone (result )
0 commit comments