def test_supported_models_is_cached(self): models = ["Foo", "Bar"] app_config = Mock(spec=[], cms_extension=Mock(spec=[], navigation_apps_models=models)) with patch.object(apps, "get_app_config", return_value=app_config): supported_models() with patch.object(apps, "get_app_config") as mock: supported_models() mock.assert_not_called()
def test_supported_models(self): models = ["Foo", "Bar"] app_config = Mock(spec=[], cms_extension=Mock(spec=[], navigation_apps_models=models)) with patch.object(apps, "get_app_config", return_value=app_config): self.assertEqual(supported_models(), models)
def test_config_with_multiple_apps(self): registered_models = supported_models() expected_models = { TestModel1: [], TestModel2: [], TestModel3: [], TestModel4: [], Page: ["title"], PollContent: ["text"], } self.assertDictEqual(registered_models, expected_models)
def get_data(self): content_type_id = self.request.GET.get("content_type_id", None) query = self.request.GET.get("query", None) site = self.request.GET.get("site") content_object = ContentType.objects.get_for_id(content_type_id) model = content_object.model_class() try: # If versioning is enabled then get versioning queryset for model app_config = apps.get_app_config("djangocms_versioning") versionable_item = app_config.cms_extension.versionables_by_grouper[ model] queryset = versionable_item.grouper_choices_queryset() except (LookupError, KeyError): queryset = model.objects.all() try: pk = int(self.request.GET.get("pk")) except (TypeError, ValueError): pk = None if site: if hasattr(model.objects, "on_site"): queryset = queryset.on_site(site) elif hasattr(model, "site"): queryset = queryset.filter(site=site) if pk: queryset = queryset.filter(pk=pk) if query: # TODO: filter by language and publish state # For Page model filter query by pagecontent title if model == Page: queryset = queryset.filter( pagecontent_set__title__icontains=query) else: # Non page model should work using filter against field in queryset options = {} search_fields = supported_models( self.menu_content_model).get(model) if search_fields: for field in search_fields: options[field] = query queryset = queryset.filter(**options) return queryset
def test_supported_models_returns_empty_list_on_lookup_error( self, mocked_apps): self.assertDictEqual(supported_models(), {})