Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test if unpublished products appear in search results
Jakub Draganek2334fd1afcd9
diff --git a/tests/cassettes/test_new_search_doesnt_show_unpublished.yaml b/tests/cassettes/test_new_search_doesnt_show_unpublished.yamlnew file mode 100644index 0000000000..c0fed486de--- /dev/null+++ b/tests/cassettes/test_new_search_doesnt_show_unpublished.yaml@@ -0,0 +1,17 @@+interactions:+- request:+ body: '{"_source": ["pk"], "query": {"bool": {"must": [{"multi_match": {"fields":+ ["name", "description"], "query": "Group"}}], "filter": [{"term": {"is_published_filter":+ true}}, {"match": {"content_type": "product.Product"}}]}}}'+ headers:+ connection: [keep-alive]+ content-type: [application/json]+ method: GET+ uri: http://search:9200/storefront__product_product/_search+ response:+ body: {string: '{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":3.2280896,"hits":[{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:58","_score":3.2280896,"_source":{"pk":"58"}},{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:15","_score":2.7298274,"_source":{"pk":"15"}},{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:34","_score":2.7298274,"_source":{"pk":"34"}}]}}'}+ headers:+ content-length: ['531']+ content-type: [application/json; charset=UTF-8]+ status: {code: 200, message: OK}+version: 1diff --git a/tests/cassettes/test_new_search_with_result.yaml b/tests/cassettes/test_new_search_with_result.yamlnew file mode 100644index 0000000000..c8b91750c5--- /dev/null+++ b/tests/cassettes/test_new_search_with_result.yaml@@ -0,0 +1,17 @@+interactions:+- request:+ body: '{"_source": ["pk"], "query": {"bool": {"filter": [{"term": {"is_published_filter":+ true}}, {"match": {"content_type": "product.Product"}}], "must": [{"multi_match":+ {"query": "Group", "fields": ["name", "description"]}}]}}}'+ headers:+ connection: [keep-alive]+ content-type: [application/json]+ method: GET+ uri: http://search:9200/storefront__product_product/_search+ response:+ body: {string: '{"took":9,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":3.2280896,"hits":[{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:58","_score":3.2280896,"_source":{"pk":"58"}},{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:15","_score":2.7298274,"_source":{"pk":"15"}},{"_index":"storefront__product_product","_type":"product_product","_id":"product_product:34","_score":2.7298274,"_source":{"pk":"34"}}]}}'}+ headers:+ content-length: ['531']+ content-type: [application/json; charset=UTF-8]+ status: {code: 200, message: OK}+version: 1diff --git a/tests/test_search.py b/tests/test_search.pyindex 7507fd3190..71c66ae93c 100644--- a/tests/test_search.py+++ b/tests/test_search.py@@ -99,9 +99,46 @@ def test_new_search_with_empty_results(db, client, new_search_backend):assert WORD == response.context['query']+def other_indexed_products(product_class, default_category):+ def gen_product_with_id(object_id):+ product = Product.objects.create(+ pk=object_id,+ name='Test product ' + str(object_id),+ price=Decimal(10.0),+ product_class=product_class)+ product.categories.add(default_category)+ return product+ return [gen_product_with_id(prod) for prod in [15, 58]]++@pytest.mark.integration@pytest.mark.vcr(record_mode='once', match_on=MATCH_SEARCH_REQUEST)-def test_new_search_with_results(db, client, new_search_backend):- WORD = 'group'- response = client.get(reverse('search:search'), {'q': WORD})- _extract_pks(response.context['results'].object_list)+def test_new_search_with_result(db, other_indexed_products, client,+ new_search_backend):+ EXISTING_PHRASE = 'Group'+ response = client.get(reverse('search:search'), {'q': EXISTING_PHRASE})+ found_products = _extract_pks(response.context['results'].object_list)+ assert [15, 58] == sorted(found_products)+ assert EXISTING_PHRASE == response.context['query']+++def products_with_mixed_publishing(other_indexed_products):+ UNPUBLISH_PK = [15]+ products_to_unpublish = Product.objects.filter(pk__in=UNPUBLISH_PK)+ for prod in products_to_unpublish:+ prod.is_published = False+ prod.save()+ return other_indexed_products++[email protected](record_mode='once', match_on=MATCH_SEARCH_REQUEST)+def test_new_search_doesnt_show_unpublished(db, products_with_mixed_publishing,+ client, new_search_backend):+ EXISTING_PHRASE = 'Group'+ response = client.get(reverse('search:search'), {'q': EXISTING_PHRASE})+ found_products = _extract_pks(response.context['results'].object_list)+ assert [58] == found_products+ assert EXISTING_PHRASE == response.context['query']