def test_not_equal(self): from yepes.contrib.registry.models import Entry obj = Entry.objects.get(key='KEY') lazy_obj = LazyModelObject(Entry, key='KEY') self.assertFalse(lazy_obj != obj) self.assertFalse(lazy_obj != obj) self.assertFalse(obj != lazy_obj)
def test_hash(self): from yepes.contrib.registry.models import Entry obj = Entry.objects.get(key='KEY') lazy_obj = LazyModelObject(Entry, key='KEY') self.assertEqual(hash(lazy_obj), hash(obj)) self.assertEqual(hash(obj), hash(lazy_obj)) self.assertIn(lazy_obj, {obj}) self.assertIn(obj, {lazy_obj})
def test_attributes(self): from yepes.contrib.registry.models import Entry obj = Entry.objects.get(key='KEY') lazy_obj = LazyModelObject(Entry, key='KEY') self.assertEqual(lazy_obj.pk, obj.pk) self.assertEqual(lazy_obj.site, obj.site) self.assertEqual(lazy_obj.key, obj.key) self.assertEqual(lazy_obj.value, obj.value)
def test_class(self): from yepes.contrib.registry.models import Entry obj = Entry.objects.get(key='KEY') lazy_obj = LazyModelObject(Entry, key='KEY') self.assertEqual(lazy_obj.__class__, obj.__class__) self.assertEqual(lazy_obj.__class__, Entry) self.assertIsInstance(lazy_obj, obj.__class__) self.assertIsInstance(lazy_obj, Entry)
def test_lazy_loading(self): from yepes.contrib.registry.models import Entry lazy_obj = LazyModelObject(Entry, key='asdfg') with self.assertRaises(Entry.DoesNotExist): lazy_obj.key lazy_obj = LazyModelObject('registry.Entry', key='asdfg') with self.assertRaises(Entry.DoesNotExist): lazy_obj.key = 'hjklñ' lazy_obj = LazyModelObject('registry.Entry', 'all_objects', key='asdfg') with self.assertRaises(Entry.DoesNotExist): del lazy_obj.key
def test_representation(self): from yepes.contrib.registry.models import Entry obj = Entry.objects.get(key='KEY') lazy_obj = LazyModelObject(Entry, key='KEY') self.assertNotEqual(repr(lazy_obj), repr(obj)) self.assertEqual(repr(lazy_obj), '<LazyModelObject: {0}>'.format(obj))
def test_string(self): from yepes.contrib.registry.models import Entry obj = Entry.objects.get(key='KEY') lazy_obj = LazyModelObject(Entry, key='KEY') self.assertEqual(str(lazy_obj), str(obj)) self.assertEqual(str(obj), str(lazy_obj))