diff --git a/tests/frontend_tests.py b/tests/frontend_tests.py index 53e536d..f05e8b6 100644 --- a/tests/frontend_tests.py +++ b/tests/frontend_tests.py @@ -4,8 +4,11 @@ import urllib.request from flask import url_for from flask_testing import LiveServerTestCase from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.support.select import Select from app import create_app +from app.models import Agent, Charge from pdc_config import TestConfig from tests.common_db_feed import resources_to_instancedb @@ -115,3 +118,56 @@ class AccessTestCase(BaseFrontTestCase): self.assertEqual(self.driver.current_url, f'http://localhost:8943/project/{project_id}') td_elmts = self.driver.find_elements_by_xpath("//table[@id='charge_table']/tbody/tr/td") self.assertEqual(1085, len(td_elmts)) + + +class FormsTestCase(BaseFrontTestCase): + + # Test agemt form + def test_agent_edit(self): + # load the form + target_url = self.get_server_url() + url_for('main.agent_edit') + self.driver.get(target_url) + # fill it in + firstname_input = self.driver.find_elements_by_xpath("//input[@id='firstname']")[0] + firstname_input.send_keys("Hitier") + secondname_input = self.driver.find_elements_by_xpath("//input[@id='secondname']")[0] + secondname_input.send_keys("Richard") + # submit + submit_button = self.driver.find_elements_by_xpath("//input[@type='submit']")[0] + submit_button.send_keys(Keys.ENTER) + # check on database + latest_agent = Agent.query.order_by(Agent.id.desc()).all()[0] + self.assertEqual('Hitier', latest_agent.firstname) + + # Test agemt form + def test_charge_add(self): + # load the form + target_url = self.get_server_url() + url_for('main.charge_add') + self.driver.get(target_url) + # fill it in + agent_select = Select(self.driver.find_elements_by_xpath("//select[@id='agent_id']")[0]) + agent_select.select_by_index(1) + project_select = Select(self.driver.find_elements_by_xpath("//select[@id='project_id']")[0]) + project_select.select_by_index(1) + service_select = Select(self.driver.find_elements_by_xpath("//select[@id='service_id']")[0]) + service_select.select_by_index(1) + period_select = Select(self.driver.find_elements_by_xpath("//select[@id='period_id']")[0]) + period_select.select_by_index(1) + capacity_select = Select(self.driver.find_elements_by_xpath("//select[@id='capacity_id']")[0]) + capacity_select.select_by_index(1) + charge_input = self.driver.find_elements_by_xpath("//input[@id='charge_rate']")[0] + charge_input.send_keys("99") + + # submit + submit_button = self.driver.find_elements_by_xpath("//input[@type='submit']")[0] + submit_button.send_keys(Keys.ENTER) + # check on database + latest_charge = Charge.query.order_by(Charge.id.desc()).all()[0] + self.assertEqual([514, 41, 17, 1, 1, 99], + [latest_charge.agent_id, + latest_charge.project_id, + latest_charge.service_id, + latest_charge.capacity_id, + latest_charge.period_id, + latest_charge.charge_rate] + ) -- libgit2 0.21.2