Source code for django_webapps_fullstack.test.test_account_password_renew

"""
test program for the django template "password_renew"
based on the "unittest" and "selenium" functionality
"""

import unittest
from selenium.webdriver.common.by    import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support      import expected_conditions as EC

# Import base test case for automatic cleanup
from django_webapps_fullstack.test.base_test_case import ReadOnlyDjangoTestCase

[docs] class test_account_password_renew(ReadOnlyDjangoTestCase): """ Class for the test cases of the django template "password_renew" """
[docs] def test_cases(self): """ test cases for the template "password_renew" """ # Get test parameters from configuration custom_login = self.config_test.get('get_settings_customer', 'login') custom_password = self.config_test.get('get_settings_customer', 'password') custom_title_dashboard = self.config_test.get('get_settings_title', 'title_dashboard') custom_title_login = self.config_test.get('get_settings_title', 'title_login') custom_url = self.config_global.get('settings_django_server', 'url') # find the user for whom the password should be updated res_users_id = self.models.execute_kw(self.db, self.uid, self.password, 'res.users', 'search', [[ ['login', '=', custom_login], ['x_activate_complete', '=', False], ]]) # if a user exist: # update of 'x_activate_complete' so that the password could be uptaded for x in res_users_id: id = x result = self.models.execute_kw(self.db, self.uid, self.password, 'res.users', 'write', [[id], {'x_activate_complete': True}]) # login of the user to create the request session # url of template "login" = '/account/login' self.driver.get(custom_url + '/account/login') # assertion to confirm that the title has the keyword in it assert custom_title_login in self.driver.title # search and enter email and submit button login = self.driver.find_element(By.ID, 'id_login') password = self.driver.find_element(By.ID, 'id_password') button = self.driver.find_element(By.CLASS_NAME, 'btn-primary') login.send_keys(custom_login) password.send_keys(custom_password) button.click() # wait for the change to the expected title of the new template "dashboard" wait = WebDriverWait(self.driver, 80) wait.until(EC.title_contains(custom_title_dashboard)) # assertion to test that template "dashboard" is called after submit assert custom_title_dashboard in self.driver.title # user has been logged into, "password_renew" procedure could be started # url of template "password_renew" = '/account/password_renew' self.driver.get(custom_url + '/account/password_renew') # assertion to confirm that the title has the keyword in it assert 'Password Renew' in self.driver.title # search and enter email and submit button password = self.driver.find_element(By.ID, 'id_password') password_confirm = self.driver.find_element(By.ID, 'id_password_confirm') button = self.driver.find_element(By.CLASS_NAME, 'btn-primary') password.send_keys(custom_password) password_confirm.send_keys(custom_password) button.click() wait = WebDriverWait(self.driver, 10) wait.until(EC.title_contains("Password Renew Done")) # assertion to test that template "password_recovery_done" is called after submit self.assertIn("Password Renew Done", self.driver.title)
if __name__ == "__main__": unittest.main()