|
4 | 4 | import socket |
5 | 5 | import time |
6 | 6 | from base64 import b64encode |
| 7 | +from functools import wraps |
7 | 8 | from sys import platform |
8 | 9 | from urllib.parse import quote_plus |
9 | 10 |
|
10 | 11 | import betamax |
11 | 12 | import pytest |
| 13 | +from betamax.cassette.cassette import Cassette, dispatch_hooks |
12 | 14 | from betamax.serializers import JSONSerializer |
13 | 15 |
|
14 | 16 |
|
@@ -55,7 +57,7 @@ def filter_access_token(interaction, current_cassette): |
55 | 57 | x: env_default(x) |
56 | 58 | for x in ( |
57 | 59 | "auth_code client_id client_secret password redirect_uri test_subreddit" |
58 | | - " user_agent username" |
| 60 | + " user_agent username refresh_token" |
59 | 61 | ).split() |
60 | 62 | } |
61 | 63 |
|
@@ -83,6 +85,28 @@ def serialize(self, cassette_data): |
83 | 85 | config.define_cassette_placeholder(f"<{key.upper()}>", value) |
84 | 86 |
|
85 | 87 |
|
| 88 | +def add_init_hook(original_init): |
| 89 | + """Wrap an __init__ method to also call some hooks.""" |
| 90 | + |
| 91 | + @wraps(original_init) |
| 92 | + def wrapper(self, *args, **kwargs): |
| 93 | + original_init(self, *args, **kwargs) |
| 94 | + dispatch_hooks("after_init", self) |
| 95 | + |
| 96 | + return wrapper |
| 97 | + |
| 98 | + |
| 99 | +Cassette.__init__ = add_init_hook(Cassette.__init__) |
| 100 | + |
| 101 | + |
| 102 | +def init_hook(cassette): |
| 103 | + if cassette.is_recording(): |
| 104 | + pytest.set_up_record() # dynamically defined in __init__.py |
| 105 | + |
| 106 | + |
| 107 | +Cassette.hooks["after_init"].append(init_hook) |
| 108 | + |
| 109 | + |
86 | 110 | class Placeholders: |
87 | 111 | def __init__(self, _dict): |
88 | 112 | self.__dict__ = _dict |
|
0 commit comments