def get_and_login_user(self, user=None, in_group=None, is_superuser=False, in_national_admin_group=False): """ this function is a handy way to log in a user to the testing client. :param user: optional user to be logged in :param in_group: optional group to have the user assigned to :param is_superuser: is the user a superuser? :param in_national_admin_group: supplying True will put the user as either a travel, csas or project admin; with access to shared models org structure """ if not user: user = UserFactory() login_successful = self.client.login( username=user.username, password=UserFactory.get_test_password()) self.assertEqual(login_successful, True) if in_group: group = GroupFactory(name=in_group) user.groups.add(group) if is_superuser: user.is_superuser = True user.save() if in_national_admin_group: case = faker.pyint(1, 3) if case == 1: # travel TravelUser.objects.create(user=user, is_national_admin=True) elif case == 2: # csas CSASAdminUser.objects.create(user=user, is_national_admin=True) elif case == 3: # csas PPTAdminUser.objects.create(user=user, is_national_admin=True)
def get_and_login_user(self, user=None, in_group=None, is_superuser=False): """ this function is a handy way to log in a user to the testing client. :param user: optional user to be logged in :param in_group: optional group to have the user assigned to :is_superuser: is the user a superuser? """ if not user: user = UserFactory() login_successful = self.client.login(username=user.username, password=UserFactory.get_test_password()) self.assertEqual(login_successful, True) if in_group: group = GroupFactory(name=in_group) user.groups.add(group) if is_superuser: user.is_superuser = True user.save() return user