Commits

Jean-Tiare Le Bigot  committed 7cbf4ab

store empty field raise validationerror (fix #4), fix item count checks in list validation

  • Participants
  • Parent commits 2fa4e87

Comments (0)

Files changed (4)

 
 - accurate table statuses
 - fix pyramid entry-point
+- fix list validations. Len limitation was not working
+- attempt to store empty field/set raise ValidationError (#4)
 
 =============
 ddbmock 0.3.0

File ddbmock/validators/types.py

     range(min=Decimal('1E-128'), max=Decimal('1E+126'), msg="Number values must be between 10^-128 to 10^+126"),
 )
 
-field_string_value = unicode
+field_string_value = all(unicode, length(min=1, msg="String fields can not be empty"))
 
 field_binary_value = all(
     unicode,
+    length(min=1, msg="Binary data fields can not be empty"),
     match(base_64, msg="Binary data must be base64 encoded"),
 
 )
 
-field_number_set_value = [field_number_value]
-field_string_set_value = [field_string_value]
-field_binary_set_value = [field_binary_value]
+field_number_set_value = all(length(min=1, msg="A set can not be empty"), [field_number_value])
+field_string_set_value = all(length(min=1, msg="A set can not be empty"), [field_string_value])
+field_binary_set_value = all(length(min=1, msg="A set can not be empty"), [field_binary_value])
 
 # complex types
 
 field_value = simple_field_value.copy()
 field_value.update(set_field_value)
 
-single_str_num_bin_list = [all(length(min=1, max=1), simple_field_value)]
-single_str_bin_list = [all(length(min=1, max=1), {
+single_str_num_bin_list = all(length(min=1, max=1), [simple_field_value])
+single_str_bin_list = all(length(min=1, max=1), [{
     optional(u'S'): field_string_value,
     optional(u'B'): field_binary_value,
-})]
+}])
 
 item_schema = {
     required(field_name): field_value,

File tests/functional/boto/test_put_item.py

     TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
     u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
 }
+ITEM3_EMPTY_FIELD = {
+    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
+    u'relevant_data': {u'B': u''},
+}
+ITEM3_EMPTY_SET = {
+    TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
+    u'relevant_data': {u'B': u'THVkaWEgaXMgdGhlIGJlc3QgY29tcGFueSBldmVyIQ=='},
+    u'empty_set': {u'NS': []},
+}
 ITEM4 = {
     TABLE_HK_NAME: {TABLE_HK_TYPE: HK_VALUE},
     u'irelevant_data': {u'B': u'WW91IHdpc2ggeW91IGNvdWxkIGNoYW5nZSB5b3VyIGpvYi4uLg=='},
             db.layer1.put_item(TABLE_NAME2, ITEM4, return_values=u'ALL_OLD'),
         )
 
+    def test_put_h_empty_field_fail(self):
+        # From http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_PutItem.html
+        # Attribute values may not be null; string and binary type attributes must have lengths greater than zero; and set type attributes must not be empty. Requests with empty values will be rejected with a ValidationException.
+        from ddbmock import connect_boto
+        from ddbmock.database.db import DynamoDB
+        from boto.dynamodb.exceptions import DynamoDBValidationError
+
+        db = connect_boto()
+
+        self.assertRaises(DynamoDBValidationError,
+                          db.layer1.put_item,
+                          TABLE_NAME2, ITEM3_EMPTY_SET)
+
+        self.assertFalse(self.t2.data[HK_VALUE][False])
+
+        self.assertRaises(DynamoDBValidationError,
+                          db.layer1.put_item,
+                          TABLE_NAME2, ITEM3_EMPTY_FIELD)
+
+        self.assertFalse(self.t2.data[HK_VALUE][False])
+
     def test_put_hr_404(self):
         from ddbmock import connect_boto
         from ddbmock.database.db import DynamoDB

File tests/functional/boto/test_query.py

         ret = db.layer1.query(TABLE_NAME, {TABLE_HK_TYPE: HK_VALUE}, condition, fields)
         self.assertEqual(expected, ret)
 
+    def test_query_invalid_condition_multiple_data_in_field(self):
+        from ddbmock import connect_boto
+        from ddbmock.database.db import DynamoDB
+        from boto.dynamodb.exceptions import DynamoDBValidationError
+
+        condition = {
+            "AttributeValueList":[
+                {"S":"Waldo-2"},
+                {"S":"Waldo-3"},
+            ],
+            "ComparisonOperator":"GT"
+        }
+        fields = [u'relevant_data']
+
+        db = connect_boto()
+
+        self.assertRaises(DynamoDBValidationError,
+                          db.layer1.query,
+                          TABLE_NAME, {TABLE_HK_TYPE: HK_VALUE}, condition, fields)
+