def from_instance(cls, resource): if not isinstance(resource, Resource): raise ValueError('%s must be an instance of Resource' % resource) type_ = to_snake(type(resource).__name__) if type_ not in cls.valid_types: raise ValueError('%s must be one of %s' % (type_, cls.valid_types)) return cls(type=type_, id=resource.id)
def from_instance(cls, resource): if not isinstance(resource, Resource): raise ValueError('%s must be an instance of Resource' % resource) type_ = to_snake(type(resource).__name__) if type_ not in cls.valid_types: raise ValueError('%s must be one of %s' % (type_, cls.valid_types)) return cls( type=type_, id=resource.id )
def from_resource_and_id(cls, resource, id): type_ = to_snake(resource.__name__) if type_ not in cls.valid_types: raise ValueError('%s must be one of %s' % (type_, cls.valid_types)) return cls(type=type_, id=id)
def test_to_snake(): assert to_snake('FooBar') == 'foo_bar' assert to_snake('foo-bar') == 'foo_bar' assert to_snake('foo_bar') == 'foo_bar'