Commit 264e5cfb9647f3c7cefdba12659dbaf63b1d20e0

Authored by hitier
1 parent f3be946a

New agents and projects pages tests

using common resource 2 instance db path
Showing 1 changed file with 34 additions and 6 deletions   Show diff stats
tests/frontend_tests.py
1 import os 1 import os
2 import urllib.request 2 import urllib.request
3 3
  4 +from flask import url_for
4 from flask_testing import LiveServerTestCase 5 from flask_testing import LiveServerTestCase
5 from selenium import webdriver 6 from selenium import webdriver
6 7
7 from app import create_app 8 from app import create_app
8 from pdc_config import TestConfig 9 from pdc_config import TestConfig
  10 +from tests.common_db_feed import resources_to_instancedb
9 11
10 12
11 class BaseFrontTestCase(LiveServerTestCase): 13 class BaseFrontTestCase(LiveServerTestCase):
@@ -18,18 +20,18 @@ class BaseFrontTestCase(LiveServerTestCase): @@ -18,18 +20,18 @@ class BaseFrontTestCase(LiveServerTestCase):
18 os.environ['WERKZEUG_RUN_MAIN'] = 'true' 20 os.environ['WERKZEUG_RUN_MAIN'] = 'true'
19 21
20 # pass in test configurations 22 # pass in test configurations
21 - app = create_app(TestConfig)  
22 - self.db_path = os.path.join(app.instance_path, 'test-app.db')  
23 - app.config.update( 23 + self.app = create_app(TestConfig)
  24 + self.db_path = resources_to_instancedb(self.app)
  25 + self.app.config.update(
24 # Specify the test database as the default in_memory wont work for web tests 26 # Specify the test database as the default in_memory wont work for web tests
25 SQLALCHEMY_DATABASE_URI='sqlite:///' + self.db_path, 27 SQLALCHEMY_DATABASE_URI='sqlite:///' + self.db_path,
26 # Change the port that the liveserver listens on as we dont want to conflict with running:5000 28 # Change the port that the liveserver listens on as we dont want to conflict with running:5000
27 LIVESERVER_PORT=8943 29 LIVESERVER_PORT=8943
28 ) 30 )
29 31
30 - self.app_context = app.app_context() 32 + self.app_context = self.app.app_context()
31 self.app_context.push() 33 self.app_context.push()
32 - return app 34 + return self.app
33 35
34 def setUp(self): 36 def setUp(self):
35 self.driver = self.create_chrome_driver() 37 self.driver = self.create_chrome_driver()
@@ -86,4 +88,30 @@ class AccessTestCase(BaseFrontTestCase): @@ -86,4 +88,30 @@ class AccessTestCase(BaseFrontTestCase):
86 88
87 def test_server_is_up_and_running(self): 89 def test_server_is_up_and_running(self):
88 response = urllib.request.urlopen(self.get_server_url()) 90 response = urllib.request.urlopen(self.get_server_url())
89 - self.assertEqual(response.code, 200)  
90 \ No newline at end of file 91 \ No newline at end of file
  92 + self.assertEqual(response.code, 200)
  93 +
  94 + def test_agents_page(self):
  95 + target_url = self.get_server_url() + url_for('main.agents')
  96 + self.driver.get(target_url)
  97 + self.assertEqual(self.driver.current_url, 'http://localhost:8943/agents')
  98 +
  99 + def test_agent_page(self):
  100 + agent_id = 60
  101 + target_url = self.get_server_url() + url_for('main.agent', agent_id=agent_id)
  102 + self.driver.get(target_url)
  103 + self.assertEqual(self.driver.current_url, f'http://localhost:8943/agent/{agent_id}')
  104 + td_elmts = self.driver.find_elements_by_xpath("//table[@id='charge_table']/tbody/tr/td")
  105 + self.assertEqual(260, len(td_elmts))
  106 +
  107 + def test_projects_page(self):
  108 + target_url = self.get_server_url() + url_for('main.projects')
  109 + self.driver.get(target_url)
  110 + self.assertEqual(self.driver.current_url, 'http://localhost:8943/projects')
  111 +
  112 + def test_project_page(self):
  113 + project_id = 8
  114 + target_url = self.get_server_url() + url_for('main.project', project_id=project_id)
  115 + self.driver.get(target_url)
  116 + self.assertEqual(self.driver.current_url, f'http://localhost:8943/project/{project_id}')
  117 + td_elmts = self.driver.find_elements_by_xpath("//table[@id='charge_table']/tbody/tr/td")
  118 + self.assertEqual(1085, len(td_elmts))