diff --git a/tests/frontend_tests.py b/tests/frontend_tests.py index 0ac6a6b..53e536d 100644 --- a/tests/frontend_tests.py +++ b/tests/frontend_tests.py @@ -1,11 +1,13 @@ import os import urllib.request +from flask import url_for from flask_testing import LiveServerTestCase from selenium import webdriver from app import create_app from pdc_config import TestConfig +from tests.common_db_feed import resources_to_instancedb class BaseFrontTestCase(LiveServerTestCase): @@ -18,18 +20,18 @@ class BaseFrontTestCase(LiveServerTestCase): os.environ['WERKZEUG_RUN_MAIN'] = 'true' # pass in test configurations - app = create_app(TestConfig) - self.db_path = os.path.join(app.instance_path, 'test-app.db') - app.config.update( + self.app = create_app(TestConfig) + self.db_path = resources_to_instancedb(self.app) + self.app.config.update( # Specify the test database as the default in_memory wont work for web tests SQLALCHEMY_DATABASE_URI='sqlite:///' + self.db_path, # Change the port that the liveserver listens on as we dont want to conflict with running:5000 LIVESERVER_PORT=8943 ) - self.app_context = app.app_context() + self.app_context = self.app.app_context() self.app_context.push() - return app + return self.app def setUp(self): self.driver = self.create_chrome_driver() @@ -86,4 +88,30 @@ class AccessTestCase(BaseFrontTestCase): def test_server_is_up_and_running(self): response = urllib.request.urlopen(self.get_server_url()) - self.assertEqual(response.code, 200) \ No newline at end of file + self.assertEqual(response.code, 200) + + def test_agents_page(self): + target_url = self.get_server_url() + url_for('main.agents') + self.driver.get(target_url) + self.assertEqual(self.driver.current_url, 'http://localhost:8943/agents') + + def test_agent_page(self): + agent_id = 60 + target_url = self.get_server_url() + url_for('main.agent', agent_id=agent_id) + self.driver.get(target_url) + self.assertEqual(self.driver.current_url, f'http://localhost:8943/agent/{agent_id}') + td_elmts = self.driver.find_elements_by_xpath("//table[@id='charge_table']/tbody/tr/td") + self.assertEqual(260, len(td_elmts)) + + def test_projects_page(self): + target_url = self.get_server_url() + url_for('main.projects') + self.driver.get(target_url) + self.assertEqual(self.driver.current_url, 'http://localhost:8943/projects') + + def test_project_page(self): + project_id = 8 + target_url = self.get_server_url() + url_for('main.project', project_id=project_id) + self.driver.get(target_url) + 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)) -- libgit2 0.21.2