You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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('c', include([
  17. path('d', lambda x:x, name='foo'),
  18. ]))
  19. ]
  20. def test_only_returns_dashboard_urls():
  21. with mock.patch('oscar.apps.dashboard.nav.apps.get_app_configs') as mock_configs:
  22. mock_configs.return_value = [PathAppConfig('name', 'module')]
  23. output = _dashboard_url_names_to_config.__wrapped__()
  24. assert not output
  25. def test_only_returns_named_urls_and_skips_includes():
  26. config = DashConfig('name', 'module')
  27. with mock.patch('oscar.apps.dashboard.nav.apps.get_app_configs') as mock_configs:
  28. mock_configs.return_value = [config]
  29. output = _dashboard_url_names_to_config.__wrapped__()
  30. assert output == {"lol": config}
  31. def test_raises_if_same_name_in_different_configs():
  32. config_a = DashConfig('a_name', 'a_module')
  33. config_b = DashConfig('b_name', 'b_module')
  34. with mock.patch('oscar.apps.dashboard.nav.apps.get_app_configs') as mock_configs:
  35. mock_configs.return_value = [config_a, config_b]
  36. with pytest.raises(ImproperlyConfigured):
  37. _dashboard_url_names_to_config.__wrapped__()