Skip to content

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

Test dashboard search queries generation

Jakub Draganek1109089f876e
diff --git a/saleor/search/backends/elasticsearch_dashboard.py b/saleor/search/backends/elasticsearch_dashboard.py
index 7d0643ba10..ca65c3e498 100644
--- a/saleor/search/backends/elasticsearch_dashboard.py
+++ b/saleor/search/backends/elasticsearch_dashboard.py
@@ -19,4 +19,5 @@ def get_search_query(phrase):
def search(phrase):
+ ''' Provide queryset for every search result '''
return {k: s.to_queryset() for k, s in get_search_query(phrase).items()}
diff --git a/saleor/search/backends/test_dashboard.py b/saleor/search/backends/test_dashboard.py
new file mode 100644
index 0000000000..a9aaa74e82
--- /dev/null
+++ b/saleor/search/backends/test_dashboard.py
@@ -0,0 +1,39 @@
+from __future__ import unicode_literals
+from . import elasticsearch_dashboard
+
+
+PHRASE = 'You can go to the west'
+PRODUCT_QUERY = {
+ '_source': False,
+ 'query': {
+ 'multi_match': {
+ 'fields': ['name', 'description'],
+ 'query': PHRASE
+ }
+ }
+}
+ORDERS_QUERY = {
+ '_source': False,
+ 'query': {
+ 'multi_match': {
+ 'fields': ['user_email', 'status', 'discount_name'],
+ 'query': PHRASE
+ }
+ }
+}
+USERS_QUERY = {
+ '_source': False,
+ 'query': {
+ 'match': {
+ 'email': PHRASE
+ }
+ }
+}
+
+
+def test_dashboard_search_query_syntax():
+ ''' Check if generated ES queries have desired syntax '''
+ searches = elasticsearch_dashboard.get_search_query(PHRASE)
+ assert PRODUCT_QUERY == searches['products'].to_dict()
+ assert ORDERS_QUERY == searches['orders'].to_dict()
+ assert USERS_QUERY == searches['users'].to_dict()