Source code for django_webapps_fullstack.test.test_account_register

"""
Test program for the django template "register"
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 DjangoSeleniumTestCase



[docs] class test_account_register(DjangoSeleniumTestCase): """ Class for the test cases of the django template "register" """
[docs] def test_cases(self): """ test cases for the template "register" """ # Get test parameters from configuration custom_url = self.config_global.get('settings_django_server', 'url') custom_new_name = self.config_test.get('get_settings_customer', 'new_name') custom_new_login = self.config_test.get('get_settings_customer', 'new_login') custom_new_email = self.config_test.get('get_settings_customer', 'new_email') custom_password = self.config_test.get('get_settings_customer', 'password') # url of template "password_register = '/account/register' self.driver.get(custom_url + '/account/register') # assertion to confirm that the title has the keyword in it assert 'Register' in self.driver.title # search and enter email and submit button name = self.driver.find_element(By.ID, 'id_name') login = self.driver.find_element(By.ID, 'id_login') email = self.driver.find_element(By.ID, 'id_email') 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') name.send_keys(custom_new_name) login.send_keys(custom_new_login) email.send_keys(custom_new_email) password.send_keys(custom_password) password_confirm.send_keys(custom_password) # Wait for the button to exist wait = WebDriverWait(self.driver, 10) button = wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'btn-primary'))) # Scroll into view self.driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", button) # Optional short wait (if layout takes a moment) self.driver.implicitly_wait(1) # Click via JavaScript to avoid obstruction issues self.driver.execute_script("arguments[0].click();", button) # wait for the change to the expected title of the new template wait = WebDriverWait(self.driver, 20) wait.until(EC.title_contains("Register Done")) # assertion to test that template "Overview" is called after submit assert "Register Done" in self.driver.title # Find the created user and register for automatic cleanup res_users_id = self.models.execute_kw( self.db, self.uid, self.password, 'res.users', 'search_read', [[['login', '=', custom_new_login]]], {'fields': ['partner_id']} ) # Register for cleanup (LIFO order: partner first, deleted last) if res_users_id: user_id = res_users_id[0]['id'] partner_id = res_users_id[0]['partner_id'][0] if res_users_id[0].get('partner_id') else None if partner_id: self.addCleanup_partner(partner_id) if user_id: self.addCleanup_user(user_id)
if __name__ == "__main__": unittest.main()