Ejemplo n.º 1
0
    def test_action_delete(self):
        from ddbmock.database.item import Item

        # field does not exist (just ignores)
        item = Item({})
        item._apply_action(FIELDNAME, {"Action": "DELETE", "Value": VALUE_S})
        self.assertEqual([], item.items())

        # delete scalar value
        item = Item({
            FIELDNAME: VALUE_S,
        })
        item._apply_action(FIELDNAME, {"Action": "DELETE"})
        self.assertEqual([], item.items())

        # delete set from set
        item = Item({
            FIELDNAME: VALUE_SS,
        })
        item._apply_action(FIELDNAME, {"Action": "DELETE", "Value": VALUE_SS_DEL})
        self.assertEqual([(FIELDNAME, VALUE_SS_SUR)], item.items())

        # delete set all from set
        item = Item({
            FIELDNAME: VALUE_SS,
        })
        item._apply_action(FIELDNAME, {"Action": "DELETE", "Value": VALUE_SS})
        self.assertEqual([], item.items())
Ejemplo n.º 2
0
    def test_action_delete(self):
        from ddbmock.database.item import Item

        # field does not exist (just ignores)
        item = Item({})
        item._apply_action(FIELDNAME, {"Action": "DELETE", "Value": VALUE_S})
        self.assertEqual([], item.items())

        # delete scalar value
        item = Item({
            FIELDNAME: VALUE_S,
        })
        item._apply_action(FIELDNAME, {"Action": "DELETE"})
        self.assertEqual([], item.items())

        # delete set from set
        item = Item({
            FIELDNAME: VALUE_SS,
        })
        item._apply_action(FIELDNAME, {
            "Action": "DELETE",
            "Value": VALUE_SS_DEL
        })
        self.assertEqual([(FIELDNAME, VALUE_SS_SUR)], item.items())

        # delete set all from set
        item = Item({
            FIELDNAME: VALUE_SS,
        })
        item._apply_action(FIELDNAME, {"Action": "DELETE", "Value": VALUE_SS})
        self.assertEqual([], item.items())
Ejemplo n.º 3
0
    def test_action_add(self):
        from ddbmock.database.item import Item

        # add value to int field
        item = Item({FIELDNAME: VALUE_N})
        item._apply_action(FIELDNAME, {"Action": "ADD", "Value": VALUE_N})
        self.assertEqual([(FIELDNAME, VALUE_N_X2)], item.items())

        # push value to any set
        item = Item({FIELDNAME: VALUE_SS})
        item._apply_action(FIELDNAME, {"Action": "ADD", "Value": VALUE_SS_DEL})
        self.assertEqual([(FIELDNAME, VALUE_SS_RES)], item.items())

        # field does not exist
        item = Item({})
        item._apply_action(FIELDNAME, {"Action": "ADD", "Value": VALUE_NS})
        self.assertEqual([(FIELDNAME, VALUE_NS)], item.items())
Ejemplo n.º 4
0
    def test_action_add(self):
        from ddbmock.database.item import Item

        # add value to int field
        item = Item({FIELDNAME: VALUE_N})
        item._apply_action(FIELDNAME, {"Action": "ADD", "Value": VALUE_N})
        self.assertEqual([(FIELDNAME, VALUE_N_X2)], item.items())

        # push value to any set
        item = Item({FIELDNAME: VALUE_SS})
        item._apply_action(FIELDNAME, {"Action": "ADD", "Value": VALUE_SS_DEL})
        self.assertEqual([(FIELDNAME, VALUE_SS_RES)], item.items())

        # field does not exist
        item = Item({})
        item._apply_action(FIELDNAME, {"Action": "ADD", "Value": VALUE_NS})
        self.assertEqual([(FIELDNAME, VALUE_NS)], item.items())

        # add string set to non existing field
        item = Item({})
        item._apply_action(FIELDNAME, {"Action": "ADD", "Value": VALUE_SS})
        self.assertEqual([(FIELDNAME, VALUE_SS)], item.items())
Ejemplo n.º 5
0
    def test_action_type_mismatch(self):
        from ddbmock.database.item import Item
        from ddbmock.errors import ValidationException

        # delete from set, set of same type
        item = Item({
            FIELDNAME: VALUE_SS,
        })
        self.assertRaises(ValidationException, item._apply_action, FIELDNAME, {
            "Action": "DELETE",
            "Value": VALUE_S
        })
        self.assertEqual([(FIELDNAME, VALUE_SS)], item.items())
        self.assertRaises(ValidationException, item._apply_action, FIELDNAME, {
            "Action": "DELETE",
            "Value": VALUE_NS
        })
        self.assertEqual([(FIELDNAME, VALUE_SS)], item.items())

        # delete value from scalar field (fail)
        item = Item({
            FIELDNAME: VALUE_S,
        })
        self.assertRaises(ValidationException, item._apply_action, FIELDNAME, {
            "Action": "DELETE",
            "Value": VALUE_S
        })
        self.assertEqual([(FIELDNAME, VALUE_S)], item.items())

        # add to scalar non number field
        item = Item({FIELDNAME: VALUE_S})
        self.assertRaises(ValidationException, item._apply_action, FIELDNAME, {
            "Action": "ADD",
            "Value": VALUE_S
        })
        self.assertEqual([(FIELDNAME, VALUE_S)], item.items())

        # add to set of different type
        item = Item({FIELDNAME: VALUE_SS})
        self.assertRaises(ValidationException, item._apply_action, FIELDNAME, {
            "Action": "ADD",
            "Value": VALUE_NS
        })
        self.assertEqual([(FIELDNAME, VALUE_SS)], item.items())

        # add non number to non existing field
        item = Item({})
        self.assertRaises(ValidationException, item._apply_action, FIELDNAME, {
            "Action": "ADD",
            "Value": VALUE_S
        })
        self.assertEqual([], item.items())
Ejemplo n.º 6
0
    def test_action_type_mismatch(self):
        from ddbmock.database.item import Item
        from ddbmock.errors import ValidationException

        # delete from set, set of same type
        item = Item({
            FIELDNAME: VALUE_SS,
        })
        self.assertRaises(ValidationException,
                          item._apply_action,
                          FIELDNAME, {"Action": "DELETE", "Value": VALUE_S})
        self.assertEqual([(FIELDNAME, VALUE_SS)], item.items())
        self.assertRaises(ValidationException,
                          item._apply_action,
                          FIELDNAME, {"Action": "DELETE", "Value": VALUE_NS})
        self.assertEqual([(FIELDNAME, VALUE_SS)], item.items())

        # delete value from scalar field (fail)
        item = Item({
            FIELDNAME: VALUE_S,
        })
        self.assertRaises(ValidationException,
                          item._apply_action,
                          FIELDNAME, {"Action": "DELETE", "Value": VALUE_S})
        self.assertEqual([(FIELDNAME, VALUE_S)], item.items())

        # add to scalar non number field
        item = Item({FIELDNAME: VALUE_S})
        self.assertRaises(ValidationException,
                          item._apply_action,
                          FIELDNAME, {"Action": "ADD", "Value": VALUE_S})
        self.assertEqual([(FIELDNAME, VALUE_S)], item.items())

        # add to set of different type
        item = Item({FIELDNAME: VALUE_SS})
        self.assertRaises(ValidationException,
                          item._apply_action,
                          FIELDNAME, {"Action": "ADD", "Value": VALUE_NS})
        self.assertEqual([(FIELDNAME, VALUE_SS)], item.items())

        # add non number to non existing field
        item = Item({})
        self.assertRaises(ValidationException,
                          item._apply_action,
                          FIELDNAME, {"Action": "ADD", "Value": VALUE_S})
        self.assertEqual([], item.items())
Ejemplo n.º 7
0
    def test_action_put(self):
        from ddbmock.database.item import Item

        item = Item({})
        item._apply_action(FIELDNAME, {"Action": "PUT", "Value": VALUE_S})
        self.assertEqual([(FIELDNAME, VALUE_S)], item.items())
Ejemplo n.º 8
0
    def test_action_put(self):
        from ddbmock.database.item import Item

        item = Item({})
        item._apply_action(FIELDNAME, {"Action": "PUT", "Value": VALUE_S})
        self.assertEqual([(FIELDNAME, VALUE_S)], item.items())