def test_ajax_select_view_with_products(rf): activate("en") view = MultiselectAjaxView.as_view() results = _get_search_results(rf, view, "shoop.Product", "some str") assert len(results) == 0 product_name_en = "The Product" product = create_product("the product", **{"name": product_name_en}) product_name_fi = "product" product.set_current_language("fi") # Making sure we are not getting duplicates from translations product.name = "product" # It seems that finnish translation overlaps with english name product.save() view = MultiselectAjaxView.as_view() results = _get_search_results(rf, view, "shoop.Product", "some str") assert len(results) == 0 results = _get_search_results(rf, view, "shoop.Product", "product") assert len(results) == 1 assert results[0].get("id") == product.id assert results[0].get("name") == product_name_en activate("fi") results = _get_search_results(rf, view, "shoop.Product", "product") assert len(results) == 1 assert results[0].get("id") == product.id assert results[0].get("name") == product_name_fi
def get_urls(): urls = [] urls.extend(get_module_urls()) urls.extend([ admin_url(r'^$', DashboardView.as_view(), name='dashboard'), admin_url(r'^search/$', SearchView.as_view(), name='search'), admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select'), admin_url(r'^menu/$', MenuView.as_view(), name='menu'), admin_url(r'^login/$', login, kwargs={"template_name": "shoop/admin/auth/login.jinja"}, name='login', require_authentication=False), admin_url(r'^logout/$', auth_views.logout, kwargs={"template_name": "shoop/admin/auth/logout.jinja"}, name='logout', require_authentication=False), admin_url(r'^set-language/$', csrf_exempt(set_language), name="set-language"), ]) for u in urls: # pragma: no cover if not isinstance(u, AdminRegexURLPattern): warnings.warn("Admin URL %r is not an AdminRegexURLPattern" % u) # Add Django javascript catalog url urls.append(url(r'^i18n.js$', javascript_catalog_all, name='js-catalog')) return tuple(urls)
def test_ajax_select_view_with_contacts(rf, contact_cls): view = MultiselectAjaxView.as_view() model_name = "shoop.%s" % contact_cls._meta.model_name results = _get_search_results(rf, view, model_name, "some str") assert len(results) == 0 customer = contact_cls.objects.create(name="Michael Jackson", email="*****@*****.**") results = _get_search_results(rf, view, model_name, "michael") assert len(results) == 1 assert results[0].get("id") == customer.id assert results[0].get("name") == customer.name results = _get_search_results(rf, view, model_name, "jacks") assert len(results) == 1 assert results[0].get("id") == customer.id assert results[0].get("name") == customer.name results = _get_search_results(rf, view, model_name, "el@ex") assert len(results) == 1 assert results[0].get("id") == customer.id assert results[0].get("name") == customer.name results = _get_search_results( rf, view, model_name, "random") # Shouldn't find anything with this assert len(results) == 0
def test_multiselect_inactive_users_and_contacts(rf, regular_user): """ Make sure inactive users and contacts are filtered from search results. """ view = MultiselectAjaxView.as_view() assert "joe" in regular_user.username results = _get_search_results(rf, view, "auth.User", "joe") assert len(results) == 1 assert results[0].get("id") == regular_user.id assert results[0].get("name") == regular_user.username contact = PersonContact.objects.create(first_name="Joe", last_name="Somebody") results = _get_search_results(rf, view, "shoop.PersonContact", "joe") assert len(results) == 1 assert results[0].get("id") == contact.id assert results[0].get("name") == contact.name contact.is_active = False contact.save() results = _get_search_results(rf, view, "shoop.PersonContact", "joe") assert len(results) == 0
def get_urls(): urls = [] urls.extend(get_module_urls()) urls.extend([ admin_url(r'^$', DashboardView.as_view(), name='dashboard'), admin_url(r'^search/$', SearchView.as_view(), name='search'), admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select'), admin_url(r'^menu/$', MenuView.as_view(), name='menu'), admin_url( r'^login/$', login, kwargs={"template_name": "shoop/admin/auth/login.jinja"}, name='login', require_authentication=False ), admin_url( r'^logout/$', auth_views.logout, kwargs={"template_name": "shoop/admin/auth/logout.jinja"}, name='logout', require_authentication=False ), admin_url( r'^set-language/$', csrf_exempt(set_language), name="set-language" ), ]) for u in urls: # pragma: no cover if not isinstance(u, AdminRegexURLPattern): warnings.warn("Admin URL %r is not an AdminRegexURLPattern" % u) # Add Django javascript catalog url urls.append(url(r'^i18n.js$', javascript_catalog_all, name='js-catalog')) return tuple(urls)
def test_ajax_select_view_with_contacts(rf, contact_cls): view = MultiselectAjaxView.as_view() model_name = "shoop.%s" % contact_cls._meta.model_name results = _get_search_results(rf, view, model_name, "some str") assert len(results) == 0 customer = contact_cls.objects.create(name="Michael Jackson", email="*****@*****.**") results = _get_search_results(rf, view, model_name, "michael") assert len(results) == 1 assert results[0].get("id") == customer.id assert results[0].get("name") == customer.name results = _get_search_results(rf, view, model_name, "jacks") assert len(results) == 1 assert results[0].get("id") == customer.id assert results[0].get("name") == customer.name results = _get_search_results(rf, view, model_name, "el@ex") assert len(results) == 1 assert results[0].get("id") == customer.id assert results[0].get("name") == customer.name results = _get_search_results(rf, view, model_name, "random") # Shouldn't find anything with this assert len(results) == 0