Source code for django_webapps_fullstack.test.test_account_register
"""Test program for the django template "register"based on the "unittest" and "selenium" functionality"""importunittestfromselenium.webdriver.common.byimportByfromselenium.webdriver.support.waitimportWebDriverWaitfromselenium.webdriver.supportimportexpected_conditionsasEC# Import base test case for automatic cleanupfromdjango_webapps_fullstack.test.base_test_caseimportDjangoSeleniumTestCase
[docs]classtest_account_register(DjangoSeleniumTestCase):""" Class for the test cases of the django template "register" """
[docs]deftest_cases(self):""" test cases for the template "register" """# Get test parameters from configurationcustom_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 itassert'Register'inself.driver.title# search and enter email and submit buttonname=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 existwait=WebDriverWait(self.driver,10)button=wait.until(EC.presence_of_element_located((By.CLASS_NAME,'btn-primary')))# Scroll into viewself.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 issuesself.driver.execute_script("arguments[0].click();",button)# wait for the change to the expected title of the new templatewait=WebDriverWait(self.driver,20)wait.until(EC.title_contains("Register Done"))# assertion to test that template "Overview" is called after submitassert"Register Done"inself.driver.title# Find the created user and register for automatic cleanupres_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)ifres_users_id:user_id=res_users_id[0]['id']partner_id=res_users_id[0]['partner_id'][0]ifres_users_id[0].get('partner_id')elseNoneifpartner_id:self.addCleanup_partner(partner_id)ifuser_id:self.addCleanup_user(user_id)