Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Test product search result in dashboard

Jakub Draganek66473692895b
diff --git a/tests/cassettes/test_dashboard_search_with_product_result.yaml b/tests/cassettes/test_dashboard_search_with_product_result.yaml
new file mode 100644
index 0000000000..e7ef9bae36
--- /dev/null
+++ b/tests/cassettes/test_dashboard_search_with_product_result.yaml
@@ -0,0 +1,50 @@
+interactions:
+- request:
+ body: '{"query": {"multi_match": {"query": "Group", "fields": ["user", "status",
+ "discount_name"]}}, "_source": {"exclude": ["*"]}}'
+ headers:
+ connection: [keep-alive]
+ content-type: [application/json]
+ method: GET
+ uri: http://search:9200/orders/order_document/_search
+ response:
+ body: {string: '{"took":5,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}'}
+ headers:
+ Warning: ['299 Elasticsearch-5.4.3-eed30a8 "Deprecated field [exclude] used,
+ expected [excludes] instead" "Wed, 15 Nov 2017 12:23:11 GMT"']
+ content-length: ['122']
+ content-type: [application/json; charset=UTF-8]
+ status: {code: 200, message: OK}
+- request:
+ body: '{"query": {"multi_match": {"query": "Group", "fields": ["name", "description"]}},
+ "_source": {"exclude": ["*"]}}'
+ headers:
+ connection: [keep-alive]
+ content-type: [application/json]
+ method: GET
+ uri: http://search:9200/storefront/product_document/_search
+ response:
+ body: {string: '{"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":2,"max_score":3.3258386,"hits":[{"_index":"storefront","_type":"product_document","_id":"6","_score":3.3258386,"_source":{}},{"_index":"storefront","_type":"product_document","_id":"29","_score":3.3258386,"_source":{}}]}}'}
+ headers:
+ Warning: ['299 Elasticsearch-5.4.3-eed30a8 "Deprecated field [exclude] used,
+ expected [excludes] instead" "Wed, 15 Nov 2017 12:23:11 GMT"']
+ content-length: ['313']
+ content-type: [application/json; charset=UTF-8]
+ status: {code: 200, message: OK}
+- request:
+ body: '{"query": {"multi_match": {"query": "Group", "fields": ["user"]}}, "_source":
+ {"exclude": ["*"]}}'
+ headers:
+ connection: [keep-alive]
+ content-type: [application/json]
+ method: GET
+ uri: http://search:9200/users/user_document/_search
+ response:
+ body: {string: '{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}'}
+ headers:
+ Warning: ['299 Elasticsearch-5.4.3-eed30a8 "Deprecated field [exclude] used,
+ expected [excludes] instead" "Wed, 15 Nov 2017 12:23:11 GMT"']
+ content-length: ['122']
+ content-type: [application/json; charset=UTF-8]
+ status: {code: 200, message: OK}
+version: 1
diff --git a/tests/test_search.py b/tests/test_search.py
index 3acc329058..df366628cd 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -5,7 +5,9 @@ from decimal import Decimal
import pytest
MATCH_SEARCH_REQUEST = ['method', 'host', 'port', 'path', 'body']
-PRODUCTS_INDEXED = {15, 56} # same as in recorded data!
+STOREFRONT_PRODUCTS = {15,56} # same as in recorded data!
+DASHBOARD_PRODUCTS = {6, 29}
+PRODUCTS_INDEXED = STOREFRONT_PRODUCTS | DASHBOARD_PRODUCTS
PRODUCTS_TO_UNPUBLISH = {56} # choose from PRODUCTS_INDEXED
PHRASE_WITH_RESULTS = 'Group'
PHRASE_WITHOUT_RESULTS = 'foo'
@@ -64,7 +66,7 @@ def test_new_search_with_empty_results(db, client):
def test_new_search_with_result(db, indexed_products, client):
''' some products founds, only those both in search result and objects '''
found_products = execute_search(client, PHRASE_WITH_RESULTS)
- assert PRODUCTS_INDEXED == set(found_products)
+ assert STOREFRONT_PRODUCTS == set(found_products)
@pytest.fixture
@@ -80,7 +82,7 @@ def products_with_mixed_publishing(indexed_products):
@pytest.mark.vcr(record_mode='once', match_on=MATCH_SEARCH_REQUEST)
def test_new_search_doesnt_show_unpublished(db, products_with_mixed_publishing,
client):
- published_products = PRODUCTS_INDEXED - PRODUCTS_TO_UNPUBLISH
+ published_products = STOREFRONT_PRODUCTS - PRODUCTS_TO_UNPUBLISH
found_products = execute_search(client, PHRASE_WITH_RESULTS)
assert published_products == set(found_products)
@@ -103,3 +105,13 @@ def test_dashboard_search_with_empty_results(db, admin_client):
assert 0 == len(products)
assert 0 == len(users)
assert 0 == len(orders)
+
+
[email protected](record_mode='once', match_on=MATCH_SEARCH_REQUEST)
+def test_dashboard_search_with_product_result(db, indexed_products,
+ admin_client):
+ ''' products found in dashboard search view '''
+ products, _, _ = execute_dashboard_search(admin_client,
+ PHRASE_WITH_RESULTS)
+ assert DASHBOARD_PRODUCTS == products