@contextlib.contextmanager
def with_site_configuration_context(domain='test.localhost', configuration=None):
 (site, __) = Site.objects.get_or_create(domain=domain, name=domain)
 (site_configuration, created) = SiteConfiguration.objects.get_or_create(site=site, defaults={'enabled': True, 'values': configuration})
 if (not created):
  site_configuration.values = configuration
  site_configuration.save()
 with patch('openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration', return_value=site_configuration):
  with patch('openedx.core.djangoapps.theming.helpers.get_current_site', return_value=site):
   with patch('django.contrib.sites.models.SiteManager.get_current', return_value=site):
    (yield)

@ contextlib . contextmanager def with_site_configuration_context ( domain = 'test.localhost' , configuration = None ) : ( site , __ ) = Site . objects . get_or_create ( domain = domain , name = domain ) ( site_configuration , created ) = SiteConfiguration . objects . get_or_create ( site = site , defaults = { 'enabled' : True , 'values' : configuration } ) if ( not created ) : site_configuration . values = configuration site_configuration . save ( ) with patch ( 'openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration' , return_value = site_configuration ) : with patch ( 'openedx.core.djangoapps.theming.helpers.get_current_site' , return_value = site ) : with patch ( 'django.contrib.sites.models.SiteManager.get_current' , return_value = site ) : ( yield )
a function to get a context manger to run a test with a configuration enabled .