def setUp(self): self.tenant_id = "TENANT_ID" self.tenant_name = "TENANT_NAME" self.tenant_description = "TENANT_DESCRIPTION" self.tenant_enabled = False self.tenant_dict = { "id": self.tenant_id, "name": self.tenant_name, "description": self.tenant_description, "enabled": self.tenant_enabled } self.tenant_json_dict = { "name": self.tenant_name, "description": self.tenant_description, "enabled": self.tenant_enabled } self.href = "HREF" self.type = "TYPE" self.rel = "REL" self.tenants_link_dict = { "href": self.href, "type": self.type, "rel": self.rel } self.expected_tenant = Tenant(id_=self.tenant_id, name=self.tenant_name, description=self.tenant_description, enabled=self.tenant_enabled) self.tenant_serialized_str = '{"tenant": ' \ '{"id": "TENANT_ID", ' \ '"enabled": false, ' \ '"name": "TENANT_NAME", ' \ '"description": "TENANT_DESCRIPTION"}}' self.expected_tenant_link = TenantsLink(href=self.href, type_=self.type, rel=self.rel) self.tenant_list_dict = [self.tenant_dict] self.expected_tenants = Tenants(tenants=[self.expected_tenant]) self.tenants_serialized_str = '{"tenants": ' \ '[{"id": "TENANT_ID", ' \ '"enabled": false, ' \ '"name": "TENANT_NAME", ' \ '"description": "TENANT_DESCRIPTION"}]}' self.expected_tenant_json = json.dumps( {"tenant": self.tenant_json_dict}) self.expected_tenants_link_json = \ json.dumps({"tenantsLink": self.tenants_link_dict})
def _xml_list_to_obj(cls, xml_list): kwargs = {'users': [User._xml_ele_to_obj(ele) for ele in xml_list]} return Tenants(**kwargs)
def test_list_to_obj(self): assert self.expected_tenants == Tenants._list_to_obj( self.tenant_list_dict)
def test_json_to_obj(self): assert self.expected_tenant == Tenant._json_to_obj( self.tenant_serialized_str) assert self.expected_tenants == Tenants._json_to_obj( self.tenants_serialized_str)