def test_service_xml_serialization(self): service = Service(id=1, name="the service", type="compute", blank=None) xml_str = service.to_xml() self.assertTrue(testutils.XMLTools.xmlEqual(xml_str, '<service \ xmlns="http://docs.openstack.org/identity/api/ext/OS-KSADM/v1.0" \ id="1" name="the service" type="compute"/>'))
def test_service_xml_serialization(self): service = Service(id=1, name="the service", type="compute", blank=None) xml_str = service.to_xml() self.assertTrue( testutils.XMLTools.xmlEqual( xml_str, '<service \ xmlns="http://docs.openstack.org/identity/api/ext/OS-KSADM/v1.0" \ id="1" name="the service" type="compute"/>'))
def test_service_json_serialization(self): service = Service(id=1, name="the service", type="compute", blank=None) service["dynamic"] = "test" json_str = service.to_json() d1 = json.loads(json_str) d2 = json.loads('{"OS-KSADM:service": {"name": "the service", \ "id": "1", "dynamic": "test", "type": "compute"}}') self.assertDictEqual(d1, d2)
def test_json_serialization(self): service_list = [ Service(name="keystone", type="identity"), Service(name="nova", type="compute"), Service(name="glance", type="image-service") ] services = Services(service_list, {}) json_str = services.to_json() self.assertEqual( json_str, '{"OS-KSADM:services": [{"type": "identity", "name": \ "keystone"}, {"type": "compute", "name": "nova"}, {"type": "image-service", \ "name": "glance"}], "OS-KSADM:services_links": []}')
def to_model(ref): """ Returns Keystone model object based on SQLAlchemy model""" if ref: return Service(id=str(ref.id), name=ref.name, description=ref.desc, type=ref.type, owner_id=ref.owner_id)
def test_xml_serialization(self): service_list = [ Service(name="keystone", type="identity"), Service(name="nova", type="compute"), Service(name="glance", type="image-service") ] services = Services(service_list, {}) xml_str = services.to_xml() self.assertTrue( testutils.XMLTools.xmlEqual( xml_str, '<services xmlns="http://docs.openstack.org/identity/api/ext/\ OS-KSADM/v1.0"><service xmlns="http://docs.openstack.org/identity/api/ext/\ OS-KSADM/v1.0" type="identity" name="keystone"/><service xmlns="http://\ docs.openstack.org/identity/api/ext/OS-KSADM/v1.0" type="compute" name="nova"\ /><service xmlns="http://docs.openstack.org/identity/api/ext/OS-KSADM/v1.0" \ type="image-service" name="glance"/></services>'))
def test_service(self): service = Service() self.assertEquals( str(service.__class__), "<class 'keystone.models.Service'>", "service should be of instance " "class keystone.models.Service but instead " "was '%s'" % str(service.__class__)) self.assertIsInstance(service, dict, "")
def test_service_json_deserialization(self): service = Service.from_json('{"name": "the service", "id": 1,\ "type": "compute"}', hints={ "contract_attributes": ['id', 'name'], "types": [("id", int)]}) self.assertIsInstance(service, Service) self.assertEquals(service.id, 1) self.assertEquals(service.name, "the service")
def test_service_json_deserialization(self): service = Service.from_json('{"name": "the service", "id": 1,\ "type": "compute"}', hints={ "contract_attributes": ['id', 'name'], "types": [("id", int)] }) self.assertIsInstance(service, Service) self.assertEquals(service.id, 1) self.assertEquals(service.name, "the service")
def to_model(ref): """ Returns Keystone model object based on SQLAlchemy model""" if ref: if hasattr(api.USER, 'id_to_uid'): if 'owner_id' in ref: ref['owner_id'] = api.USER.id_to_uid(ref['owner_id']) elif hasattr(ref, 'owner_id'): ref.owner_id = api.USER.id_to_uid(ref.owner_id) return Service(id=str(ref.id), name=ref.name, description=ref.desc, type=ref.type, owner_id=ref.owner_id)
def test_service_inspection(self): service = Service(id=1, name="the service", type="compute") self.assertFalse(service.inspect())
def test_service_validation(self): service = Service(id=1, name="the service", type="compute") self.assertTrue(service.validate())
def test_service_xml_deserialization(self): service = Service(id=1, name="the service", blank=None) self.assertIsInstance(service, Service)
def test_service_static_properties(self): service = Service(id=1, name="the service", type="compute", blank=None) self.assertEquals(service.id, "1") self.assertEquals(service.name, "the service") self.assertRaises(AttributeError, getattr, service, 'some_bad_property')
def test_service_properties(self): service = Service(id=1, name="the service", type="compute", blank=None) service["dynamic"] = "test" self.assertEquals(service["dynamic"], "test")