def test_filters(self): request = bottle.BaseRequest( environ={'QUERY_STRING': 'status=A&status=B,C&other=2'}) expected = {'status': ['A', 'B', 'C'], 'other': '2'} results = rest.process_params(request, filter_fields=['status', 'other']) self.assertEqual(results, expected)
def test_dfaults(self): request = bottle.BaseRequest( environ={'QUERY_STRING': 'status=INACTIVE'}) defaults = {'status': 'ACTIVE', 'size': 1} results = rest.process_params(request, filter_fields=defaults.keys(), defaults=defaults) self.assertEqual(results, {'status': 'INACTIVE', 'size': 1})
def test_dfaults(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': 'status=INACTIVE' }) defaults = {'status': 'ACTIVE', 'size': 1} results = rest.process_params(request, filter_fields=defaults.keys(), defaults=defaults) self.assertEqual(results, {'status': 'INACTIVE', 'size': 1})
def test_filters(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': 'status=A&status=B,C&other=2' }) expected = {'status': ['A', 'B', 'C'], 'other': '2'} results = rest.process_params(request, filter_fields=['status', 'other']) self.assertEqual(results, expected)
def test_strange(self): request = bottle.BaseRequest(environ={'QUERY_STRING': ',,\n??&&'}) with self.assertRaises(bottle.HTTPError): rest.process_params(request)
def test_blank(self): request = bottle.BaseRequest(environ={'QUERY_STRING': ''}) results = rest.process_params(request) self.assertEqual(results, {})
def test_invalid(self): request = bottle.BaseRequest(environ={'QUERY_STRING': 'foo=bar'}) with self.assertRaises(bottle.HTTPError): rest.process_params(request)
def test_text(self): request = bottle.BaseRequest(environ={'QUERY_STRING': 'q=txt'}) results = rest.process_params(request) self.assertEqual(results, {'q': ['txt']})
def test_standard(self): request = bottle.BaseRequest( environ={'QUERY_STRING': 'limit=100&offset=0&facets=status'}) results = rest.process_params(request) self.assertEqual(results, {})
def test_sort(self): request = bottle.BaseRequest( environ={'QUERY_STRING': 'sort=up&sort=-down'}) expected = {'sort': ['up', '-down']} self.assertEqual(rest.process_params(request), expected)
def test_strange(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': ',,\n??&&' }) with self.assertRaises(bottle.HTTPError): rest.process_params(request)
def test_blank(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': '' }) results = rest.process_params(request) self.assertEqual(results, {})
def test_invalid(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': 'foo=bar' }) with self.assertRaises(bottle.HTTPError): rest.process_params(request)
def test_standard(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': 'limit=100&offset=0&q=txt&facets=status' }) results = rest.process_params(request) self.assertEqual(results, {})
def test_sort(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': 'sort=up&sort=-down' }) expected = {'sort': ['up', '-down']} self.assertEqual(rest.process_params(request), expected)
def test_text(self): request = bottle.BaseRequest(environ={ 'QUERY_STRING': 'q=txt' }) results = rest.process_params(request) self.assertEqual(results, {'q': ['txt']})