コード例 #1
0
 def test_entity(self):
     self.client.get.side_effect = [
         mock_response(
             '/v2/spaces/space_id',
             OK,
             None,
             'v2', 'spaces', 'GET_{id}_response.json'),
         mock_response(
             '/v2/organizations/d7d77408-a250-45e3-8de5-71fcf199bbab',
             OK,
             None,
             'v2', 'organizations', 'GET_{id}_response.json'),
         mock_response(
             '/v2/spaces/2d745a4b-67e3-4398-986e-2adbcf8f7ec9/apps',
             OK,
             None,
             'v2', 'apps', 'GET_response.json'),
         mock_response(
             '/v2/spaces/2d745a4b-67e3-4398-986e-2adbcf8f7ec9/service_instances',
             OK,
             None,
             'v2', 'service_instances', 'GET_response.json')
     ]
     space = self.client.spaces.get('space_id')
     self.assertIsNotNone(space.organization())
     cpt = reduce(lambda increment, _: increment + 1, space.apps(), 0)
     self.assertEqual(cpt, 3)
     cpt = reduce(lambda increment, _: increment + 1, space.service_instances(), 0)
     self.assertEqual(cpt, 1)
     self.client.get.assert_has_calls([call(side_effect.url) for side_effect in self.client.get.side_effect],
                                      any_order=False)
コード例 #2
0
    def test_entity(self):
        self.client.get.side_effect = [
            mock_response(
                '/v2/service_instances/instance_id',
                OK,
                None,
                'v2', 'service_instances', 'GET_{id}_response.json'),
            mock_response(
                '/v2/spaces/e3138257-8035-4c03-8aba-ab5d35eec0f9',
                OK,
                None,
                'v2', 'spaces', 'GET_{id}_response.json')
            ,
            mock_response(
                '/v2/service_instances/df52420f-d5b9-4b86-a7d3-6d7005d1ce96/service_bindings',
                OK,
                None,
                'v2', 'service_bindings', 'GET_response.json'),
            mock_response(
                '/v2/service_plans/65740f84-214a-46cf-b8e3-2233d580f293',
                OK,
                None,
                'v2', 'service_plans', 'GET_{id}_response.json'),
            mock_response(
                '/v2/service_instances/df52420f-d5b9-4b86-a7d3-6d7005d1ce96/routes',
                OK,
                None,
                'v2', 'routes', 'GET_response.json'
            ),
            mock_response(
                '/v2/service_instances/df52420f-d5b9-4b86-a7d3-6d7005d1ce96/service_keys',
                OK,
                None,
                'v2', 'service_keys', 'GET_response.json'
            )
        ]
        service_instance = self.client.service_instances.get('instance_id')

        self.assertIsNotNone(service_instance.space())
        cpt = reduce(lambda increment, _: increment + 1, service_instance.service_bindings(), 0)
        self.assertEqual(cpt, 1)
        self.assertIsNotNone(service_instance.service_plan())
        cpt = reduce(lambda increment, _: increment + 1, service_instance.routes(), 0)
        self.assertEqual(cpt, 1)
        cpt = reduce(lambda increment, _: increment + 1, service_instance.service_keys(), 0)
        self.assertEqual(cpt, 1)
        self.client.get.assert_has_calls([call(side_effect.url) for side_effect in self.client.get.side_effect],
                                         any_order=False)
コード例 #3
0
    def test_entity(self):
        self.client.get.side_effect = [
            mock_response(
                '/v2/service_plans/plan_id',
                OK,
                None,
                'v2', 'service_plans', 'GET_{id}_response.json'),
            mock_response(
                '/v2/services/6a4abae6-93e0-438b-aaa2-5ae67f3a069d',
                OK,
                None,
                'v2', 'services', 'GET_{id}_response.json')
            ,
            mock_response(
                '/v2/service_plans/5d8f3b0f-6b5b-487f-8fed-4c2d9b812a72/service_instances',
                OK,
                None,
                'v2', 'service_instances', 'GET_response.json')
        ]
        service_plan = self.client.service_plans.get('plan_id')

        self.assertIsNotNone(service_plan.service())
        cpt = reduce(lambda increment, _: increment + 1, service_plan.service_instances(), 0)
        self.assertEqual(cpt, 1)
        self.client.get.assert_has_calls([call(side_effect.url) for side_effect in self.client.get.side_effect],
                                         any_order=False)
コード例 #4
0
 def test_list(self):
     self.client.get.return_value = mock_response(
         "/v2/services?q=label%20IN%20some_label", OK, None, "v2", "services", "GET_response.json"
     )
     cpt = reduce(lambda increment, _: increment + 1, self.client.services.list(label="some_label"), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #5
0
 def test_list(self):
     self.client.get.return_value = mock_response('/v2/spaces?q=organization_guid%20IN%20org_id',
                                                  OK,
                                                  None,
                                                  'v2', 'spaces', 'GET_response.json')
     cpt = reduce(lambda increment, _: increment + 1, self.client.spaces.list(organization_guid='org_id'), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #6
0
 def test_list(self):
     self.client.get.return_value = mock_response('/v2/buildpacks',
                                                  OK,
                                                  None,
                                                  'v2', 'buildpacks', 'GET_response.json')
     cpt = reduce(lambda increment, _: increment + 1, self.client.buildpacks.list(), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 3)
コード例 #7
0
 def test_list(self):
     self.client.get.return_value = mock_response(
         '/v2/service_plans?q=service_guid%20IN%20service_id',
         OK,
         None,
         'v2', 'service_plans', 'GET_response.json')
     cpt = reduce(lambda increment, _: increment + 1, self.client.service_plans.list(service_guid='service_id'), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #8
0
 def test_recents(self):
     boundary = '7e061f8d6ec00677d6f6b17fcafec9eef2e3a2360e557f72e3e1116efcec'
     self.client.get.return_value = mock_response('/recent?app=app_id',
                                                  OK,
                                                  {'content-type':
                                                       'multipart/x-protobuf; boundary=%s' % boundary},
                                                  'recents', 'GET_response.bin')
     cpt = reduce(lambda increment, _: increment + 1, self.client.loggregator.get_recent('app_id'), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url, stream=True)
     self.assertEqual(cpt, 5946)
コード例 #9
0
 def test_list_service_bindings(self):
     self.client.get.return_value = mock_response(
         '/v2/apps/app_id/service_bindings',
         OK,
         None,
         'v2', 'apps', 'GET_{id}_service_bindings_response.json')
     cpt = reduce(lambda increment, _: increment + 1,
                  self.client.apps.list_service_bindings('app_id'), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #10
0
 def test_list_instances(self):
     self.client.get.return_value = mock_response(
         '/v2/service_plans/plan_id/service_instances?q=space_guid%20IN%20space_id',
         OK,
         None,
         'v2', 'apps', 'GET_{id}_routes_response.json')
     cpt = reduce(lambda increment, _: increment + 1,
                  self.client.service_plans.list_instances('plan_id', space_guid='space_id'), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #11
0
 def test_list(self):
     self.client.get.return_value = mock_response(
         '/v2/service_brokers?q=space_guid%20IN%20space_guid',
         OK,
         None,
         'v2', 'service_bindings', 'GET_response.json')
     cpt = reduce(lambda increment, _: increment + 1,
                  self.client.service_brokers.list(space_guid='space_guid'), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #12
0
 def test_recents(self):
     boundary = '7e061f8d6ec00677d6f6b17fcafec9eef2e3a2360e557f72e3e1116efcec'
     self.client.get.return_value = mock_response(
         '/recent?app=app_id', OK,
         {'content-type': 'multipart/x-protobuf; boundary=%s' % boundary},
         'recents', 'GET_response.bin')
     cpt = reduce(lambda increment, _: increment + 1,
                  self.client.loggregator.get_recent('app_id'), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url,
                                        stream=True)
     self.assertEqual(cpt, 5946)
コード例 #13
0
 def test_list(self):
     self.client.get.return_value = mock_response(
         '/v2/service_instances?q=service_plan_guid%3Aplan_id&q=space_guid%3Aspace_guid',
         OK, None, 'v2', 'service_instances', 'GET_response.json')
     cpt = reduce(
         lambda increment, _: increment + 1,
         self.client.v2.service_instances.list(space_guid='space_guid',
                                               service_plan_guid='plan_id'),
         0)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #14
0
    def test_iter(self):
        client = MagicMock()
        entity_manager = EntityManager(TARGET_ENDPOINT, client,
                                       '/fake/something')

        client.get.return_value = mock_response('/fake/something', OK, None,
                                                'fake', 'GET_response.json')
        cpt = reduce(lambda increment, _: increment + 1, entity_manager, 0)
        client.get.assert_called_with(client.get.return_value.url)

        self.assertEqual(cpt, 2)
コード例 #15
0
 def test_recents(self):
     boundary = 'd661b2c1426a3abcf1c0524d7fdbc774c42a767bdd6702141702d16047bc'
     app_guid = 'app_id'
     self.client.get.return_value = mock_response(
         '/apps/%s/recentlogs' % app_guid, OK,
         {'content-type': 'multipart/x-protobuf; boundary=%s' % boundary},
         'recents', 'GET_response.bin')
     cpt = reduce(lambda increment, _: increment + 1,
                  self.client.doppler.recent_logs(app_guid), 0)
     self.client.get.assert_called_with(self.client.get.return_value.url,
                                        stream=True)
     self.assertEqual(cpt, 200)
コード例 #16
0
 def test_list_routes(self):
     self.client.get.return_value = mock_response(
         '/v2/apps/app_id/routes?q=route_guid%3Aroute_id',
         OK,
         None,
         'v2', 'apps', 'GET_{id}_routes_response.json')
     cpt = reduce(lambda increment, _: increment + 1,
                  self.client.v2.apps.list_routes('app_id', route_guid='route_id'), 0)
     for route in self.client.v2.apps.list_routes('app_id', route_guid='route_id'):
         print(route)
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertEqual(cpt, 1)
コード例 #17
0
    def test_iter(self):
        client = MagicMock()
        entity_manager = EntityManager(TARGET_ENDPOINT, client, '/fake/something')

        client.get.return_value = mock_response(
            '/fake/something',
            OK,
            None,
            'fake', 'GET_response.json')
        cpt = reduce(lambda increment, _: increment + 1, entity_manager, 0)
        client.get.assert_called_with(client.get.return_value.url)

        self.assertEqual(cpt, 2)
コード例 #18
0
    def test_entity(self):
        self.client.get.side_effect = [
            mock_response('/v2/service_instances/instance_id', OK, None, 'v2',
                          'service_instances', 'GET_{id}_response.json'),
            mock_response('/v2/spaces/e3138257-8035-4c03-8aba-ab5d35eec0f9',
                          OK, None, 'v2', 'spaces', 'GET_{id}_response.json'),
            mock_response(
                '/v2/service_instances/df52420f-d5b9-4b86-a7d3-6d7005d1ce96/service_bindings',
                OK, None, 'v2', 'service_bindings', 'GET_response.json'),
            mock_response(
                '/v2/service_plans/65740f84-214a-46cf-b8e3-2233d580f293', OK,
                None, 'v2', 'service_plans', 'GET_{id}_response.json'),
            mock_response(
                '/v2/service_instances/df52420f-d5b9-4b86-a7d3-6d7005d1ce96/routes',
                OK, None, 'v2', 'routes', 'GET_response.json'),
            mock_response(
                '/v2/service_instances/df52420f-d5b9-4b86-a7d3-6d7005d1ce96/service_keys',
                OK, None, 'v2', 'service_keys', 'GET_response.json')
        ]
        service_instance = self.client.v2.service_instances.get('instance_id')

        self.assertIsNotNone(service_instance.space())
        cpt = reduce(lambda increment, _: increment + 1,
                     service_instance.service_bindings(), 0)
        self.assertEqual(cpt, 1)
        self.assertIsNotNone(service_instance.service_plan())
        cpt = reduce(lambda increment, _: increment + 1,
                     service_instance.routes(), 0)
        self.assertEqual(cpt, 1)
        cpt = reduce(lambda increment, _: increment + 1,
                     service_instance.service_keys(), 0)
        self.assertEqual(cpt, 1)
        self.client.get.assert_has_calls([
            call(side_effect.url)
            for side_effect in self.client.get.side_effect
        ],
                                         any_order=False)
コード例 #19
0
    def _get_url_filtered(url, **kwargs):
        list_query_paramters = ["page", "results-per-page", "order-direction"]

        def _append_encoded_parameter(parameters, args):
            parameter_name, parameter_value = args[0], args[1]
            if parameter_name in list_query_paramters:
                parameters.append("%s=%s" % (parameter_name, str(parameter_value)))
            else:
                parameters.append("q=%s" % quote("%s IN %s" % (parameter_name, str(parameter_value))))
            return parameters

        if len(kwargs) > 0:
            return "%s?%s" % (url, "&".join(reduce(_append_encoded_parameter, sorted(list(kwargs.items())), [])))
        else:
            return url
コード例 #20
0
 def test_entity(self):
     self.client.get.side_effect = [
         mock_response('/v2/organizations/org_id', OK, None, 'v2',
                       'organizations', 'GET_{id}_response.json'),
         mock_response(
             '/v2/organizations/fe79371b-39b8-4f0d-8331-cff423a06aca/spaces',
             OK, None, 'v2', 'spaces', 'GET_response.json')
     ]
     organization = self.client.v2.organizations.get('org_id')
     cpt = reduce(lambda increment, _: increment + 1, organization.spaces(),
                  0)
     self.assertEqual(cpt, 1)
     self.client.get.assert_has_calls([
         call(side_effect.url)
         for side_effect in self.client.get.side_effect
     ],
                                      any_order=False)
コード例 #21
0
    def _get_url_filtered(url, **kwargs):
        def _append_encoded_parameter(parameters, args):
            parameter_name, parameter_value = args[0], args[1]
            if isinstance(parameter_value, (list, tuple)):
                parameters.append(
                    '%s=%s' %
                    (parameter_name, quote(','.join(parameter_value))))
            else:
                parameters.append(
                    '%s=%s' % (parameter_name, quote(str(parameter_value))))
            return parameters

        if len(kwargs) > 0:
            return '%s?%s' % (url, "&".join(
                reduce(_append_encoded_parameter, sorted(list(kwargs.items())),
                       [])))
        else:
            return url
コード例 #22
0
 def test_entity(self):
     self.client.get.side_effect = [
         mock_response("/v2/services/service_id", OK, None, "v2", "services", "GET_{id}_response.json"),
         mock_response(
             "/v2/services/2c883dbb-a726-4ecf-a0b7-d65588897e7f/service_plans",
             OK,
             None,
             "v2",
             "service_plans",
             "GET_response.json",
         ),
     ]
     service = self.client.services.get("service_id")
     cpt = reduce(lambda increment, _: increment + 1, service.service_plans(), 0)
     self.assertEqual(cpt, 1)
     self.client.get.assert_has_calls(
         [call(side_effect.url) for side_effect in self.client.get.side_effect], any_order=False
     )
コード例 #23
0
    def test_entity(self):
        self.client.get.side_effect = [
            mock_response(
                '/v2/services/service_id',
                OK,
                None,
                'v2', 'services', 'GET_{id}_response.json'),
            mock_response(
                '/v2/services/2c883dbb-a726-4ecf-a0b7-d65588897e7f/service_plans',
                OK,
                None,
                'v2', 'service_plans', 'GET_response.json')

        ]
        service = self.client.v2.services.get('service_id')
        cpt = reduce(lambda increment, _: increment + 1, service.service_plans(), 0)
        self.assertEqual(cpt, 1)
        self.client.get.assert_has_calls([call(side_effect.url) for side_effect in self.client.get.side_effect],
                                         any_order=False)
コード例 #24
0
ファイル: test_apps.py プロジェクト: lgarvey/cf-python-client
    def test_entity(self):
        self.client.get.side_effect = [
            mock_response('/v2/apps/app_id', OK, None, 'v2', 'apps',
                          'GET_{id}_response.json'),
            mock_response('/v2/spaces/space_id', OK, None, 'v2', 'spaces',
                          'GET_{id}_response.json'),
            mock_response('/v2/routes', OK, None, 'v2', 'routes',
                          'GET_response.json')
        ]
        application = self.client.apps.get('app_id')

        self.assertIsNotNone(application.space())
        cpt = reduce(lambda increment, _: increment + 1, application.routes(),
                     0)
        self.assertEqual(cpt, 1)
        self.client.get.assert_has_calls([
            call(side_effect.url)
            for side_effect in self.client.get.side_effect
        ],
                                         any_order=False)
コード例 #25
0
    def test_entity(self):
        self.client.get.side_effect = [
            mock_response('/v2/service_plans/plan_id', OK, None, 'v2',
                          'service_plans', 'GET_{id}_response.json'),
            mock_response('/v2/services/6a4abae6-93e0-438b-aaa2-5ae67f3a069d',
                          OK, None, 'v2', 'services',
                          'GET_{id}_response.json'),
            mock_response(
                '/v2/service_plans/5d8f3b0f-6b5b-487f-8fed-4c2d9b812a72/service_instances',
                OK, None, 'v2', 'service_instances', 'GET_response.json')
        ]
        service_plan = self.client.v2.service_plans.get('plan_id')

        self.assertIsNotNone(service_plan.service())
        cpt = reduce(lambda increment, _: increment + 1,
                     service_plan.service_instances(), 0)
        self.assertEqual(cpt, 1)
        self.client.get.assert_has_calls([
            call(side_effect.url)
            for side_effect in self.client.get.side_effect
        ],
                                         any_order=False)
コード例 #26
0
    def test_list(self):
        client = MagicMock()
        entity_manager = EntityManager(TARGET_ENDPOINT, client, '/fake/first')

        first_response = mock_response(
            '/fake/first?order-direction=asc&page=1&results-per-page=20&q=space_guid%20IN%20some-id',
            OK,
            None,
            'fake', 'GET_multi_page_0_response.json')
        second_response = mock_response('/fake/next?order-direction=asc&page=2&results-per-page=50',
                                        OK,
                                        None,
                                        'fake', 'GET_multi_page_1_response.json')

        client.get.side_effect = [first_response, second_response]
        cpt = reduce(lambda increment, _: increment + 1, entity_manager.list(**{"results-per-page": 20,
                                                                                'order-direction': 'asc',
                                                                                'page': 1,
                                                                                "space_guid": 'some-id'}), 0)
        client.get.assert_has_calls([call(first_response.url),
                                     call(second_response.url)],
                                    any_order=False)
        self.assertEqual(cpt, 3)
コード例 #27
0
    def _get_url_filtered(self, url, **kwargs):

        def _append_encoded_parameter(parameters, args):
            parameter_name, parameter_value = args[0], args[1]
            if parameter_name in self.list_query_parameters:
                parameters.append('%s=%s' % (parameter_name, str(parameter_value)))
            elif parameter_name in self.list_multi_parameters:
                value_list = parameter_value
                if not isinstance(value_list, (list, tuple)):
                    value_list = [value_list]
                for value in value_list:
                    parameters.append('%s=%s' % (parameter_name, str(value)))
            elif isinstance(parameter_value, (list, tuple)):
                parameters.append('q=%s' % quote('%s IN %s' % (parameter_name, ','.join(parameter_value))))
            else:
                parameters.append('q=%s' % quote('%s:%s' % (parameter_name, str(parameter_value))))
            return parameters

        if len(kwargs) > 0:
            return '%s?%s' % (url,
                              "&".join(reduce(_append_encoded_parameter, sorted(list(kwargs.items())), [])))
        else:
            return url
コード例 #28
0
 def test_entity(self):
     self.client.get.side_effect = [
         mock_response('/v2/routes/route_id', OK, None, 'v2', 'routes',
                       'GET_{id}_response.json'),
         mock_response(
             '/v2/service_instances/e3db4ea8-ab0c-4c47-adf8-a70a8e990ee4',
             OK, None, 'v2', 'service_instances', 'GET_{id}_response.json'),
         mock_response('/v2/spaces/b3f94ab9-1520-478b-a6d6-eb467c179ada',
                       OK, None, 'v2', 'spaces', 'GET_{id}_response.json'),
         mock_response(
             '/v2/routes/75c16cfe-9b8a-4faf-bb65-02c713c7956f/apps', OK,
             None, 'v2', 'apps', 'GET_response.json')
     ]
     route = self.client.v2.routes.get('route_id')
     self.assertIsNotNone(route.service_instance())
     self.assertIsNotNone(route.space())
     cpt = reduce(lambda increment, _: increment + 1, route.apps(), 0)
     self.assertEqual(cpt, 3)
     self.client.get.assert_has_calls([
         call(side_effect.url)
         for side_effect in self.client.get.side_effect
     ],
                                      any_order=False)