예제 #1
0
 def test_validate_dict(self):
     # 0. original
     d = self.d()
     validate_dict(d, self.s())
     d['name'] = 123
     with assert_raises(TypeError):
         validate_dict(d, self.s())
예제 #2
0
 def test_validate_dict(self):
     # 0. original
     d = self.d()
     validate_dict(d, self.s())
     d['name'] = 123
     with assert_raises(TypeError):
         validate_dict(d, self.s())
예제 #3
0
    def test_build_dict(self):
        d1 = build_dict(self.s(), ('nature.luck', 1))
        print d1
        validate_dict(d1, self.s())

        d2 = build_dict(self.s(), ('nature.luck', 2))
        print d2
        assert d1['nature']['luck'] != d2['nature']['luck']
예제 #4
0
    def test_build_dict(self):
        d1 = build_dict(self.s(), ('nature.luck', 1))
        print d1
        validate_dict(d1, self.s())

        d2 = build_dict(self.s(), ('nature.luck', 2))
        print d2
        assert d1['nature']['luck'] != d2['nature']['luck']
예제 #5
0
    def test_validate_dict_nr_ns(self):
        # 1 not required and not strict
        #   - not exist
        #   - exist and value is instance of type
        #   - exist and value is None

        d = self.d(disks=None)
        del d['name']
        validate_dict(d, self.s())
예제 #6
0
    def test_validate_dict_nr_ns(self):
        # 1 not required and not strict
        #   - not exist
        #   - exist and value is instance of type
        #   - exist and value is None

        d = self.d(disks=None)
        del d['name']
        validate_dict(d, self.s())
예제 #7
0
    def test_validate_dict_nr_s(self):
        # 3. not required and strict
        #    - not exist
        #    - exist and value is instance of type
        d = self.d()
        del d['name']
        validate_dict(d, self.s(), strict_fields=['name'])

        d = self.d(name=None)
        with assert_raises(TypeError):
            validate_dict(d, self.s(), strict_fields=['name'])
예제 #8
0
    def test_validate_dict_nr_s(self):
        # 3. not required and strict
        #    - not exist
        #    - exist and value is instance of type
        d = self.d()
        del d['name']
        validate_dict(d, self.s(), strict_fields=['name'])

        d = self.d(name=None)
        with assert_raises(TypeError):
            validate_dict(d, self.s(), strict_fields=['name'])
예제 #9
0
    def test_validate_dict_r_s(self):
        # 4. required and strict
        #    - exist and value is instance of type
        d = self.d()
        del d['name']
        with assert_raises(KeyError):
            validate_dict(d,
                          self.s(),
                          required_fields=['name'],
                          strict_fields=['name'])

        d = self.d()
        validate_dict(d,
                      self.s(),
                      required_fields=['nature.luck'],
                      strict_fields=['nature.luck'])

        d['nature']['luck'] = None
        with assert_raises(TypeError):
            validate_dict(d,
                          self.s(),
                          required_fields=['nature.luck'],
                          strict_fields=['nature.luck'])

        del d['nature']['luck']
        with assert_raises(KeyError):
            validate_dict(d,
                          self.s(),
                          required_fields=['nature.luck'],
                          strict_fields=['nature.luck'])
예제 #10
0
    def test_hash_dict(self):
        d1 = self.d()
        d2 = self.d()
        assert d1 is not d2
        assert hash_dict(d1) == hash_dict(d2)

        # change d2
        d2['id'] = ObjectId()
        assert hash_dict(d1) != hash_dict(d2)

        # acturally a test for validate_dict,
        # to test whether dict is changed or not after validate process
        d3 = self.d()
        hash_before = hash_dict(d3)
        validate_dict(d3, self.s())
        assert hash_dict(d3) == hash_before
예제 #11
0
    def test_hash_dict(self):
        d1 = self.d()
        d2 = self.d()
        assert d1 is not d2
        assert hash_dict(d1) == hash_dict(d2)

        # change d2
        d2['id'] = ObjectId()
        assert hash_dict(d1) != hash_dict(d2)

        # acturally a test for validate_dict,
        # to test whether dict is changed or not after validate process
        d3 = self.d()
        hash_before = hash_dict(d3)
        validate_dict(d3, self.s())
        assert hash_dict(d3) == hash_before
예제 #12
0
    def test_validate_dict_r_ns(self):
        # 2 required and not strict
        #   - exist and value is instance of type
        #   - exist and value is None

        d = self.d()
        del d['name']
        with assert_raises(KeyError):
            validate_dict(d, self.s(), required_fields=['name'])

        d = self.d(nature=None)
        validate_dict(d, self.s(), required_fields=['nature'])
        with assert_raises(TypeError):
            validate_dict(d, self.s(), required_fields=['nature.luck'])
        d['nature'] = {}
        with assert_raises(KeyError):
            validate_dict(d, self.s(), required_fields=['nature.luck'])
예제 #13
0
    def test_validate_dict_r_ns(self):
        # 2 required and not strict
        #   - exist and value is instance of type
        #   - exist and value is None

        d = self.d()
        del d['name']
        with assert_raises(KeyError):
            validate_dict(d, self.s(), required_fields=['name'])

        d = self.d(nature=None)
        validate_dict(d, self.s(), required_fields=['nature'])
        with assert_raises(TypeError):
            validate_dict(d, self.s(), required_fields=['nature.luck'])
        d['nature'] = {}
        with assert_raises(KeyError):
            validate_dict(d, self.s(), required_fields=['nature.luck'])
예제 #14
0
    def test_validate_dict_r_s(self):
        # 4. required and strict
        #    - exist and value is instance of type
        d = self.d()
        del d['name']
        with assert_raises(KeyError):
            validate_dict(d, self.s(), required_fields=['name'], strict_fields=['name'])

        d = self.d()
        validate_dict(d, self.s(), required_fields=['nature.luck'], strict_fields=['nature.luck'])

        d['nature']['luck'] = None
        with assert_raises(TypeError):
            validate_dict(d, self.s(), required_fields=['nature.luck'], strict_fields=['nature.luck'])

        del d['nature']['luck']
        with assert_raises(KeyError):
            validate_dict(d, self.s(), required_fields=['nature.luck'], strict_fields=['nature.luck'])
예제 #15
0
 def test_validate_dict_nis(self):
     # 5. not in struct
     d = self.d(foo='bar')
     validate_dict(d, self.s())
예제 #16
0
 def test_validate_dict_nis(self):
     # 5. not in struct
     d = self.d(foo='bar')
     validate_dict(d, self.s())