您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test_nav.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from unittest import mock
  2. import pytest
  3. from django.apps import AppConfig
  4. from django.core.exceptions import ImproperlyConfigured
  5. from django.urls import include, path
  6. from oscar.apps.dashboard.nav import _dashboard_url_names_to_config
  7. from oscar.core.application import OscarDashboardConfig
  8. class PathAppConfig(AppConfig):
  9. path = "fake"
  10. class DashConfig(OscarDashboardConfig):
  11. path = "fake"
  12. def get_urls(self):
  13. return [
  14. path("a", lambda x: x, name="lol"),
  15. path("b", lambda x: x),
  16. path(
  17. "c",
  18. include(
  19. [
  20. path("d", lambda x: x, name="foo"),
  21. ]
  22. ),
  23. ),
  24. ]
  25. def test_only_returns_dashboard_urls():
  26. with mock.patch("oscar.apps.dashboard.nav.apps.get_app_configs") as mock_configs:
  27. mock_configs.return_value = [PathAppConfig("name", "module")]
  28. output = _dashboard_url_names_to_config.__wrapped__()
  29. assert not output
  30. def test_only_returns_named_urls_and_skips_includes():
  31. config = DashConfig("name", "module")
  32. with mock.patch("oscar.apps.dashboard.nav.apps.get_app_configs") as mock_configs:
  33. mock_configs.return_value = [config]
  34. output = _dashboard_url_names_to_config.__wrapped__()
  35. assert output == {"lol": config}
  36. def test_raises_if_same_name_in_different_configs():
  37. config_a = DashConfig("a_name", "a_module")
  38. config_b = DashConfig("b_name", "b_module")
  39. with mock.patch("oscar.apps.dashboard.nav.apps.get_app_configs") as mock_configs:
  40. mock_configs.return_value = [config_a, config_b]
  41. with pytest.raises(ImproperlyConfigured):
  42. _dashboard_url_names_to_config.__wrapped__()