예제 #1
0
def get_requested_site(request):
    """
    From a request return the corresponding site.

    This functions makes use of the `REQUESTED_SITE_BACKEND` setting if configured, otherwise
    it defaults to Django's get_current_site().

    :return Site
    """
    backend_path = settings.ENV_TOKENS['FIGURES'].get('REQUESTED_SITE_BACKEND')
    if backend_path:
        requested_site_backend = import_from_path(backend_path)
        requested_site = requested_site_backend(request)
    else:
        requested_site = sites_shortcuts.get_current_site(request)
    return requested_site
예제 #2
0
def get_sites():
    """
    Get a list of sites for Figures purposes in a configurable manner.

    This functions makes use of the `SITES_BACKEND` setting if configured, otherwise
    it defaults to  _get_all_sites().

    :return list of Site (QuerySet)
    """
    sites_backend_path = settings.ENV_TOKENS['FIGURES'].get('SITES_BACKEND')
    if sites_backend_path:
        sites_backend = import_from_path(sites_backend_path)
        sites = sites_backend()
    else:
        sites = _get_all_sites()

    return sites
예제 #3
0
def test_import_from_bad_syntax():
    utc_tz_path = 'not a path'
    with pytest.raises(ValueError):
        # Malformed path
        import_from_path(utc_tz_path)
예제 #4
0
def test_import_from_path_missing_module():
    utc_tz_path = 'non_existent_module.submodule:some_variable'
    with pytest.raises(ImportError):
        # Should raise an ImportError because the module does not exist
        import_from_path(utc_tz_path)
예제 #5
0
def test_import_from_path_failing():
    utc_tz_path = 'django.utils.timezone:non_existent_variable'
    with pytest.raises(AttributeError):
        # Should raise an AttributeError because the helper is using getattr()
        import_from_path(utc_tz_path)
예제 #6
0
def test_import_from_path_working():
    utc_tz_path = 'django.utils.timezone:utc'
    imported_utc = import_from_path(utc_tz_path)
    assert imported_utc is utc, 'Should import the utc variable correctly'