Skip to content

Instantly share code, notes, and snippets.

@PirosB3
Created October 3, 2014 17:31
Show Gist options
  • Save PirosB3/72265828099136ca9057 to your computer and use it in GitHub Desktop.
Save PirosB3/72265828099136ca9057 to your computer and use it in GitHub Desktop.
def test_get_fields_only_searaches_forward_on_apps_not_ready(self):
opts = Person._meta
# If apps registry is not ready, get_field() searches
# over only forward fields.
opts.apps.ready = False
# 'data_abstract' is a forward field, and therefore will be found
self.assertTrue(opts.get_field('data_abstract'))
message = "Person has no field named 'relating_baseperson'. The app cache " \
"isn't ready yet, so if this is a forward field, it won't be " \
"available yet."
with self.assertRaises(FieldDoesNotExist) as err:
opts.get_field('relating_baseperson')
self.assertEqual(str(err.exception), message)
opts.apps.ready = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment