Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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
     )
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
def test_to_snake():
    assert to_snake('FooBar') == 'foo_bar'
    assert to_snake('foo-bar') == 'foo_bar'
    assert to_snake('foo_bar') == 'foo_bar'
Ejemplo n.º 6
0
def test_to_snake():
    assert to_snake('FooBar') == 'foo_bar'
    assert to_snake('foo-bar') == 'foo_bar'
    assert to_snake('foo_bar') == 'foo_bar'