Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add storefront search test and fuzziness
Jakub Draganek5135e531bcf4
diff --git a/tests/test_postgresql_search.py b/tests/test_postgresql_search.pyindex 740b9891cf..0f1cd16865 100644--- a/tests/test_postgresql_search.py+++ b/tests/test_postgresql_search.py@@ -14,12 +14,6 @@ def postgresql_search_enabled(settings):settings.PREFER_DB_SEARCH = True-def test_dummy_integration(client):- phrase = 'foo'- client.get(reverse('search:search'), {'q': phrase})--PRODUCTS = [('Arabica Coffee', 'The best grains in galactic'),('Cool T-Shirt', 'Blue and big.'),('Roasted chicken', 'Fabulous vertebrate')]@@ -27,16 +21,29 @@ PRODUCTS = [('Arabica Coffee', 'The best grains in galactic'),@pytest.fixturedef named_products(default_category, product_class):- products = []- for name, description in PRODUCTS:+ def gen_product(name, description):product = Product.objects.create(name=name,description=description,price=Decimal(6.6),product_class=product_class)product.categories.add(default_category)- products.append(product)- return products+ return product+ return [gen_product(name, desc) for name, desc in PRODUCTS]++[email protected]('phrase,product_num',+ [('Arabika', 0), ('Aarabica', 0), ('Arab', 0),+ ('czicken', 2), ('blue', 1), ('roast', 2),+ ('coool', 1)])[email protected]_db(transaction=True)+def test_storefront_product_fuzzy_search(client, named_products, phrase,+ product_num):+ resp = client.get(reverse('search:search'), {'q': phrase})+ results = [prod for prod, _ in resp.context['results'].object_list]+ assert 1 == len(results)+ assert named_products[product_num] in results@pytest.mark.integration@@ -51,7 +58,7 @@ def test_search_empty_results(admin_client, named_products):@pytest.mark.integration@pytest.mark.django_db(transaction=True)def test_find_product_by_name(admin_client, named_products):- phrase = 'Coffee'+ phrase = 'coffee'resp = admin_client.get(reverse('dashboard:search'), {'q': phrase})assert 1 == len(resp.context['products'])assert named_products[0] in resp.context['products']@@ -60,7 +67,7 @@ def test_find_product_by_name(admin_client, named_products):@pytest.mark.integration@pytest.mark.django_db(transaction=True)def test_find_product_by_description(admin_client, named_products):- phrase = 'big'+ phrase = 'BIG'resp = admin_client.get(reverse('dashboard:search'), {'q': phrase})assert 1 == len(resp.context['products'])assert named_products[1] in resp.context['products']