@contextlib.contextmanager
def with_comprehensive_theme_context(theme=None):
 if theme:
  domain = '{theme}.org'.format(theme=re.sub('\\.org$', '', theme))
  (site, __) = Site.objects.get_or_create(domain=domain, name=theme)
  (site_theme, __) = SiteTheme.objects.get_or_create(site=site, theme_dir_name=theme)
  with patch('openedx.core.djangoapps.theming.helpers.get_current_site_theme', return_value=site_theme):
   with patch('openedx.core.djangoapps.theming.helpers.get_current_site', return_value=site):
    (yield)
 else:
  (yield)

@ contextlib . contextmanager def with_comprehensive_theme_context ( theme = None ) : if theme : domain = '{theme}.org' . format ( theme = re . sub ( '\\.org$' , '' , theme ) ) ( site , __ ) = Site . objects . get_or_create ( domain = domain , name = theme ) ( site_theme , __ ) = SiteTheme . objects . get_or_create ( site = site , theme_dir_name = theme ) with patch ( 'openedx.core.djangoapps.theming.helpers.get_current_site_theme' , return_value = site_theme ) : with patch ( 'openedx.core.djangoapps.theming.helpers.get_current_site' , return_value = site ) : ( yield ) else : ( yield )
a function to run a test as if request was made to the given theme .