File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ from django .apps import AppConfig
2+
3+
4+ class PicturesAppConfig (AppConfig ):
5+ name = "pictures"
6+
7+ def ready (self ):
8+ import pictures .checks # noqa
Original file line number Diff line number Diff line change 1+ from django .core .checks import Error , Tags , register
2+ from django .urls import NoReverseMatch , reverse
3+
4+ from . import conf
5+
6+ __all__ = ["placeholder_url_check" ]
7+
8+
9+ @register (Tags .urls )
10+ def placeholder_url_check (app_configs , ** kwargs ):
11+ errors = []
12+ if conf .get_settings ().USE_PLACEHOLDERS :
13+ try :
14+ reverse (
15+ "pictures:placeholder" ,
16+ kwargs = {
17+ "alt" : "test" ,
18+ "width" : 100 ,
19+ "ratio" : "1x1" ,
20+ "file_type" : "jpg" ,
21+ },
22+ )
23+ except NoReverseMatch :
24+ errors .append (
25+ Error (
26+ "Placeholder URLs are not configured correctly." ,
27+ hint = (
28+ 'PICTURES["USE_PLACEHOLDERS"] is True,'
29+ ' but include("pictures.urls") is missing for your URL config.'
30+ ),
31+ id = "pictures.E001" ,
32+ )
33+ )
34+ return errors
Original file line number Diff line number Diff line change 1+ from unittest .mock import Mock
2+
3+ from django .urls import NoReverseMatch
4+
5+ from pictures import checks
6+
7+
8+ def test_placeholder_url_check (settings , monkeypatch ):
9+ """Test that the placeholder URL check works."""
10+
11+ settings .PICTURES ["USE_PLACEHOLDERS" ] = True
12+ assert not checks .placeholder_url_check ({})
13+
14+ reverse = Mock (side_effect = NoReverseMatch )
15+ monkeypatch .setattr (checks , "reverse" , reverse )
16+
17+ assert checks .placeholder_url_check ({})
18+
19+ settings .PICTURES ["USE_PLACEHOLDERS" ] = False
20+ assert not checks .placeholder_url_check ({})
You can’t perform that action at this time.
0 commit comments