コード例 #1
0
 def test_entity(self):
     self.client.get.side_effect = [
         mock_response(
             '/v2/spaces/space_id',
             httplib.OK,
             None,
             'v2', 'spaces', 'GET_{id}_response.json'),
         mock_response(
             '/v2/organizations/d7d77408-a250-45e3-8de5-71fcf199bbab',
             httplib.OK,
             None,
             'v2', 'organizations', 'GET_{id}_response.json'),
         mock_response(
             '/v2/spaces/2d745a4b-67e3-4398-986e-2adbcf8f7ec9/apps',
             httplib.OK,
             None,
             'v2', 'apps', 'GET_response.json'),
         mock_response(
             '/v2/spaces/2d745a4b-67e3-4398-986e-2adbcf8f7ec9/service_instances',
             httplib.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([mock.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_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)
コード例 #3
0
 def test_entity(self):
     self.client.get.side_effect = [
         mock_response(
             '/v2/routes/route_id',
             httplib.OK,
             None,
             'v2', 'routes', 'GET_{id}_response.json'),
         mock_response(
             '/v2/service_instances/e3db4ea8-ab0c-4c47-adf8-a70a8e990ee4',
             httplib.OK,
             None,
             'v2', 'service_instances', 'GET_{id}_response.json'),
         mock_response(
             '/v2/spaces/b3f94ab9-1520-478b-a6d6-eb467c179ada',
             httplib.OK,
             None,
             'v2', 'spaces', 'GET_{id}_response.json'),
         mock_response('/v2/routes/75c16cfe-9b8a-4faf-bb65-02c713c7956f/apps',
                       httplib.OK,
                       None,
                       'v2', 'apps', 'GET_response.json')
     ]
     route = self.client.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([mock.call(side_effect.url) for side_effect in self.client.get.side_effect],
                                      any_order=False)
コード例 #4
0
 def test_get(self):
     self.client.get.return_value = mock_response(
         "/v2/services/service_id", OK, None, "v2", "services", "GET_{id}_response.json"
     )
     result = self.client.services.get("service_id")
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertIsNotNone(result)
コード例 #5
0
 def test_delete(self):
     self.client.delete.return_value = mock_response(
         '/v2/service_brokers/broker_id',
         httplib.NO_CONTENT,
         None)
     self.client.service_brokers.remove('broker_id')
     self.client.delete.assert_called_with(self.client.delete.return_value.url)
コード例 #6
0
 def test_main_list_services(self):
     with patch("cloudfoundry_client.main.build_client_from_configuration", new=lambda: self.client):
         self.client.get.return_value = mock_response(
             "/v2/services", OK, None, "v2", "services", "GET_response.json"
         )
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #7
0
 def test_delete(self):
     self.client.delete.return_value = mock_response(
         '/v2/service_bindings/binding_id',
         NO_CONTENT,
         None)
     self.client.service_bindings.remove('binding_id')
     self.client.delete.assert_called_with(self.client.delete.return_value.url)
コード例 #8
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)
コード例 #9
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)
コード例 #10
0
 def test_list(self):
     self.client.get.return_value = mock_response('/v2/services?q=label%20IN%20some_label',
                                                  httplib.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)
コード例 #11
0
 def build_client(self):
     with patch('cloudfoundry_client.client.requests') as fake_requests:
         fake_info_response = mock_response('/v2/info', 200, None)
         fake_info_response.text = json.dumps(dict(api_version='2.X',
                                                   authorization_endpoint=TARGET_ENDPOINT,
                                                   logging_endpoint=TARGET_ENDPOINT))
         fake_requests.get.return_value = fake_info_response
         self.client = CloudFoundryClient(TARGET_ENDPOINT)
コード例 #12
0
 def test_list(self):
     self.client.get.return_value = mock_response('/v2/spaces?q=organization_guid%20IN%20org_id',
                                                              httplib.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)
コード例 #13
0
 def test_get(self):
     self.client.get.return_value = mock_response(
         '/v2/buildpacks/buildpack_id',
         OK,
         None,
         'v2', 'buildpacks', 'GET_{id}_response.json')
     result = self.client.buildpacks.get('buildpack_id')
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertIsNotNone(result)
コード例 #14
0
 def test_main_list_service_bindings(self):
     with patch('cloudfoundry_client.main.build_client_from_configuration',
                new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/service_bindings',
                                                      OK,
                                                      None,
                                                      'v2', 'service_bindings', 'GET_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #15
0
 def test_main_get_service(self):
     with mock.patch('cloudfoundry_client.main.build_client_from_configuration',
                     new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/services/2c883dbb-a726-4ecf-a0b7-d65588897e7f',
                                                      httplib.OK,
                                                      None,
                                                      'v2', 'services', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #16
0
 def test_main_list_routes(self):
     with mock.patch('cloudfoundry_client.main.build_client_from_configuration',
                     new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/routes',
                                                      httplib.OK,
                                                      None,
                                                      'v2', 'routes', 'GET_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #17
0
 def test_main_get_buildpack(self):
     with patch('cloudfoundry_client.main.build_client_from_configuration',
                     new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/buildpacks/6e72c33b-dff0-4020-8603-bcd8a4eb05e4',
                                                      OK,
                                                      None,
                                                      'v2', 'buildpacks', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #18
0
 def test_main_get_route(self):
     with mock.patch('cloudfoundry_client.main.build_client_from_configuration',
                     new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/routes/75c16cfe-9b8a-4faf-bb65-02c713c7956f',
                                                      httplib.OK,
                                                      None,
                                                      'v2', 'routes', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #19
0
 def test_get(self):
     self.client.get.return_value = mock_response(
         '/v2/service_bindings/service_binding_id',
         OK,
         None,
         'v2', 'service_bindings', 'GET_{id}_response.json')
     result = self.client.service_bindings.get('service_binding_id')
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertIsNotNone(result)
コード例 #20
0
 def test_main_get_service_key(self):
     with patch('cloudfoundry_client.main.build_client_from_configuration',
                new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/service_keys/67755c27-28ed-4087-9688-c07d92f3bcc9',
                                                      OK,
                                                      None,
                                                      'v2', 'service_keys', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #21
0
 def test_get(self):
     self.client.get.return_value = mock_response(
         '/v2/spaces/space_id',
         httplib.OK,
         None,
         'v2', 'spaces', 'GET_{id}_response.json')
     result = self.client.spaces.get('space_id')
     self.client.get.assert_called_with(self.client.get.return_value.url)
     self.assertIsNotNone(result)
コード例 #22
0
 def test_main_get_service_broker(self):
     with mock.patch('cloudfoundry_client.main.build_client_from_configuration',
                     new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/service_brokers/ade9730c-4ee5-4290-ad37-0b15cecd2ca6',
                                                      httplib.OK,
                                                      None,
                                                      'v2', 'service_brokers', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #23
0
 def test_main_get_service_binding(self):
     with patch('cloudfoundry_client.main.build_client_from_configuration',
                new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/service_bindings/eaabd042-8f5c-44a2-9580-1e114c36bdcb',
                                                      OK,
                                                      None,
                                                      'v2', 'service_bindings', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #24
0
 def test_main_get_service_plan(self):
     with patch('cloudfoundry_client.main.build_client_from_configuration',
                new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/service_plans/5d8f3b0f-6b5b-487f-8fed-4c2d9b812a72',
                                                      OK,
                                                      None,
                                                      'v2', 'service_plans', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #25
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
     )
コード例 #26
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)
コード例 #27
0
 def test_main_get_spaces(self):
     with mock.patch('cloudfoundry_client.main.build_client_from_configuration',
                     new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/spaces/2d745a4b-67e3-4398-986e-2adbcf8f7ec9',
                                                      httplib.OK,
                                                      None,
                                                      'v2', 'spaces', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #28
0
 def test_main_get_service_instance(self):
     with patch('cloudfoundry_client.main.build_client_from_configuration',
                new=lambda: self.client):
         self.client.get.return_value = mock_response('/v2/service_instances/df52420f-d5b9-4b86-a7d3-6d7005d1ce96',
                                                      OK,
                                                      None,
                                                      'v2', 'service_instances', 'GET_{id}_response.json')
         main.main()
         self.client.get.assert_called_with(self.client.get.return_value.url)
コード例 #29
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)
コード例 #30
0
 def test_main_delete_service_key(self):
     with patch('cloudfoundry_client.main.build_client_from_configuration',
                new=lambda: self.client):
         self.client.delete.return_value = mock_response(
             '/v2/service_keys/67755c27-28ed-4087-9688-c07d92f3bcc9',
             NO_CONTENT,
             None)
         main.main()
         self.client.delete.assert_called_with(self.client.delete.return_value.url)
         main.main()
コード例 #31
0
    def test_get_camera_picture(self, fake_requests):
        image_id = 'test-image-id'
        key = 'test-key'

        def _check_data(**kwargs):
            self.assertIsNotNone(kwargs.get('params'))
            self.assertEqual(kwargs.get('params').get('image_id'), image_id)
            self.assertEqual(kwargs.get('params').get('key'), key)

        fake_requests.get = mock_response(
            'https://api.netatmo.net/api/getcamerapicture', 'get', _check_data,
            httplib.OK, None, 'api', 'getcamerapicture', 'GET.bin')

        result = self.client.welcome.get_camera_picture(image_id=image_id,
                                                        key=key)
        self.assertEqual(len(result), 21638)
コード例 #32
0
 def test_update(self):
     self.client.patch.return_value = mock_response(
         '/v3/organizations/organization_id',
         HTTPStatus.OK,
         None,
         'v3', 'organizations', 'PATCH_{id}_response.json')
     result = self.client.v3.organizations.update('organization_id', 'my-organization',
                                                  suspended=True)
     self.client.patch.assert_called_with(self.client.patch.return_value.url,
                                          json={'suspended': True,
                                                'name': 'my-organization',
                                                'metadata': {
                                                    'labels': None,
                                                    'annotations': None
                                                }
                                          })
     self.assertIsNotNone(result)
コード例 #33
0
    def test_get_last_event_of(self):
        home_id = 'test-home-id'
        person_id = 'test-person-id'
        size = 10

        self.client.get.return_value = mock_response(
            'https://api.netatmo.net/api/getlasteventof', httplib.OK, None,
            'api', 'getlasteventof', 'GET.json')

        result = self.client.security.get_last_event_of(home_id=home_id,
                                                        person_id=person_id,
                                                        number_of_events=size)

        self.client.get.assert_called_with(
            'https://api.netatmo.net/api/getlasteventof',
            params=dict(home_id=home_id, person_id=person_id, size=size))
        self.assertEqual(len(result['events_list']), 51)
コード例 #34
0
 def test_create(self):
     self.client.post.return_value = mock_response(
         '/v2/service_instances',
         CREATED,
         None,
         'v2', 'service_instances', 'POST_response.json')
     service_instance = self.client.service_instances.create('space_guid', 'name', 'plan_id',
                                                             parameters=dict(the_service_broker="wants this object"),
                                                             tags=['mongodb'])
     self.client.post.assert_called_with(self.client.post.return_value.url,
                                         json=dict(name='name',
                                                   space_guid='space_guid',
                                                   service_plan_guid='plan_id',
                                                   parameters=dict(
                                                       the_service_broker="wants this object"),
                                                   tags=['mongodb'])
                                         )
     self.assertIsNotNone(service_instance)
コード例 #35
0
 def test_create(self):
     self.client.post.return_value = mock_response(
         '/v3/organizations',
         HTTPStatus.OK,
         None,
         'v3', 'organizations', 'POST_response.json')
     result = self.client.v3.organizations.create('my-organization',
                                                  suspended=False)
     self.client.post.assert_called_with(self.client.post.return_value.url,
                                         files=None,
                                         json={'name': 'my-organization',
                                               'suspended': False,
                                               'metadata': {
                                                   'labels': None,
                                                   'annotations': None
                                               }
                                         })
     self.assertIsNotNone(result)
コード例 #36
0
    def test_switch_schedule(self):
        device_id = 'test-device-id'
        module_id = 'test-module-id'
        schedule_id = 'test-schedule-id'

        self.client.post.return_value = mock_response(
            'https://api.netatmo.net/api/switchschedule', httplib.OK, None,
            'api', 'switchschedule', 'POST.json')

        self.client.energy.switch_schedule(device_id=device_id,
                                           module_id=module_id,
                                           schedule_id=schedule_id)

        self.client.post.assert_called_with(
            'https://api.netatmo.net/api/switchschedule',
            data=dict(device_id=device_id,
                      module_id=module_id,
                      schedule_id=schedule_id),
            json=None)
コード例 #37
0
    def test_get_public_data(self, fake_requests):
        lat_ne = 15
        lon_ne = 20
        lat_sw = -15
        lon_sw = -20

        def _check_data(**kwargs):
            self.assertIsNotNone(kwargs.get('params'))
            self.assertEqual(kwargs.get('params').get('lat_ne'), lat_ne)
            self.assertEqual(kwargs.get('params').get('lon_ne'), lon_ne)
            self.assertEqual(kwargs.get('params').get('lat_sw'), lat_sw)
            self.assertEqual(kwargs.get('params').get('lon_sw'), lon_sw)

        fake_requests.get = mock_response(
            'https://api.netatmo.net/api/getpublicdata', 'get', _check_data,
            httplib.OK, None, 'api', 'getpublicdata', 'GET.json')
        result = self.client.public.get_public_data(lat_ne, lon_ne, lat_sw,
                                                    lon_sw)
        self.assertEqual(len(result), 313)
コード例 #38
0
    def test_get_last_event_of(self, fake_requests):
        home_id = 'test-home-id'
        person_id = 'test-person-id'
        size = 10

        def _check_data(**kwargs):
            self.assertIsNotNone(kwargs.get('params'))
            self.assertEqual(kwargs.get('params').get('home_id'), home_id)
            self.assertEqual(kwargs.get('params').get('person_id'), person_id)
            self.assertEqual(kwargs.get('params').get('size'), size)

        fake_requests.get = mock_response(
            'https://api.netatmo.net/api/getlasteventof', 'get', _check_data,
            httplib.OK, None, 'api', 'getlasteventof', 'GET.json')

        result = self.client.welcome.get_last_event_of(home_id=home_id,
                                                       person_id=person_id,
                                                       number_of_events=size)
        self.assertEqual(len(result['events_list']), 51)
コード例 #39
0
    def test_sync_schedule(self):
        device_id = 'test-device-id'
        module_id = 'test-module-id'

        self.client.post.return_value = mock_response(
            'https://api.netatmo.net/api/syncschedule', httplib.OK, None,
            'api', 'syncschedule', 'POST.json')

        self.client.energy.sync_schedule(device_id=device_id,
                                         module_id=module_id,
                                         zones=[],
                                         timetable=[])
        self.client.post.assert_called_with(
            'https://api.netatmo.net/api/syncschedule',
            data=dict(device_id=device_id,
                      module_id=module_id,
                      zones='[]',
                      timetable='[]'),
            json=None)
コード例 #40
0
    def test_switch_schedule(self, fake_requests):
        device_id = 'test-device-id'
        module_id = 'test-module-id'
        schedule_id = 'test-schedule-id'

        def _check_form(**kwargs):
            self.assertIsNotNone(kwargs.get('data'))
            form = kwargs.get('data')
            self.assertEqual(form.get('device_id'), device_id)
            self.assertEqual(form.get('module_id'), module_id)
            self.assertEqual(form.get('schedule_id'), schedule_id)

        fake_requests.post = mock_response(
            'https://api.netatmo.net/api/switchschedule', 'post', _check_form,
            httplib.OK, None, 'api', 'switchschedule', 'POST.json')

        self.client.thermostat.switch_schedule(device_id=device_id,
                                               module_id=module_id,
                                               schedule_id=schedule_id)
コード例 #41
0
    def test_get_station_data_by_device(self):
        device_id = 'test-device-id'

        def _check_data(**kwargs):
            self.assertIsNotNone(kwargs.get('params'))
            self.assertEqual(kwargs.get('params').get('device_id'), device_id)

        self.client.get.return_value = mock_response(
            'https://api.netatmo.net/api/getstationsdata', httplib.OK, None,
            'api', 'getstationsdata', 'GET_{id}.json')

        result = self.client.weather.get_station_data(device_id=device_id)

        self.client.get.assert_called_with(
            'https://api.netatmo.net/api/getstationsdata',
            params=dict(device_id=device_id))

        self.assertEqual(result['user']['mail'], '*****@*****.**')
        self.assertEqual(len(result['devices']), 1)
コード例 #42
0
 def test_update(self):
     self.client.put.return_value = mock_response('/v2/apps/app_id',
                                                  HTTPStatus.CREATED, None,
                                                  'v2', 'apps',
                                                  'PUT_{id}_response.json')
     application = self.client.v2.apps.update(
         'app_id',
         stack_guid='82f9c01c-72f2-4d3e-b5ed-eab97a6203cf',
         memory=1024,
         instances=1,
         disk_quota=1024,
         health_check_type="port")
     self.client.put.assert_called_with(
         self.client.put.return_value.url,
         json=dict(stack_guid='82f9c01c-72f2-4d3e-b5ed-eab97a6203cf',
                   memory=1024,
                   instances=1,
                   disk_quota=1024,
                   health_check_type="port"))
     self.assertIsNotNone(application)
コード例 #43
0
 def test_share_domain(self):
     self.client.post.return_value = mock_response(
         '/v3/domains/domain_id/relationships/shared_organizations',
         HTTPStatus.CREATED,
         None,
         'v3', 'domains', 'POST_{id}_relationships_shared_organizations_response.json')
     result = self.client.v3.domains.share_domain('domain_id',
                                                  ToManyRelationship('organization-guid-1', 'organization-guid-2'))
     self.client.post.assert_called_with(self.client.post.return_value.url,
                                         files=None,
                                         json={
                                             'data': [
                                                 {'guid': 'organization-guid-1'},
                                                 {'guid': 'organization-guid-2'}
                                             ]
                                         })
     self.assertIsNotNone(result)
     self.assertIsInstance(result, ToManyRelationship)
     result.guids[0] = 'organization-guid-1'
     result.guids[1] = 'organization-guid-1'
コード例 #44
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)
コード例 #45
0
 def test_update(self):
     self.client.patch.return_value = mock_response(
         '/v3/buildpacks/buildpack_id',
         HTTPStatus.OK,
         None,
         'v3', 'buildpacks', 'PATCH_{id}_response.json')
     result = self.client.v3.buildpacks.update('buildpack_id', 'ruby_buildpack',
                                               enabled=True,
                                               position=42,
                                               stack='windows64')
     self.client.patch.assert_called_with(self.client.patch.return_value.url,
                                          json={'locked': False,
                                                'name': 'ruby_buildpack',
                                                'enabled': True,
                                                'position': 42,
                                                'stack': 'windows64',
                                                'metadata': {
                                                    'labels': None,
                                                    'annotations': None
                                                }
                                          })
     self.assertIsNotNone(result)
コード例 #46
0
 def test_create(self):
     self.client.post.return_value = mock_response('/v2/apps',
                                                   HTTPStatus.CREATED, None,
                                                   'v2', 'apps',
                                                   'POST_response.json')
     application = self.client.v2.apps.create(
         name='test',
         space_guid='1fbb3e81-4f55-4fd3-9820-45febbd5e53e',
         stack_guid='82f9c01c-72f2-4d3e-b5ed-eab97a6203cf',
         memory=1024,
         instances=1,
         disk_quota=1024,
         health_check_type="port")
     self.client.post.assert_called_with(
         self.client.post.return_value.url,
         json=dict(name='test',
                   space_guid='1fbb3e81-4f55-4fd3-9820-45febbd5e53e',
                   stack_guid='82f9c01c-72f2-4d3e-b5ed-eab97a6203cf',
                   memory=1024,
                   instances=1,
                   disk_quota=1024,
                   health_check_type="port"))
     self.assertIsNotNone(application)
コード例 #47
0
    def test_create_schedule(self):
        device_id = 'test-device-id'
        module_id = 'test-module-id'
        name = 'test-name-id'

        self.client.post.return_value = mock_response(
            'https://api.netatmo.net/api/createnewschedule', httplib.OK, None,
            'api', 'createnewschedule', 'POST.json')

        result = self.client.energy.create_new_schedule(device_id=device_id,
                                                        module_id=module_id,
                                                        name=name,
                                                        zones=[],
                                                        timetable=[])
        self.client.post.assert_called_with(
            'https://api.netatmo.net/api/createnewschedule',
            data=dict(device_id=device_id,
                      module_id=module_id,
                      name=name,
                      zones='[]',
                      timetable='[]'),
            json=None)
        self.assertEqual(result['schedule_id'], '53a056ba55ee4f57198b4569')
コード例 #48
0
    def test_get_thermostat_data(self, fake_requests):
        def _check_request(**kwargs):
            self.assertIsNotNone(kwargs.get('data', None))
            form = kwargs['data']
            self.assertIsInstance(form, dict)
            raw_data_content = load_resource_path(False, 'oauth2', 'token',
                                                  'client_credentials.txt')
            data_content = {
                d[0]: d[1]
                for d in [c.split("=") for c in raw_data_content.split("&")]
                if len(d) == 2
            }
            for k, v in data_content.items():
                self.assertEqual(v, form[k])

        fake_requests.post = mock_response(
            'https://api.netatmo.com/oauth2/token', 'post', _check_request,
            httplib.OK, None, 'oauth2', 'token', 'POST.json')
        self.client.request_token_with_client_credentials(
            "*****@*****.**", "5\\r{SM0_~gpG", "read_station",
            "read_thermostat")
        self.assertEqual(self.client._access_token, 'the_access_token')
        self.assertEqual(self.client._refresh_token, 'the_refresh_token')
コード例 #49
0
    def test_set_therm_point(self):
        device_id = 'test-device-id'
        module_id = 'test-module-id'
        setpoint_mode = 'manual'
        setpoint_endtime = 666
        setpoint_temp = 19

        self.client.post.return_value = mock_response(
            'https://api.netatmo.net/api/setthermpoint', httplib.OK, None,
            'api', 'setthermpoint', 'POST.json')

        self.client.energy.set_therm_point(device_id=device_id,
                                           module_id=module_id,
                                           setpoint_mode=setpoint_mode,
                                           setpoint_endtime=setpoint_endtime,
                                           setpoint_temp=setpoint_temp)
        self.client.post.assert_called_with(
            'https://api.netatmo.net/api/setthermpoint',
            data=dict(device_id=device_id,
                      module_id=module_id,
                      setpoint_mode=setpoint_mode,
                      setpoint_endtime=setpoint_endtime,
                      setpoint_temp=setpoint_temp),
            json=None)
コード例 #50
0
 def test_delete(self):
     self.client.delete.return_value = mock_response(
         '/v2/service_instances/instance_id', HTTPStatus.NO_CONTENT, None)
     self.client.v2.service_instances.remove('instance_id')
     self.client.delete.assert_called_with(
         self.client.delete.return_value.url, params={})
コード例 #51
0
 def test_remove_route(self):
     self.client.delete.return_value = mock_response(
         '/v2/apps/app_id/routes/route_id', HTTPStatus.NO_CONTENT, None)
     self.client.v2.apps.remove_route('app_id', 'route_id')
     self.client.delete.assert_called_with(
         self.client.delete.return_value.url)
コード例 #52
0
 def test_delete(self):
     self.client.delete.return_value = mock_response(
         '/v2/service_bindings/binding_id', NO_CONTENT, None)
     self.client.service_bindings.remove('binding_id')
     self.client.delete.assert_called_with(
         self.client.delete.return_value.url)
コード例 #53
0
 def test_associate_route(self):
     self.client.put.return_value = mock_response('/v2/apps/app_id/routes/route_id', CREATED, None,
                                                  'v2', 'apps', 'PUT_{id}_routes_{route_id}_response.json')
     self.client.v2.apps.associate_route('app_id', 'route_id')
     self.client.put.assert_called_with(self.client.put.return_value.url, json=None)
コード例 #54
0
 def test_remove(self):
     self.client.delete.return_value = mock_response(
         '/v3/apps/app_id', NO_CONTENT, None)
     self.client.v3.apps.remove('app_id')
     self.client.delete.assert_called_with(
         self.client.delete.return_value.url)
コード例 #55
0
 def test_delete(self):
     self.client.delete.return_value = mock_response(
         '/v2/service_keys/key_id', HTTPStatus.NO_CONTENT, None)
     self.client.v2.service_keys.remove('key_id')
     self.client.delete.assert_called_with(
         self.client.delete.return_value.url)
コード例 #56
0
 def test_associate_route(self):
     self.client.put.return_value = mock_response('/v2/apps/app_id/routes/route_id', NO_CONTENT, None)
     self.client.v2.apps.associate_route('app_id', 'route_id')
     self.client.put.assert_called_with(self.client.put.return_value.url)