1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

Add test_case method to VCR

this method provides a class that can be inherited from to decorate all
test methods on the desired class with use_cassette using the relevant vcr
This commit is contained in:
Ivan Malison
2015-08-28 01:40:35 -07:00
parent 420f83b6b1
commit 6fd04f3675
3 changed files with 49 additions and 2 deletions

View File

@@ -1,4 +1,6 @@
import collections
import types
# Shamelessly stolen from https://github.com/kennethreitz/requests/blob/master/requests/structures.py
class CaseInsensitiveDict(collections.MutableMapping):
@@ -90,3 +92,19 @@ def read_body(request):
if hasattr(request.body, 'read'):
return request.body.read()
return request.body
def auto_decorate(
decorator,
predicate=lambda name, value: isinstance(value, types.FunctionType)
):
class DecorateAll(type):
def __new__(cls, name, bases, attributes_dict):
for attribute, value in attributes_dict.items():
if predicate(attribute, value):
attributes_dict[attribute] = decorator(value)
return super(DecorateAll, cls).__new__(
cls, name, bases, attributes_dict
)
return DecorateAll