Beispiel #1
0
 def test_update_from_obj(self):
     data = BareObj()
     data.OMEGA_MONGO_URL = 'updated-foo'
     update_from_obj(data, self.defaults)
     self.assertIn('OMEGA_MONGO_URL', self.defaults)
     self.assertEqual(self.defaults['OMEGA_MONGO_URL'], 'updated-foo')
     self.assertNotIn('NOTOMEGA_VALUE', self.defaults)
Beispiel #2
0
 def test_update_obj_from_obj_nested(self):
     data = BareObj()
     data.OMEGA_CELERY_CONFIG = {
         'TASK_SERIALIZER': 'json',
     }
     defaults = BareObj()
     defaults.OMEGA_CELERY_CONFIG = {
         'RESULT_SERIALIZER': 'pickle',
         'TASK_SERIALIZER': 'pickle',
     }
     update_from_obj(data, defaults)
     self.assertEqual(defaults.OMEGA_CELERY_CONFIG['RESULT_SERIALIZER'],
                      'pickle')
     self.assertEqual(defaults.OMEGA_CELERY_CONFIG['TASK_SERIALIZER'],
                      'json')
Beispiel #3
0
 def test_update_obj_dict(self):
     # source and target are dicts, scalar values
     source = {'FOO': 'bar'}
     target = {'FOO': 'baz'}
     update_from_obj(source, target)
     self.assertEqual(target['FOO'], 'bar')
     # source is dict, target is dict, dict values replace
     source = {'FOO': dict(sub='bar')}
     target = {'FOO': dict(sub='baz')}
     update_from_obj(source, target)
     self.assertEqual(target['FOO'], dict(sub='bar'))
     # source is dict, target is dict, dict values merge
     source = {'FOO': dict(othersub='bar')}
     target = {'FOO': dict(sub='baz')}
     update_from_obj(source, target)
     self.assertEqual(target['FOO'], dict(sub='baz', othersub='bar'))
     # source is dict, target is dict, dict values delete
     source = {'FOO': dict(othersub='bar', sub='__delete__')}
     target = {'FOO': dict(sub='baz')}
     update_from_obj(source, target)
     self.assertEqual(target['FOO'], dict(othersub='bar'))
Beispiel #4
0
 def test_update_obj_attrs(self):
     # source is dict, target is attributes, scalar values
     source = {'FOO': 'bar'}
     target = MiscTests
     target.FOO = 'baz'
     update_from_obj(source, target)
     self.assertEqual(target.FOO, 'bar')
     # source is dict, target is obj, merge
     source = {'FOO': dict(othersub='bar')}
     target.FOO = dict(sub='baz')
     update_from_obj(source, target)
     self.assertEqual(target.FOO, dict(sub='baz', othersub='bar'))
     # source is dict, target is obj, merge delete
     source = {'FOO': dict(othersub='bar', sub='__delete__')}
     target.FOO = dict(sub='baz')
     update_from_obj(source, target)
     self.assertEqual(target.FOO, dict(othersub='bar'))