def setUp(cls): service_log.preparing_env(cls) # Делаем выборку пользователя в статусе ENABLE и подменяем пароль на другой, с которым будем работать. cls.user = dict(random.choice(databases.db1.accounting.get_users_by_status())) service_log.user(cls.user) cls.old_pass_user = cls.get_default_password(2) cls.new_pass_user = cls.get_default_password(1) hash_res_rep = generate_sha256(cls.old_pass_user) # Ставим пароль по умолчанию №2, т.к. первый может встречаться в "тестовых пользователях". AccountingCheckMethods.save_user_password(user_id=cls.user["id"], hash_passwd=cls.user["password"]) databases.db1.accounting.update_user_password(cls.user["id"], hash_res_rep)
def test_checkUserPassword_for_exist_user(self): """ Тестирование метода checkUserPassword. Выбираем произвольного пользователя со статусом акаунта "ENABLE". Подменяем хеш его пароля в БД на заданный. Делаем запрос на проверку пароля и проверяем, что запрос отработал корректно. По завершении теста (не зависимо от результата) возвращаем хеш пользователя на первоночальный. """ service_log.run(self) hash_res_new = generate_sha256(self.get_default_password()) AccountingCheckMethods.save_user_password(user_id=self.user["id"], hash_passwd=self.user["password"]) databases.db1.accounting.update_user_password(self.user["id"], hash_res_new) result = services.accounting.root.tframed.checkUserPassword(self.user["phone"], self.get_default_password()) service_log.put("Method checkUserPassword returned result: %s" % result) self.assertTrue(result, "Password for user - is not correct.")
def test_authenticate_for_exist_user(self): """ Тестирование метода аутентификации authenticate. Выбираем произвольного пользователя со статусом акаунта "ENABLE". Подменяем хеш его пароля в БД на заданный. Делаем запрос на аутентификацию и проверяем, что запрос отработал корректно. По завершении теста (не зависимо от результата) возвращаем хеш пользователя на первоночальный. """ service_log.run(self) hash_res_new = generate_sha256(self.get_default_password()) AccountingCheckMethods.save_user_password(user_id=self.user["id"], hash_passwd=self.user["password"]) databases.db1.accounting.update_user_password(self.user["id"], hash_res_new) result = services.accounting.root.tframed.authenticate(self.user["phone"], self.get_default_password(), self.generate_session_id()) service_log.put("Method authenticate returned result: %s" % result) self.check_user(result, self.user)
def setUpClass(cls): """ Создаём тестовые данные. Создаём пользователей с заданными статусами. """ statuses = AccountingCheckMethods.USER_STATUS cls.STATUSES_USER_IDS = {index: AccountingCheckMethods.create_user_with_status(index) for index in statuses} cls.msg_error_0 = "Changed the behavior of the method." cls.msg_error_1 = "The status must not be the same." cls.msg_error_2 = "The status must be same."
def tearDown(cls): services.accounting.root.close() AccountingCheckMethods.recover_user_password() service_log.end()