Skip to content

Instantly share code, notes, and snippets.

/tests.py Secret

Created August 29, 2014 15:36
Show Gist options
  • Save anonymous/a11898d0cd8ffc78b531 to your computer and use it in GitHub Desktop.
Save anonymous/a11898d0cd8ffc78b531 to your computer and use it in GitHub Desktop.
def setUp(self):
_exists = False
for _model in apps.get_models():
if getattr(_model, '_test_eggs', False):
_exists = True
self.Eggs = _model
if getattr(_model, '_test_spam', False):
_exists = True
self.Spam = _model
# Check whether the models exist, and short circuit, if so
if _exists:
return
class Eggs(AccountModel):
_test_eggs = True # To denote that this is a test model
pass
class Spam(AccountModel):
_test_spam = True # To denote that this is a test model
eggs = models.ForeignKey(Eggs)
ham = models.CharField(max_length=255)
chicken = models.CharField(max_length=255)
steak = models.CharField(_(u'verbose steak'), max_length=255)
self.Eggs = Eggs
self.Spam = Spam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment