Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add test for limited array validation

Signed-off-by: Rick Copeland <rick@arborian.com>
  • Loading branch information...
commit 291ec69a9815db6f271bc82bbdd33af588e06aa6 1 parent 045a1c2
@rick446 rick446 authored brondsem committed
Showing with 20 additions and 8 deletions.
  1. +13 −8 benchmarks/validation.py
  2. +7 −0 ming/tests/test_schema.py
View
21 benchmarks/validation.py
@@ -5,7 +5,7 @@
from ming import schema as S
from ming.datastore import DataStore
-NUM_ITER = 10
+NUM_ITER = 100
doc_session = Session.by_name('benchmark')
@@ -130,12 +130,13 @@ class __mongometa__:
read_operations=int,
location=str,
type=str) ])
- releases=Field([dict(
+ releases=Field(
+ S.Array(
+ dict(
filename=str,
url=str,
date=datetime,
bytes=float,
- download_count=S.Deprecated,
file_type=S.String(if_missing=''),
mime_type=str,
md5sum=str,
@@ -145,11 +146,15 @@ class __mongometa__:
sf_release_id=int, sf_package_id=int, sf_type=str, sf_platform=[str],
release_notes_url=str,
# old FRS data (shouldn't exist any more)
- group=S.Deprecated, #str,
- version=S.Deprecated, #str,
- changelog=S.Deprecated, #str,
- release_notes=S.Deprecated, #str,
- )])
+ # download_count=S.Deprecated,
+ # group=S.Deprecated, #str,
+ # version=S.Deprecated, #str,
+ # changelog=S.Deprecated, #str,
+ # release_notes=S.Deprecated, #str,
+ ),
+ validate_ranges=(
+ slice(0, 5), slice(-5, -1))
+ ))
download_page=Field(str)
screenshot_page=Field(str)
maintainers=Field([_person])
View
7 ming/tests/test_schema.py
@@ -46,6 +46,13 @@ def test_make_array(self):
self.assertEqual(S.Int, si_int.field_type.__class__)
self.assertRaises(ValueError, S.SchemaItem.make, [int, str])
+ def test_validate_limited_range(self):
+ si = S.Array(
+ int,
+ validate_ranges=[slice(0, 2) ])
+ si.validate([1,2,'foo', 'bar'])
+ self.assertRaises(S.Invalid, si.validate, [1,'foo', 'bar'])
+
def test_dict_is_not_array(self):
si = S.SchemaItem.make([])
self.assertRaises(S.Invalid, si.validate, {})
Please sign in to comment.
Something went wrong with that request. Please try again.