def test_items(self): obj = Object() obj.attr1 = 1 x = DictAttribute(obj) x["attr2"] = 2 self.assertDictEqual(dict(x.iteritems()), dict(attr1=1, attr2=2)) self.assertDictEqual(dict(x.items()), dict(attr1=1, attr2=2))
def test_get_set(self): x = DictAttribute(Object()) x["foo"] = "The quick brown fox" self.assertEqual(x["foo"], "The quick brown fox") self.assertEqual(x["foo"], x.obj.foo) self.assertEqual(x.get("foo"), "The quick brown fox") self.assertIsNone(x.get("bar")) self.assertRaises(KeyError, x.__getitem__, "bar")
def test_get_set(self): x = DictAttribute(Object()) x['foo'] = 'The quick brown fox' self.assertEqual(x['foo'], 'The quick brown fox') self.assertEqual(x['foo'], x.obj.foo) self.assertEqual(x.get('foo'), 'The quick brown fox') self.assertIsNone(x.get('bar')) with self.assertRaises(KeyError): x['bar']
def read_configuration(self): """Load configuration from Django settings.""" from django.conf import settings self.configured = True # Default backend needs to be the database backend for backward # compatibility. backend = getattr(settings, "CELERY_RESULT_BACKEND", None) or \ getattr(settings, "CELERY_BACKEND", None) if not backend: settings.CELERY_RESULT_BACKEND = "database" return DictAttribute(settings)
def config_from_object(self, obj, silent=False): if isinstance(obj, basestring): try: obj = get_cls_by_name(obj, imp=self.import_from_cwd) except (ImportError, AttributeError): if silent: return False raise if not hasattr(obj, "__getitem__"): obj = DictAttribute(obj) self._conf = obj return True
def config_from_object(self, obj, silent=False): if isinstance(obj, string_t): try: obj = self._smart_import(obj, imp=self.import_from_cwd) except (ImportError, AttributeError): if silent: return False raise if not hasattr(obj, '__getitem__'): obj = DictAttribute(obj) self._conf = obj return True
def read_configuration(self): """Load configuration from Django settings.""" self.configured = True # Default backend needs to be the database backend for backward # compatibility. backend = getattr(settings, 'CELERY_RESULT_BACKEND', None) or \ getattr(settings, 'CELERY_BACKEND', None) if not backend: settings.CELERY_RESULT_BACKEND = 'database' if NO_TZ: if getattr(settings, 'CELERY_ENABLE_UTC', None): warnings.warn('CELERY_ENABLE_UTC requires Django 1.4+') settings.CELERY_ENABLE_UTC = False return DictAttribute(settings)
def test_get_set_keys_values_items(self): x = DictAttribute(Object()) x['foo'] = 'The quick brown fox' self.assertEqual(x['foo'], 'The quick brown fox') self.assertEqual(x['foo'], x.obj.foo) self.assertEqual(x.get('foo'), 'The quick brown fox') self.assertIsNone(x.get('bar')) with self.assertRaises(KeyError): x['bar'] x.foo = 'The quick yellow fox' self.assertEqual(x['foo'], 'The quick yellow fox') self.assertIn( ('foo', 'The quick yellow fox'), list(x.items()), ) self.assertIn('foo', list(x.keys())) self.assertIn('The quick yellow fox', list(x.values()))
def test_get_set_keys_values_items(self): x = DictAttribute(Bunch()) x["foo"] = "The quick brown fox" self.assertEqual(x["foo"], "The quick brown fox") self.assertEqual(x["foo"], x.obj.foo) self.assertEqual(x.get("foo"), "The quick brown fox") self.assertIsNone(x.get("bar")) with self.assertRaises(KeyError): x["bar"] x.foo = "The quick yellow fox" self.assertEqual(x["foo"], "The quick yellow fox") self.assertIn(("foo", "The quick yellow fox"), list(x.items())) self.assertIn("foo", list(x.keys())) self.assertIn("The quick yellow fox", list(x.values()))
def setup_settings(self, settingsdict): return DictAttribute(settingsdict)
def test_setdefault(self): x = DictAttribute(Bunch()) x.setdefault("foo", "NEW") self.assertEqual(x["foo"], "NEW") x.setdefault("foo", "XYZ") self.assertEqual(x["foo"], "NEW")
def test_setdefault(self): x = DictAttribute(Object()) self.assertEqual(x.setdefault("foo", "NEW"), "NEW") self.assertEqual(x.setdefault("foo", "XYZ"), "NEW")
def test_contains(self): x = DictAttribute(Object()) x['foo'] = 1 self.assertIn('foo', x) self.assertNotIn('bar', x)
def test_setdefault(self): x = DictAttribute(Bunch()) x.setdefault('foo', 'NEW') self.assertEqual(x['foo'], 'NEW') x.setdefault('foo', 'XYZ') self.assertEqual(x['foo'], 'NEW')
def read_configuration(self): """ Read configuration defined in invenio.celery_config """ usercfg = self._import_config_module('invenio.celery_config') self.configured = True return DictAttribute(usercfg)
def test_setdefault(self): x = DictAttribute(Object()) self.assertEqual(x.setdefault('foo', 'NEW'), 'NEW') self.assertEqual(x.setdefault('foo', 'XYZ'), 'NEW')
def read_configuration(self): from irgsh_node.conf import settings self.configured = True return DictAttribute(settings)
def test_items(self): obj = Bunch(attr1=1) x = DictAttribute(obj) x['attr2'] = 2 self.assertEqual(x['attr1'], 1) self.assertEqual(x['attr2'], 2)
def test_contains(self): x = DictAttribute(Object()) x["foo"] = 1 self.assertIn("foo", x) self.assertNotIn("bar", x)
def test_iteritems(self): obj = Object() obj.attr1 = 1 x = DictAttribute(obj) x["attr2"] = 2 self.assertDictEqual(dict(x.iteritems()), dict(attr1=1, attr2=2))