Commit 12b452665fbd6d5cfbbc014b038fd7b747b5dc18

Authored by hitier
1 parent a540c9b1

Add web tests for latest forms

Showing 1 changed file with 56 additions and 0 deletions   Show diff stats
tests/frontend_tests.py
... ... @@ -4,8 +4,11 @@ import urllib.request
4 4 from flask import url_for
5 5 from flask_testing import LiveServerTestCase
6 6 from selenium import webdriver
  7 +from selenium.webdriver.common.keys import Keys
  8 +from selenium.webdriver.support.select import Select
7 9  
8 10 from app import create_app
  11 +from app.models import Agent, Charge
9 12 from pdc_config import TestConfig
10 13 from tests.common_db_feed import resources_to_instancedb
11 14  
... ... @@ -115,3 +118,56 @@ class AccessTestCase(BaseFrontTestCase):
115 118 self.assertEqual(self.driver.current_url, f'http://localhost:8943/project/{project_id}')
116 119 td_elmts = self.driver.find_elements_by_xpath("//table[@id='charge_table']/tbody/tr/td")
117 120 self.assertEqual(1085, len(td_elmts))
  121 +
  122 +
  123 +class FormsTestCase(BaseFrontTestCase):
  124 +
  125 + # Test agemt form
  126 + def test_agent_edit(self):
  127 + # load the form
  128 + target_url = self.get_server_url() + url_for('main.agent_edit')
  129 + self.driver.get(target_url)
  130 + # fill it in
  131 + firstname_input = self.driver.find_elements_by_xpath("//input[@id='firstname']")[0]
  132 + firstname_input.send_keys("Hitier")
  133 + secondname_input = self.driver.find_elements_by_xpath("//input[@id='secondname']")[0]
  134 + secondname_input.send_keys("Richard")
  135 + # submit
  136 + submit_button = self.driver.find_elements_by_xpath("//input[@type='submit']")[0]
  137 + submit_button.send_keys(Keys.ENTER)
  138 + # check on database
  139 + latest_agent = Agent.query.order_by(Agent.id.desc()).all()[0]
  140 + self.assertEqual('Hitier', latest_agent.firstname)
  141 +
  142 + # Test agemt form
  143 + def test_charge_add(self):
  144 + # load the form
  145 + target_url = self.get_server_url() + url_for('main.charge_add')
  146 + self.driver.get(target_url)
  147 + # fill it in
  148 + agent_select = Select(self.driver.find_elements_by_xpath("//select[@id='agent_id']")[0])
  149 + agent_select.select_by_index(1)
  150 + project_select = Select(self.driver.find_elements_by_xpath("//select[@id='project_id']")[0])
  151 + project_select.select_by_index(1)
  152 + service_select = Select(self.driver.find_elements_by_xpath("//select[@id='service_id']")[0])
  153 + service_select.select_by_index(1)
  154 + period_select = Select(self.driver.find_elements_by_xpath("//select[@id='period_id']")[0])
  155 + period_select.select_by_index(1)
  156 + capacity_select = Select(self.driver.find_elements_by_xpath("//select[@id='capacity_id']")[0])
  157 + capacity_select.select_by_index(1)
  158 + charge_input = self.driver.find_elements_by_xpath("//input[@id='charge_rate']")[0]
  159 + charge_input.send_keys("99")
  160 +
  161 + # submit
  162 + submit_button = self.driver.find_elements_by_xpath("//input[@type='submit']")[0]
  163 + submit_button.send_keys(Keys.ENTER)
  164 + # check on database
  165 + latest_charge = Charge.query.order_by(Charge.id.desc()).all()[0]
  166 + self.assertEqual([514, 41, 17, 1, 1, 99],
  167 + [latest_charge.agent_id,
  168 + latest_charge.project_id,
  169 + latest_charge.service_id,
  170 + latest_charge.capacity_id,
  171 + latest_charge.period_id,
  172 + latest_charge.charge_rate]
  173 + )
... ...