def setup_settings_file(settings_path):
original_lib_name = "django_fileresponse"
settings_content = f"""
[DEFAULT]
lib_name = {original_lib_name}
"""
with settings_path.open("w") as f:
f.write(settings_content)
return settings_path, original_lib_name
def get_actual_lib_name(settings_path):
config = get_config(settings_path)
return config["DEFAULT"]["lib_name"]
settings_path, original_lib_name = setup_settings_file(Path.cwd() / "test.ini")
with patch_lib_name(settings_path, "fileresponse") as patched_config:
patched_lib_name = get_actual_lib_name(settings_path)
print("lib_name original vs patched: ", original_lib_name, patched_lib_name)
reset_lib_name = get_actual_lib_name(settings_path)
print("after leaving contextmanager, lib_name is back to original: ", reset_lib_name)
# arange
settings_path, original_lib_name = setup_settings_file(Path.cwd() / "test.ini")
# act and assert
patched_lib_name = "fileresponse"
with patch_lib_name(settings_path, patched_lib_name) as patched_config:
actual_lib_name = get_actual_lib_name(settings_path)
assert patched_lib_name == actual_lib_name
# assert
actual_lib_name = get_actual_lib_name(settings_path)
assert original_lib_name == actual_lib_name