def setUp(self): super().setUp() self.test_url = reverse_lazy('whalebrary:user_list') self.test_url1 = reverse_lazy('whalebrary:user_list', args=[1]) self.expected_template = 'whalebrary/user_list.html' self.user = self.get_and_login_user(in_group="whalebrary_admin") GroupFactory(name="whalebrary_admin") GroupFactory(name="whalebrary_edit")
def setUp(self): super().setUp() self.instance = FactoryFloor.UserFactory() self.test_url = reverse_lazy('vault:user_list') self.test_url1 = reverse_lazy('vault:user_list', args=[1]) self.expected_template = 'vault/user_list.html' self.user = self.get_and_login_user(in_group="vault_admin") GroupFactory(name="vault_admin") GroupFactory(name="vault_edit")
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 setUp(self): super().setUp() # used to import fixtures # need to download the webdriver and stick it in the path/point to it here: # can be downloaded from: https://chromedriver.chromium.org/downloads self.browser = webdriver.Chrome( 'bio_diversity/test/functional_test/chromedriver.exe') self.browser.maximize_window() # generate a user user_data = UserFactory.get_valid_data() self.user = User.objects.create_superuser( username=user_data['username'], email=user_data['email1'], password=UserFactory.get_test_password()) bio_group = GroupFactory(name='bio_diversity_admin') self.user.groups.add(bio_group) self.user.first_name = user_data["first_name"] self.user.last_name = user_data["last_name"] self.user.save() self.browser.get(self.live_server_url + '/en/') self.client.force_login(self.user) # Native django test client cookie = self.client.cookies['sessionid'] # grab the login cookie self.browser.add_cookie({ 'name': 'sessionid', 'value': cookie.value, 'secure': False, 'path': '/' }) self.browser.refresh( ) # selenium will set cookie domain based on current page domain
def get_and_login_user(self, user=None, in_group=None): """ 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 """ 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) return user