def setUpClass(cls): super().setUpClass() with transaction.atomic(): user = User.objects.create_user( username=USERNAME, password=PASSWORD ) user_detail = UserDetail() user_detail.auth_user = user user_detail.save() cls.api_client = ApiClient()
def add_wantoo_bot(apps, schema_editor): User = apps.get_model(settings.AUTH_USER_MODEL) UserDetail = apps.get_model('users', 'UserDetail') print 'Creating Wantoo Bot User...' try: wantoo_bot = User.objects.get(email='*****@*****.**') print 'Wantoobot already exists...' except: #Doesn't work all the time... # wantoo_bot = User.objects.create_user(username='******', # email='*****@*****.**', # password='******', # first_name="~ WANTOOBOT", # last_name="~", # is_staff=True, # is_superuser=True) # User = apps.get_registered_model('auth', 'User') wantoo_bot = User( username='******', email='*****@*****.**', password=make_password('2i8oaKhwbeTc'), is_superuser=True, is_staff=True, first_name="~ WANTOOBOT", last_name="~", ) wantoo_bot.save() print 'Wantoobot Created!' print 'Done!' print 'Adding UserDetail to Wantoo Bot...' try: user_detail = UserDetail() user_detail.user = wantoo_bot user_detail.casl = True user_detail.save() print 'UserDetail created!' except: print 'UserDetail already exists...' print 'Done!'