Skip to content

Commit

Permalink
SNO-183-allow-specification-of-cart-in-search (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
keenangraham authored Dec 12, 2020
1 parent 8745db0 commit b935f22
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/snovault/elasticsearch/searches/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,12 @@ class SearchBaseResponseField(ResponseField):
(Same query_string, different path.)
'''

def __init__(self, *args, **kwargs):
def __init__(self, search_base=SEARCH_PATH, *args, **kwargs):
self.search_base = search_base
super().__init__(*args, **kwargs)

def _get_search_base(self):
search_base = SEARCH_PATH
search_base = self.search_base
qs = self.get_request().query_string
if qs:
search_base += '?' + qs
Expand Down
1 change: 1 addition & 0 deletions src/snovault/elasticsearch/searches/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
BOOL = 'bool'
BOOST_VALUES = 'boost_values'
BUCKETS = 'buckets'
CART_KEY = 'cart'
CLEAR_FILTERS = 'clear_filters'
COLLECTION_NAME = 'item_type'
COLUMNS = 'columns'
Expand Down
7 changes: 7 additions & 0 deletions src/snovault/elasticsearch/searches/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import defaultdict

from .interfaces import ADVANCED_QUERY_KEY
from .interfaces import CART_KEY
from .interfaces import DEBUG_KEY
from .interfaces import FIELD_KEY
from .interfaces import FROM_KEY
Expand Down Expand Up @@ -286,6 +287,12 @@ def get_debug(self, params=None):
params=params
)

def get_cart(self, params=None):
return self.get_key_filters(
key=CART_KEY,
params=params
)

def group_values_by_key(self, params=None):
values_by_key = defaultdict(list)
for p in self._params(params):
Expand Down
6 changes: 6 additions & 0 deletions src/snovault/tests/test_searches_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ def test_searches_fields_search_base_get_search_base(dummy_parent):
sb = SearchBaseResponseField()
sb.parent = dummy_parent
assert sb._get_search_base() == '/search/'
dummy_parent._meta['params_parser']._request.environ['QUERY_STRING'] = (
''
)
sb = SearchBaseResponseField(search_base='/different-search/')
sb.parent = dummy_parent
assert sb._get_search_base() == '/different-search/'


def test_searches_fields_search_base_render(dummy_parent):
Expand Down
12 changes: 12 additions & 0 deletions src/snovault/tests/test_searches_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,18 @@ def test_searches_parsers_params_parser_get_debug(dummy_request):
]


def test_searches_parsers_params_parser_get_cart(dummy_request):
from snovault.elasticsearch.searches.parsers import ParamsParser
dummy_request.environ['QUERY_STRING'] = (
'frame=embedded&status!=submitted&type=File&sort=date_created&debug=true&cart=abc123&cart=def456'
)
p = ParamsParser(dummy_request)
assert p.get_cart() == [
('cart', 'abc123'),
('cart', 'def456')
]


def test_searches_parsers_params_parser_param_keys_to_list(dummy_request):
from snovault.elasticsearch.searches.parsers import ParamsParser
dummy_request.environ['QUERY_STRING'] = (
Expand Down

0 comments on commit b935f22

Please sign in to comment.