@contextmanager
def set_siteconfig_settings(settings):
    siteconfig = SiteConfiguration.objects.get_current()

    old_settings = {}

    for setting, value in six.iteritems(settings):
        old_settings[setting] = siteconfig.get(setting)
        siteconfig.set(setting, value)

    siteconfig.save()
    load_site_config()

    try:
        yield
    finally:
        for setting, value in six.iteritems(old_settings):
            siteconfig.set(setting, value)

        siteconfig.save()
        load_site_config()
A context manager to toggle site configuration settings.
dataset/ETHPy150Open reviewboard/reviewboard/reviewboard/extensions/tests.py/set_siteconfig_settings