示例#1
0
 def test_equal(self):
     re1 = Resource(self.client, resource_id='test')
     re2 = Resource(self.client, resource_id='test')
     re3 = Resource(self.client, resource_id='test3')
     self.assertTrue(re1 == re2)
     self.assertFalse(re1 == re3)
     self.assertFalse(re1 is re2)
     self.assertTrue(re1 in [re2])
示例#2
0
    def __init__(
        self,
        service_address,
        user,
        password,
        port=DEFAULT_PORT,
        hostname='',
        service_type='ds8k',
        service_version='v1',
        timeout=None,
    ):
        logger.info('================== logger is enabled ==================')

        client = HTTPClient(
            service_address,
            user,
            password,
            port=port,
            hostname=hostname,
            service_type=service_type,
            service_version=service_version,
            timeout=timeout,
        )

        self.client = client
        self.resource = Resource(self.client, DefaultManager(self.client))
        self.system = System(self.client, SystemManager(self.client))
示例#3
0
 def setUp(self):
     self.client = HTTPClient(service_address='localhost',
                              user='******',
                              password='******',
                              service_type='ds8k',
                              port='8088')
     self.resource = Resource(self.client, DefaultManager(self.client))
     self.domain = self.client.domain
示例#4
0
    def test_timeout(self):
        url = '/default/a'
        new_client = HTTPClient('localhost', 'admin', 'admin',
                                service_type='ds8k',
                                timeout=0.01)

        def _verify_request(request, uri, headers):
            time.sleep(10)
            return (200, headers, default_a_response_json)

        httpretty.register_uri(httpretty.GET,
                               new_client.domain + self.base_url + url,
                               body=_verify_request,
                               content_type='application/json',
                               )

        resource = Resource(new_client, DefaultManager(new_client))
        resource.one(DEFAULT, 'a').get()
示例#5
0
文件: base.py 项目: IBM/pyds8k
 def setUp(self):
     self.client = HTTPClient("http://localhost:8088/api/",
                              'admin',
                              'admin',
                              service_type='ds8k',
                              port=8088)
     self.base_url = self.client.base_url
     self.resource = Resource(self.client,
                              manager=DefaultManager(self.client))
     self.domain = self.client.domain
示例#6
0
 def test_update_list_field(self):
     re1 = Resource(self.client, resource_id='test')
     re1.re_list = [
         Resource(self.client, resource_id='test{}'.format(n))
         for n in range(10)
     ]
     re_not_in = Resource(self.client, resource_id='test11')
     re_in = Resource(self.client, resource_id='test1')
     with self.assertRaises(KeyError):
         re1._update_list_field('re_list', re_not_in, '-')
     with self.assertRaises(KeyError):
         re1._update_list_field('re_list', re_in)
     re1._update_list_field('re_list', re_not_in)
     self.assertTrue(re_not_in in re1.re_list)
     re1._update_list_field('re_list', re_in, '-')
     self.assertTrue(re_in not in re1.re_list)
示例#7
0
    def test_force_get(self):
        re1 = Resource(
            self.client,
            DefaultManager(self.client),
        )
        re1._template = {'key1': '', 'key2': ''}
        re1._add_details(info={'key1': 'val1'})
        self.assertEqual(re1._get_modified_info_dict(), {})
        self.assertEqual(re1.key1, 'val1')
        re1.key1 = 'val1_changed'
        self.assertEqual(re1._get_modified_info_dict(),
                         {'key1': 'val1_changed'})
        self.assertEqual(re1.key1, 'val1_changed')

        re1._add_details(info={'key1': 'val1'})
        self.assertEqual(re1.key1, 'val1_changed')

        re1._add_details(info={'key1': 'val1'}, force=True)
        self.assertEqual(re1.key1, 'val1')
示例#8
0
    def test_modified_info_dict(self):
        re = Resource(self.client, DefaultManager(self.client))
        self.assertEqual(re._get_modified_info_dict(), {})
        re._set_modified_info_dict('key1', 'val1')
        self.assertEqual(re._get_modified_info_dict(), {'key1': 'val1'})
        re._del_modified_info_dict_key('key')
        self.assertEqual(re._get_modified_info_dict(), {'key1': 'val1'})
        re._del_modified_info_dict_key('key1')
        self.assertEqual(re._get_modified_info_dict(), {})
        re._set_modified_info_dict('key2', 'val2')
        self.assertEqual(re._get_modified_info_dict(), {'key2': 'val2'})
        re._del_modified_info_dict_keys({'key1': 'val1'})
        self.assertEqual(re._get_modified_info_dict(), {'key2': 'val2'})
        re._del_modified_info_dict_keys({'key2': 'val2'})
        self.assertEqual(re._get_modified_info_dict(), {})

        re1 = Resource(
            self.client,
            DefaultManager(self.client),
        )
        re1._template = {'key1': '', 'key2': ''}
        re1._add_details(info={'key1': 'val1'})
        self.assertEqual(re1._get_modified_info_dict(), {})
        self.assertEqual(re1.key1, 'val1')
        re1.key1 = 'val1_changed'
        self.assertEqual(re1._get_modified_info_dict(),
                         {'key1': 'val1_changed'})
        self.assertEqual(re1.key1, 'val1_changed')

        # set attr not in _template
        re1.key3 = 'val3'
        self.assertEqual(re1._get_modified_info_dict(),
                         {'key1': 'val1_changed'})