示例#1
0
    def test_dirty(self):
        data = {
            'id': 'some_uuid',
            'spam': 'eggs',
            'extra_data': {
                'test_foo': 5
            },
            'test_data': {
                'bar': {
                    'baz': 'baf'
                }
            }
        }
        self.assertEqual(Model(data, 'test').dirty, {})

        model = Model(data, 'test')
        model.spam = 'nee'
        self.assertEqual(model.dirty, {'spam': 'nee'})

        model = Model(data, 'test')
        model.foo = 6
        self.assertEqual(model.dirty, {
            'extra_data': {},
            'test_data': {
                'foo': 6,
                'bar': {
                    'baz': 'baf'
                }
            }
        })

        model = Model(data, 'test')
        model.bar = {'fizz': 'buzz'}
        self.assertEqual(model.dirty, {'test_data': {'bar': {'fizz': 'buzz'}}})

        model = Model(data, 'test')
        model.bar['baz'] = 'zab'
        self.assertEqual(model.dirty, {'test_data': {'bar': {'baz': 'zab'}}})

        model = Model(data, 'test')
        model.foo = 6
        model.bar = 'baz'
        model.spam = 'nee'
        model.fizz = 'buzz'
        self.assertEqual(
            model.dirty, {
                'spam': 'nee',
                'test_data': {
                    'foo': 6,
                    'bar': 'baz',
                    'fizz': 'buzz'
                },
                'extra_data': {}
            })

        model = Model({}, 'test')
        model.foo = 'bar'
        self.assertEqual(model.dirty, {'extra_data': {'test_foo': 'bar'}})
示例#2
0
 def test_both_data(self):
     data = {
         'id': 'some_uuid',
         'extra_data': {
             'test_foo': 5
         },
         'test_data': {
             'bar': {
                 'baz': 'baf'
             }
         }
     }
     self.assert_model(data)
     model = Model(data, 'test')
     model.fizz = 'buzz'
     model['buzz'] = 'fizz'
     self.assertEqual('fizz', model._data['test_data']['buzz'])
     self.assertEqual('buzz', model._data['test_data']['fizz'])
     model.foo = 6
     model.bar = {'baf': 'baz'}
     self.assertEqual({}, model._data['extra_data'])
     self.assertEqual(6, model.foo)
     self.assertEqual({'baf': 'baz'}, model['bar'])
     self.assertEqual(6, model._data['test_data']['foo'])
     self.assertEqual({'baf': 'baz'}, model._data['test_data']['bar'])
示例#3
0
 def test_dirty(self):
     data = {
         'id': 'some_uuid',
         'spam': 'eggs',
         'extra_data': {
             'test_foo': 5
         },
         'test_data': {
             'bar': {'baz': 'baf'}
         }
     }
     self.assertEqual(Model(data, 'test').dirty, {})
     
     model = Model(data, 'test')
     model.spam = 'nee'
     self.assertEqual(model.dirty, {'spam': 'nee'})
     
     model = Model(data, 'test')
     model.foo = 6
     self.assertEqual(model.dirty, {'extra_data': {}, 'test_data': {'foo': 6, 'bar': {'baz': 'baf'}}})
     
     model = Model(data, 'test')
     model.bar = {'fizz': 'buzz'}
     self.assertEqual(model.dirty, {'test_data': {'bar': {'fizz': 'buzz'}}})
     
     model = Model(data, 'test')
     model.bar['baz'] = 'zab'
     self.assertEqual(model.dirty, {'test_data': {'bar': {'baz': 'zab'}}})
     
     model = Model(data, 'test')
     model.foo = 6
     model.bar = 'baz'
     model.spam = 'nee'
     model.fizz = 'buzz'
     self.assertEqual(model.dirty, {
         'spam': 'nee',
         'test_data': {
             'foo': 6,
             'bar': 'baz',
             'fizz': 'buzz'
         },
         'extra_data': {}
     })
     
     model = Model({}, 'test')
     model.foo = 'bar'
     self.assertEqual(model.dirty, {'extra_data': {'test_foo': 'bar'}})
示例#4
0
 def test_both_data(self):
     data = {
         'id': 'some_uuid',
         'extra_data': {
             'test_foo': 5
         },
         'test_data': {
             'bar': {'baz': 'baf'}
         }
     }
     self.assert_model(data)
     model = Model(data, 'test')
     model.fizz = 'buzz'
     model['buzz'] = 'fizz'
     self.assertEqual('fizz', model._data['test_data']['buzz'])
     self.assertEqual('buzz', model._data['test_data']['fizz'])
     model.foo = 6
     model.bar = {'baf': 'baz'}
     self.assertEqual({}, model._data['extra_data'])
     self.assertEqual(6, model.foo)
     self.assertEqual({'baf': 'baz'}, model['bar'])
     self.assertEqual(6, model._data['test_data']['foo'])
     self.assertEqual({'baf': 'baz'}, model._data['test_data']['bar'])