def test_valid_number_passed_in_request(self): bottle.request.environ = {'QUERY_STRING': 'offset=2'} kwargs = {} rest.validate_range_values(bottle.request, 'offset', kwargs) self.assertEqual(2, kwargs['offset']) self.assertEqual(200, bottle.response.status_code)
def test_nothing_provided_is_valid_but_none(self): bottle.request.environ = {'QUERY_STRING': ''} kwargs = {} rest.validate_range_values(bottle.request, 'offset', kwargs) self.assertEqual(None, kwargs.get('offset')) self.assertEqual(200, bottle.response.status_code)
def test_valid_number_passed_in_param(self): bottle.request.environ = {'QUERY_STRING': ''} kwargs = {'limit': '4236'} rest.validate_range_values(bottle.request, 'limit', kwargs) self.assertEqual(4236, kwargs['limit']) self.assertEqual(200, bottle.response.status_code)
def test_non_numeric_is_invalid(self): bottle.request.environ = {'QUERY_STRING': 'limit=blah'} kwargs = {} with self.assertRaises(ValueError): rest.validate_range_values(bottle.request, 'limit', kwargs)
def test_value_too_large(self): bottle.request.environ = {'QUERY_STRING': 'offset=20000000'} kwargs = {} with self.assertRaises(ValueError): rest.validate_range_values(bottle.request, 'offset', kwargs)
def test_negative_is_invalid(self): bottle.request.environ = {'QUERY_STRING': 'offset=-2'} kwargs = {} with self.assertRaises(ValueError): rest.validate_range_values(bottle.request, 'offset', kwargs)