def factory(cls, docstring, name, schema, requests_kwargs, dl, client): class_name = utils.to_camel_case(name) resource = type(str(class_name), (cls, ), {}) #resource.__doc__ = docstring resource._schema = schema resource.client = client resource._instance_links = {} resource._attributes = {} routes = {} for link_desc in schema[LINKS]: if link_desc[HREF] in routes: route = routes[link_desc[HREF]] else: route = Route(link_desc[HREF]) routes[link_desc[HREF]] = route link = Link(route, method=link_desc[METHOD], schema=link_desc.get(SCHEMA, {}), target_schema=link_desc.get(TARGET_SCHEMA, {}), requests_kwargs=requests_kwargs, docstring=link_desc.get(DOC, None)) rel = utils.to_snake_case(link_desc[REL]) if route.is_instance: resource._instance_links[rel] = link else: setattr(resource, rel, LinkProxy(link)) for name, prop in schema[PROPERTIES].items(): attr = Attribute(prop) resource._attributes[name] = attr property_name = name if name.startswith("$"): property_name = name.replace("$", "") if attr.read_only: setattr(resource, property_name, property(fget=partial(resource._get_property, name), doc=attr.__doc__)) else: setattr(resource, property_name, property(fget=partial(resource._get_property, name), fset=partial(resource._set_property, name), fdel=partial(resource._del_property, name), doc=attr.__doc__)) if class_name == "Sample": resource.download_file = dl return resource
def test_camelize(self): self.assertEqual("CamelCase", utils.to_camel_case("camel_case")) self.assertEqual("DNA", utils.to_camel_case("d_n_a")) self.assertEqual("Dna", utils.to_camel_case("DNA"))