def details(var): """ Prints a dictionary showing the attributes of a variable, and if possible, their corresponding values. """ var_details = get_details(var) _display_details(var_details) return var_details
def test_set_value_managers(self): user = self.get_context()['user'] user_details = get_details(user) managers = [] for key in user_details.keys(): value = getattr(self.user, key, None) kls = getattr(getattr(value, '__class__', ''), '__name__', '') if kls in ('ManyRelatedManager', 'RelatedManager'): managers.append(key) for key, value in user_details.items(): if key in managers: self.assertTrue(value in ('ManyRelatedManager', 'RelatedManager') )
def test_invalid_managers_hidden(self): """ Assure managers that aren't accessible from model instances are hidden """ user = self.get_context()['user'] user_details = get_details(user) invalid_managers = [] for attr in dir(user): try: getattr(user, attr) except: invalid_managers.append(attr) self.assertTrue(all([not manager in user_details.keys() for manager in invalid_managers]))
def test_get_details_c_extensions(self): """ Ensures get_details works on objects with callables that are implemented in C extensions. inspect.getargspec fails with a TypeError for such callables, and get_details needs to handle this gracefully N.B. Only Python >=2.7 has bit_length C routine on Booleans so the test has to be skipped for Python2.6 """ if hasattr(True, 'bit_length'): try: details = get_details(True) except TypeError: self.fail('Fails to handle C routines for call to inspect.argspec') self.assertEqual(details['bit_length'], 'routine') user_details = get_details(self.get_context()['user']) self.assertTrue(any(( user_details['META_module_name'], 'django.contrib.auth.models', user_details['META_module_name'], 'django.utils.functional' ))) self.assertTrue(any(( user_details['META_class_name'] == 'User', user_details['META_class_name'] == 'AnonymousUser' )))
def test_get_details_c_extensions(self): """ Ensures get_details works on objects with callables that are implemented in C extensions. inspect.getargspec fails with a TypeError for such callables, and get_details needs to handle this gracefully N.B. Only Python >=2.7 has bit_length C routine on Booleans so the test has to be skipped for Python2.6 """ if hasattr(True, 'bit_length'): try: details = get_details(True) except TypeError: self.fail( 'Fails to handle C routines for call to inspect.argspec') self.assertEqual(details['bit_length'], 'routine') user_details = get_details(self.get_context()['user']) self.assertTrue( any((user_details['META_module_name'], 'django.contrib.auth.models', user_details['META_module_name'], 'django.utils.functional'))) self.assertTrue( any((user_details['META_class_name'] == 'User', user_details['META_class_name'] == 'AnonymousUser')))
def test_set_value_managers(self): user = self.get_context()['user'] user_details = get_details(user) managers = [] for key in user_details.keys(): value = getattr(self.user, key, None) kls = getattr(getattr(value, '__class__', ''), '__name__', '') if kls in ('ManyRelatedManager', 'RelatedManager', 'EmptyManager'): managers.append(key) for key, value in user_details.items(): if key in managers: self.assertTrue(value in ( 'ManyRelatedManager', 'RelatedManager', 'EmptyManager', ))
def test_invalid_managers_hidden(self): """ Assure managers that aren't accessible from model instances are hidden """ user = self.get_context()['user'] user_details = get_details(user) invalid_managers = [] for attr in dir(user): try: getattr(user, attr) except: invalid_managers.append(attr) self.assertTrue( all([ not manager in user_details.keys() for manager in invalid_managers ]))
def test_module_and_class_added(self): user_details = get_details(self.get_context()['user']) self.assertEqual(user_details['META_module_name'], 'django.utils.functional') self.assertEqual(user_details['META_class_name'], 'User')
def test_set_value_method(self): """Assure methods have their value set to 'method'""" user_details = get_details(self.get_context()['user']) for key, value in list(user_details.items()): if callable(getattr(self.user, key, None)): self.assertEqual(value, 'routine')
def test_set_value_method(self): """Assure methods have their value set to 'method'""" user_details = get_details(self.get_context()['user']) self.assertEqual(user_details['get_full_name'], 'routine')