Repository: Kinto/kinto

Issue:
Remove usage of assert 
```

--------------------------------------------------
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
   Severity: Low   Confidence: High
   Location: kinto/core/storage/postgresql/__init__.py:593
592	        if limit:
593	            assert isinstance(limit, six.integer_types)  # asserted in resource
594	            safeholders['pagination_limit'] = 'LIMIT %s' % limit

```


```
--------------------------------------------------
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
   Severity: Low   Confidence: High
   Location: kinto/core/storage/generators.py:22
21	        error_msg = "Generated record id does comply with regexp."
22	        assert self.match(self()), error_msg
23	

```


```

--------------------------------------------------
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
   Severity: Low   Confidence: High
   Location: kinto/core/errors.py:135
134	    errors = request.errors
135	    assert len(errors) != 0
136	
137	    sorted_errors = sorted(errors, key=lambda x: six.text_type(x['name']))

```
Remove usage of assert 
```

--------------------------------------------------
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
   Severity: Low   Confidence: High
   Location: kinto/core/storage/postgresql/__init__.py:593
592	        if limit:
593	            assert isinstance(limit, six.integer_types)  # asserted in resource
594	            safeholders['pagination_limit'] = 'LIMIT %s' % limit

```


```
--------------------------------------------------
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
   Severity: Low   Confidence: High
   Location: kinto/core/storage/generators.py:22
21	        error_msg = "Generated record id does comply with regexp."
22	        assert self.match(self()), error_msg
23	

```


```

--------------------------------------------------
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
   Severity: Low   Confidence: High
   Location: kinto/core/errors.py:135
134	    errors = request.errors
135	    assert len(errors) != 0
136	
137	    sorted_errors = sorted(errors, key=lambda x: six.text_type(x['name']))

```


Discussion:

Resolving patch:
diff --git a/kinto/core/errors.py b/kinto/core/errors.py
--- a/kinto/core/errors.py
+++ b/kinto/core/errors.py
@@ -132,9 +132,8 @@ def json_error_handler(request):
         (c.f. HTTP API).
     """
     errors = request.errors
-    assert len(errors) != 0
-
     sorted_errors = sorted(errors, key=lambda x: six.text_type(x['name']))
+    # In Cornice, we call error handler if at least one error was set.
     error = sorted_errors[0]
     name = error['name']
     description = error['description']
diff --git a/kinto/core/storage/generators.py b/kinto/core/storage/generators.py
--- a/kinto/core/storage/generators.py
+++ b/kinto/core/storage/generators.py
@@ -18,8 +18,9 @@ def __init__(self, config=None):
         self.config = config
         self._regexp = None
 
-        error_msg = "Generated record id does comply with regexp."
-        assert self.match(self()), error_msg
+        if not self.match(self()):
+            error_msg = "Generated record id does comply with regexp."
+            raise ValueError(error_msg)
 
     def match(self, record_id):
         """Validate that record ids match the generator. This is used mainly
diff --git a/kinto/core/storage/postgresql/__init__.py b/kinto/core/storage/postgresql/__init__.py
--- a/kinto/core/storage/postgresql/__init__.py
+++ b/kinto/core/storage/postgresql/__init__.py
@@ -590,7 +590,7 @@ def get_all(self, collection_id, parent_id, filters=None, sorting=None,
             placeholders.update(**holders)
 
         if limit:
-            assert isinstance(limit, six.integer_types)  # asserted in resource
+            # We validate the limit value in the resource class as integer.
             safeholders['pagination_limit'] = 'LIMIT %s' % limit
 
         with self.client.connect(readonly=True) as conn:


Test patch:
diff --git a/tests/core/test_storage.py b/tests/core/test_storage.py
--- a/tests/core/test_storage.py
+++ b/tests/core/test_storage.py
@@ -17,7 +17,7 @@ class Dumb(generators.Generator):
             def __call__(self):
                 return '*' * 80
 
-        self.assertRaises(AssertionError, Dumb)
+        self.assertRaises(ValueError, Dumb)
 
     def test_default_generator_allow_underscores_dash_alphabet(self):
         class Dumb(generators.Generator):