def test_standard_user_context_manager(self): with StandardUserContext() as user_context: query = User.select().where(User.name == user_context.username) self.assertEqual(len(query), 1) user = query[0] self.assertIsInstance(user_context.user, User) self.assertEqual(user.name, user_context.user.name)
def test_creating_new_user(self): facade: Rewardify = Rewardify.instance() # Creating the user username = '******' password = '******' facade.create_user(username, password) # Querying for the user to check if it exists query = User.select().where(User.name == username) self.assertTrue(len(query) >= 1) user = query[0] self.assertTrue(user.password.check(password))
def get_user(self, username: str) -> User: """ Returns the User object for the user with the given username CHANGELOG Added 10.06.2019 :param username: :return: """ query = User.select(User).where(User.name == username) user = query[0] return user
def exists_user(self, username: str): """ Returns the boolean value of whether or not a user with the given username exists CHANGELOG Added 15.06.2019 :param username: :return: """ query = User.select().where(User.name == username) # Of course, when there is a result to the above query, a User object has been found and thus, the user exists return len(query) != 0
def test_user_join_reward_and_pack_columns(self): # Setting all up self.setup_sample_user() self.setup_sample_pack() self.setup_sample_reward() # Attempting to get a user object with all the correct back refs to the pack and reward objects users = User.select(User).where(User.name == self.SAMPLE_USER_NAME) user = users[0] self.assertEqual(len(user.rewards), 1) self.assertEqual(user.rewards[0].name, self.SAMPLE_REWARD_NAME) self.assertEqual(len(user.packs), 1) self.assertEqual(user.packs[0].name, self.SAMPLE_PACK_NAME)
def test_user_use_reward_with_effect(self): self.setup_sample() self.create_sample_user() facade: Rewardify = Rewardify.instance() facade.user_add_dust(self.SAMPLE_USER_PARAMETERS['name'], 100) facade.user_buy_reward(self.SAMPLE_USER_PARAMETERS['name'], 'Gold Reward') user = self.get_sample_user() self.assertEqual(len(user.rewards), 1) self.assertEqual(user.gold, 0) facade.user_use_reward(self.SAMPLE_USER_PARAMETERS['name'], 'Gold Reward') user = User.select().where( User.name == self.SAMPLE_USER_PARAMETERS['name'])[0] self.assertEqual(len(user.rewards), 0) print(user.gold) self.assertEqual(user.gold, 100)
def test_database_modifications_do_not_transcend_individual_tests(self): users = User.select().where(User.name == self.SAMPLE_USER_NAME) # If other test cases indeed do not influence the self.assertEqual(len(users), 0)