def test_routes_logged_in_as_guest(_, testapp): """ Verifies behavior of these endpoints for a logged in guest user """ login_user(testapp, 'guest', '53CR3t_p4zZW0rD') # Test if the navigation bar is seen on the main page sees_navbar(testapp) # Test all endpoints routes = [('admin/backup', '<!-- Route: /live -->'), ('admin/upgrade', '<!-- Route: /live -->'), ('admin/statistics', '<!-- Route: /live -->'), ('remote/setup', '<!-- Route: /live -->'), ('settings/alerts', '<!-- Route: /live -->'), ('settings/camera', '<!-- Route: /live -->'), ('settings/general', '<!-- Route: /live -->'), ('settings/users', '<!-- Route: /live -->'), ('systemctl/restart', '<!-- Route: /live -->'), ('systemctl/shutdown', '<!-- Route: /live -->')] for route in routes: response = testapp.get('/{add}'.format(add=route[0])).maybe_follow() assert response.status_code == 200, "Endpoint Tested: {page}".format( page=route[0]) assert route[ 1] in response, "Unexpected HTTP Response: \n{body}".format( body=response.body)
def test_routes_logged_in_as_guest(_, testapp): """ Verifies behavior of these endpoints for a logged in guest user """ print("\nTest: test_routes_logged_in_as_guest") print( "test_routes_logged_in_as_guest: login_user(testapp, 'guest', '53CR3t_p4zZW0rD')" ) login_user(testapp, 'guest', '53CR3t_p4zZW0rD') # Test if the navigation bar is seen on the main page sees_navbar(testapp) # Test all endpoints routes = [('admin/backup', '<!-- Route: /live -->'), ('admin/upgrade', '<!-- Route: /live -->'), ('admin/statistics', '<!-- Route: /live -->'), ('remote/setup', '<!-- Route: /live -->'), ('settings/alerts', '<!-- Route: /live -->'), ('settings/diagnostic', '<!-- Route: /live -->'), ('settings/general', '<!-- Route: /live -->'), ('settings/measurement', '<!-- Route: /live -->'), ('settings/users', '<!-- Route: /live -->'), ('systemctl/restart', '<!-- Route: /live -->'), ('systemctl/shutdown', '<!-- Route: /live -->')] for index, route in enumerate(routes): print( "test_routes_logged_in_as_guest: Test Route ({}/{}): testapp.get('/{}').maybe_follow()" .format(index + 1, len(routes), route[0])) response = testapp.get('/{add}'.format(add=route[0])).maybe_follow() assert response.status_code == 200, "Endpoint Tested: {page}".format( page=route[0]) assert route[ 1] in response, "Unexpected HTTP Response: \n{body}".format( body=response.body)
def test_add_all_function_actions_logged_in_as_admin(_, testapp): """Verifies adding all function actions as a logged in admin user.""" print("\nTest: test_add_all_function_actions_logged_in_as_admin") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') action_count = 0 choices_action = [] dict_actions = parse_action_information() for action in dict_actions: choices_action.append(action) # Add Execute Actions function response = add_function(testapp, function_type="function_actions") assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 function_dev = Function.query.filter(Function.id == 1).first() # Add/delete every action for index, each_action in enumerate(choices_action): print("test_add_all_function_actions_logged_in_as_admin: Adding, saving, and deleting Action ({}/{}): {}".format( index + 1, len(choices_action), each_action)) response = add_action(testapp, function_id=function_dev.unique_id, action_type=each_action) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 action = Actions.query.first() # Verify data was entered into the database action_count += 1 assert Actions.query.count() == action_count, "Number of Actions doesn't match: In DB {}, Should be: {}".format( Actions.query.count(), action_count) # Delete action response = delete_data(testapp, 'action', device_dev=action) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 action_count -= 1 # Delete function response = delete_data(testapp, 'function', device_dev=function_dev) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1
def test_routes_logged_in_as_guest(_, testapp): """ Verifies behavior of these endpoints for a logged in guest user """ login_user(testapp, 'guest', '53CR3t_p4zZW0rD') # Test if the navigation bar is seen on the main page sees_navbar(testapp) # Test all endpoints routes = [ ('admin/backup', '<!-- Route: /live -->'), ('admin/upgrade', '<!-- Route: /live -->'), ('admin/statistics', '<!-- Route: /live -->'), ('remote/setup', '<!-- Route: /live -->'), ('settings/alerts', '<!-- Route: /live -->'), ('settings/camera', '<!-- Route: /live -->'), ('settings/diagnostic', '<!-- Route: /live -->'), ('settings/general', '<!-- Route: /live -->'), ('settings/measurement', '<!-- Route: /live -->'), ('settings/users', '<!-- Route: /live -->'), ('systemctl/restart', '<!-- Route: /live -->'), ('systemctl/shutdown', '<!-- Route: /live -->') ] for route in routes: response = testapp.get('/{add}'.format(add=route[0])).maybe_follow() assert response.status_code == 200, "Endpoint Tested: {page}".format(page=route[0]) assert route[1] in response, "Unexpected HTTP Response: \n{body}".format(body=response.body)
def test_add_all_input_devices_logged_in_as_admin(_, testapp): """ Verifies adding all inputs as a logged in admin user """ print("\nTest: test_add_all_input_devices_logged_in_as_admin") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Inputs input_count = 0 dict_inputs = parse_input_information() list_inputs_sorted = generate_form_input_list(dict_inputs) choices_input = [] for each_input in list_inputs_sorted: if 'interfaces' not in dict_inputs[each_input]: choices_input.append('{inp},'.format(inp=each_input)) else: for each_interface in dict_inputs[each_input]['interfaces']: choices_input.append('{inp},{int}'.format(inp=each_input, int=each_interface)) for index, each_input in enumerate(choices_input): choice_name = each_input.split(',')[0] print("test_add_all_input_devices_logged_in_as_admin: Adding, saving, and deleting Input ({}/{}): {}".format( index + 1, len(choices_input), each_input)) response = add_data(testapp, input_type=each_input) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 # Verify data was entered into the database input_count += 1 assert Input.query.count() == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format( Input.query.count(), input_count) input_dev = Input.query.filter(Input.id == input_count).first() assert choice_name == input_dev.device, "Input name doesn't match: {}".format(choice_name) # Save input response = save_data(testapp, 'input', device_dev=input_dev) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 # Delete input (speeds up further input addition checking) response = delete_data(testapp, 'input', device_dev=input_dev) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 input_count -= 1 assert Input.query.count() == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format( Input.query.count(), input_count)
def test_routes_logged_in_as_admin(_, testapp): """ Verifies behavior of these endpoints for a logged in admin user """ print("\nTest: test_routes_logged_in_as_admin") print( "test_routes_logged_in_as_admin: login_user(testapp, 'admin', '53CR3t_p4zZW0rD')" ) login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Test if the navigation bar is seen on the main page sees_navbar(testapp) # Test all endpoints routes = [('api', 'Mycodo API'), ('admin/backup', '<!-- Route: /admin/backup -->'), ('admin/statistics', '<!-- Route: /admin/statistics -->'), ('admin/upgrade', '<!-- Route: /admin/upgrade -->'), ('settings/alerts', '<!-- Route: /settings/alerts -->'), ('settings/general', '<!-- Route: /settings/general -->'), ('settings/input', '<!-- Route: /settings/input -->'), ('settings/measurement', '<!-- Route: /settings/measurement -->'), ('settings/users', '<!-- Route: /settings/users -->'), ('calibration', '<!-- Route: /calibration -->'), ('camera', '<!-- Route: /camera -->'), ('dashboard', '<!-- Route: /dashboard -->'), ('input', '<!-- Route: /input -->'), ('export', '<!-- Route: /export -->'), ('forgot_password', '<!-- Route: /forgot_password -->'), ('function', '<!-- Route: /function -->'), ('graph-async', '<!-- Route: /graph-async -->'), ('info', '<!-- Route: /info -->'), ('lcd', '<!-- Route: /lcd -->'), ('live', '<!-- Route: /live -->'), ('logview', '<!-- Route: /logview -->'), ('method', '<!-- Route: /method -->'), ('method-build/-1', 'admin logged in'), ('notes', '<!-- Route: /notes -->'), ('note_edit/0', 'admin logged in'), ('output', '<!-- Route: /output -->'), ('remote/setup', '<!-- Route: /remote/setup -->'), ('reset_password', '<!-- Route: /reset_password -->'), ('setup_atlas_ph', '<!-- Route: /setup_atlas_ph -->'), ('setup_ds_resolution', '<!-- Route: /setup_ds_resolution -->'), ('usage', '<!-- Route: /usage -->'), ('usage_reports', '<!-- Route: /usage_reports -->')] for index, route in enumerate(routes): print( "test_routes_logged_in_as_admin: Test Route ({}/{}): testapp.get('/{}').maybe_follow()" .format(index + 1, len(routes), route[0])) response = testapp.get('/{add}'.format(add=route[0])).maybe_follow() assert response.status_code == 200, "Endpoint Tested: {page}".format( page=route[0]) assert route[ 1] in response, "Unexpected HTTP Response: \n{body}".format( body=response.body)
def test_add_all_data_devices_logged_in_as_admin(_, testapp): """ Verifies adding all inputs as a logged in admin user """ login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Inputs input_count = 0 dict_inputs = parse_input_information() list_inputs_sorted = generate_form_input_list(dict_inputs) choices_input = [] for each_input in list_inputs_sorted: if 'interfaces' not in dict_inputs[each_input]: choices_input.append('{inp},'.format(inp=each_input)) else: for each_interface in dict_inputs[each_input]['interfaces']: choices_input.append('{inp},{int}'.format(inp=each_input, int=each_interface)) for each_input in choices_input: choice_name = each_input.split(',')[0] print("Testing {}".format(each_input)) response = add_data(testapp, data_type='input', input_type=each_input) # Verify success message flashed assert "{} Input with ID".format(choice_name) in response assert "successfully added" in response # Verify data was entered into the database input_count += 1 assert Input.query.count( ) == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format( Input.query.count(), input_count) input_dev = Input.query.filter(Input.id == input_count).first() assert dict_inputs[choice_name][ 'input_name'] in input_dev.name, "Input name doesn't match: {}".format( choice_name) # Add All Maths math_count = 0 for each_math in MATH_INFO.keys(): response = add_data(testapp, data_type='math', input_type=each_math) # Verify success message flashed assert "{} Math with ID".format(each_math) in response assert "successfully added" in response # Verify data was entered into the database math_count += 1 actual_count = Math.query.count() assert actual_count == math_count, "Number of Maths don't match: In DB {}, Should be: {}".format( actual_count, math_count) math_dev = Math.query.filter(Math.id == math_count).first() assert each_math in math_dev.math_type, "Math type doesn't match: {}".format( each_math)
def test_add_all_data_devices_logged_in_as_admin(_, testapp): """ Verifies adding all inputs as a logged in admin user """ login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Inputs input_count = 0 dict_inputs = parse_input_information() list_inputs_sorted = generate_form_input_list(dict_inputs) choices_input = [] for each_input in list_inputs_sorted: if 'interfaces' not in dict_inputs[each_input]: choices_input.append('{inp},'.format(inp=each_input)) else: for each_interface in dict_inputs[each_input]['interfaces']: choices_input.append('{inp},{int}'.format(inp=each_input, int=each_interface)) for each_input in choices_input: choice_name = each_input.split(',')[0] print("Testing {}".format(each_input)) response = add_data(testapp, data_type='input', input_type=each_input) # Verify success message flashed assert "{} Input with ID".format(choice_name) in response assert "successfully added" in response # Verify data was entered into the database input_count += 1 assert Input.query.count() == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format(Input.query.count(), input_count) input_dev = Input.query.filter(Input.id == input_count).first() assert dict_inputs[choice_name]['input_name'] in input_dev.name, "Input name doesn't match: {}".format(choice_name) # Add All Maths math_count = 0 for each_math in MATH_INFO.keys(): response = add_data(testapp, data_type='math', input_type=each_math) # Verify success message flashed assert "{} Math with ID".format(each_math) in response assert "successfully added" in response # Verify data was entered into the database math_count += 1 actual_count = Math.query.count() assert actual_count == math_count, "Number of Maths don't match: In DB {}, Should be: {}".format(actual_count, math_count) math_dev = Math.query.filter(Math.id == math_count).first() assert each_math in math_dev.math_type, "Math type doesn't match: {}".format(each_math)
def test_api_logged_in_as_admin(_, testapp): """ Verifies behavior of these API endpoints for a logged in admin user """ print("\nTest: test_api_logged_in_as_admin") print("test_routes_logged_in_as_admin: login_user(testapp, 'admin', '53CR3t_p4zZW0rD')") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Test all endpoints for index, route in enumerate(api_endpoints): print("test_routes_logged_in_as_admin: Test Route ({}/{}): testapp.get('/api/{}')".format( index + 1, len(api_endpoints), route[0])) response = testapp.get( '/api/{add}'.format(add=route[0]), headers={'Accept': 'application/vnd.mycodo.v1+json'}) assert response.status_code == 200, "Endpoint Tested: {page}".format(page=route[0]) assert route[1] in response, "Unexpected HTTP Response: \n{body}".format(body=response.body)
def test_add_all_data_devices_logged_in_as_admin(_, testapp): """ Verifies adding all inputs as a logged in admin user """ login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Inputs input_count = 0 for each_input, each_data in parse_input_information().items(): for each_interface in each_data['interfaces']: response = add_data(testapp, data_type='input', input_type='{},{}'.format( each_input, each_interface)) # Verify success message flashed assert "{} Input with ID".format(each_input) in response assert "successfully added" in response # Verify data was entered into the database input_count += 1 assert Input.query.count( ) == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format( Input.query.count(), input_count) input_dev = Input.query.filter(Input.id == input_count).first() assert each_data[ 'input_name'] in input_dev.name, "Input name doesn't match: {}".format( each_input) # Add All Maths math_count = 0 for each_math, each_data in MATH_INFO.items(): response = add_data(testapp, data_type='math', input_type=each_math) # Verify success message flashed assert "{} Math with ID".format(each_math) in response assert "successfully added" in response # Verify data was entered into the database math_count += 1 actual_count = Math.query.count() assert actual_count == math_count, "Number of Maths doesn't match: In DB {}, Should be: {}".format( actual_count, math_count) math_dev = Math.query.filter(Math.id == math_count).first() assert each_data[ 'name'] in math_dev.name, "Math name doesn't match: {}".format( each_math)
def test_routes_logged_in_as_admin(_, testapp): """ Verifies behavior of these endpoints for a logged in admin user """ login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Test if the navigation bar is seen on the main page sees_navbar(testapp) # Test all endpoints routes = [ ('admin/backup', '<!-- Route: /admin/backup -->'), ('admin/statistics', '<!-- Route: /admin/statistics -->'), ('admin/upgrade', '<!-- Route: /admin/upgrade -->'), ('settings/alerts', '<!-- Route: /settings/alerts -->'), ('settings/camera', '<!-- Route: /settings/camera -->'), ('settings/general', '<!-- Route: /settings/general -->'), ('settings/input', '<!-- Route: /settings/input -->'), ('settings/measurement', '<!-- Route: /settings/measurement -->'), ('settings/users', '<!-- Route: /settings/users -->'), ('calibration', '<!-- Route: /calibration -->'), ('camera', '<!-- Route: /camera -->'), ('dashboard', '<!-- Route: /dashboard -->'), ('data', '<!-- Route: /data -->'), ('export', '<!-- Route: /export -->'), ('function', '<!-- Route: /function -->'), ('graph-async', '<!-- Route: /graph-async -->'), ('help', '<h1 class="title">Mycodo Manual</h1>'), ('info', '<!-- Route: /info -->'), ('lcd', '<!-- Route: /lcd -->'), ('live', '<!-- Route: /live -->'), ('logview', '<!-- Route: /logview -->'), ('method', '<!-- Route: /method -->'), ('method-build/-1', 'admin logged in'), ('notes', '<!-- Route: /notes -->'), ('note_edit/0', 'admin logged in'), ('output', '<!-- Route: /output -->'), ('remote/setup', '<!-- Route: /remote/setup -->'), ('setup_atlas_ph', '<!-- Route: /setup_atlas_ph -->'), ('setup_ds_resolution', '<!-- Route: /setup_ds_resolution -->'), ('usage', '<!-- Route: /usage -->'), ('usage_reports', '<!-- Route: /usage_reports -->') ] for route in routes: response = testapp.get('/{add}'.format(add=route[0])).maybe_follow() assert response.status_code == 200, "Endpoint Tested: {page}".format(page=route[0]) assert route[1] in response, "Unexpected HTTP Response: \n{body}".format(body=response.body)
def test_add_all_output_devices_logged_in_as_admin(_, testapp): """ Verifies adding all outputs as a logged in admin user """ print("\nTest: test_add_all_output_devices_logged_in_as_admin") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Inputs output_count = 0 dict_outputs = parse_output_information() list_outputs_sorted = generate_form_output_list(dict_outputs) choices_output = [] for each_output in list_outputs_sorted: if 'interfaces' not in dict_outputs[each_output]: choices_output.append('{inp},'.format(inp=each_output)) else: for each_interface in dict_outputs[each_output]['interfaces']: choices_output.append('{inp},{int}'.format(inp=each_output, int=each_interface)) for index, each_output in enumerate(choices_output): print( "test_add_all_output_devices_logged_in_as_admin: Adding, saving, and deleting Output ({}/{}): {}" .format(index + 1, len(choices_output), each_output)) response = add_output(testapp, output_type=each_output) # Verify success message flashed assert "with ID 1 successfully added" in response # Verify data was entered into the database output_count += 1 assert Output.query.count( ) == output_count, "Number of Outputs doesn't match: In DB {}, Should be: {}".format( Output.query.count(), output_count) output = Output.query.filter(Output.id == output_count).first() # Save output response = save_data(testapp, 'output', device_dev=output) assert "Success: Modify Output" in response # Delete output (speeds up further output addition checking) response = delete_data(testapp, 'output', device_dev=output) assert "Success: Delete output with ID: {}".format( output.unique_id) in response output_count -= 1
def test_routes_logged_in_as_admin(_, testapp): """ Verifies behavior of these endpoints for a logged in admin user """ login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Test if the navigation bar is seen on the main page sees_navbar(testapp) # Test all endpoints routes = [('admin/backup', '<!-- Route: /admin/backup -->'), ('admin/statistics', '<!-- Route: /admin/statistics -->'), ('admin/upgrade', '<!-- Route: /admin/upgrade -->'), ('settings/alerts', '<!-- Route: /settings/alerts -->'), ('settings/camera', '<!-- Route: /settings/camera -->'), ('settings/general', '<!-- Route: /settings/general -->'), ('settings/input', '<!-- Route: /settings/input -->'), ('settings/measurement', '<!-- Route: /settings/measurement -->'), ('settings/users', '<!-- Route: /settings/users -->'), ('calibration', '<!-- Route: /calibration -->'), ('camera', '<!-- Route: /camera -->'), ('dashboard', '<!-- Route: /dashboard -->'), ('data', '<!-- Route: /data -->'), ('export', '<!-- Route: /export -->'), ('function', '<!-- Route: /function -->'), ('graph-async', '<!-- Route: /graph-async -->'), ('help', '<h1 class="title">Mycodo Manual</h1>'), ('info', '<!-- Route: /info -->'), ('lcd', '<!-- Route: /lcd -->'), ('live', '<!-- Route: /live -->'), ('logview', '<!-- Route: /logview -->'), ('method', '<!-- Route: /method -->'), ('method-build/-1', 'admin logged in'), ('notes', '<!-- Route: /notes -->'), ('note_edit/0', 'admin logged in'), ('output', '<!-- Route: /output -->'), ('remote/setup', '<!-- Route: /remote/setup -->'), ('usage', '<!-- Route: /usage -->'), ('usage_reports', '<!-- Route: /usage_reports -->')] for route in routes: response = testapp.get('/{add}'.format(add=route[0])).maybe_follow() assert response.status_code == 200, "Endpoint Tested: {page}".format( page=route[0]) assert route[ 1] in response, "Unexpected HTTP Response: \n{body}".format( body=response.body)
def test_add_all_function_devices_logged_in_as_admin(_, testapp): """ Verifies adding all functions as a logged in admin user """ print("\nTest: test_add_all_function_devices_logged_in_as_admin") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Custom Functions function_count = 0 choices_function = choices_custom_functions() for index, each_function in enumerate(choices_function): choice_name = each_function["item"] print( "test_add_all_function_devices_logged_in_as_admin: Adding, saving, and deleting Function ({}/{}): {}" .format(index + 1, len(choices_function), each_function["value"])) response = add_function(testapp, function_type=each_function["value"]) # Verify success message flashed assert "{} Function with ID".format(choice_name) in response assert "Success: Add Function" in response # Verify data was entered into the database function_count += 1 assert CustomController.query.count( ) == function_count, "Number of Functions doesn't match: In DB {}, Should be: {}".format( CustomController.query.count(), function_count) function_dev = CustomController.query.filter( CustomController.id == function_count).first() assert each_function[ "value"] == function_dev.device, "Function name doesn't match: {}".format( choice_name) # Save function response = save_data(testapp, 'function', device_dev=function_dev) assert "Success: Modify Controller" in response # Delete function (speeds up further function addition checking) response = delete_data(testapp, 'function', device_dev=function_dev) assert "Delete custom_controller with ID: {}".format( function_dev.unique_id) in response function_count -= 1
def test_routes_logged_in_as_admin(_, testapp): """ Verifies behavior of these endpoints for a logged in admin user """ login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Test if the navigation bar is seen on the main page sees_navbar(testapp) # Test all endpoints routes = [('admin/backup', '<!-- Route: /admin/backup -->'), ('admin/statistics', '<!-- Route: /admin/statistics -->'), ('admin/upgrade', '<!-- Route: /admin/upgrade -->'), ('settings/alerts', '<!-- Route: /settings/alerts -->'), ('settings/camera', '<!-- Route: /settings/camera -->'), ('settings/general', '<!-- Route: /settings/general -->'), ('settings/users', '<!-- Route: /settings/users -->'), ('camera', '<!-- Route: /camera -->'), ('export', '<!-- Route: /export -->'), ('graph', '<!-- Route: /graph -->'), ('graph-async', '<!-- Route: /graph-async -->'), ('help', '<!-- Route: /help -->'), ('info', '<!-- Route: /info -->'), ('lcd', '<!-- Route: /lcd -->'), ('live', '<!-- Route: /live -->'), ('logview', '<!-- Route: /logview -->'), ('method', '<!-- Route: /method -->'), ('method-build/-1', 'admin logged in'), ('pid', '<!-- Route: /pid -->'), ('relay', '<!-- Route: /relay -->'), ('remote/setup', '<!-- Route: /remote/setup -->'), ('sensor', '<!-- Route: /sensor -->'), ('timer', '<!-- Route: /timer -->'), ('usage', '<!-- Route: /usage -->'), ('usage_reports', '<!-- Route: /usage_reports -->')] for route in routes: response = testapp.get('/{add}'.format(add=route[0])).maybe_follow() assert response.status_code == 200, "Endpoint Tested: {page}".format( page=route[0]) assert route[ 1] in response, "Unexpected HTTP Response: \n{body}".format( body=response.body)
def test_add_all_widgets_logged_in_as_admin(_, testapp): """Verifies adding all widgets as a logged in admin user.""" print("\nTest: test_add_all_widgets_logged_in_as_admin") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Widgets widget_count = 0 dict_widgets = parse_widget_information() list_widgets_sorted = generate_form_widget_list(dict_widgets) choices_widget = [] for each_widget in list_widgets_sorted: choices_widget.append(each_widget) first_dashboard = Dashboard.query.first() if not first_dashboard: print("Error: Could not find a Dashboard, cannot test Widgets.") return for index, each_widget in enumerate(choices_widget): choice_name = each_widget.split(',')[0] print("test_add_all_widget_devices_logged_in_as_admin: Adding, saving, and deleting Widget ({}/{}): {}".format( index + 1, len(choices_widget), each_widget)) add_widget(testapp, dashboard_id=first_dashboard.unique_id, widget_type=each_widget) # Verify data was entered into the database widget_count += 1 assert Widget.query.count() == widget_count, "Number of Widgets doesn't match: In DB {}, Should be: {}".format( Widget.query.count(), widget_count) widget_dev = Widget.query.filter(Widget.id == widget_count).first() assert choice_name == widget_dev.graph_type, "Widget name doesn't match: {}".format(choice_name) # Delete widget (speeds up further widget addition checking) delete_data(testapp, 'widget', device_dev=widget_dev, dashboard_id=first_dashboard.unique_id) widget_count -= 1 assert Widget.query.count() == widget_count, "Number of Widgets doesn't match: In DB {}, Should be: {}".format( Widget.query.count(), widget_count)
def test_add_all_data_devices_logged_in_as_admin(_, testapp): """ Verifies adding all inputs as a logged in admin user """ print("\nTest: test_add_all_data_devices_logged_in_as_admin") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Inputs input_count = 0 dict_inputs = parse_input_information() list_inputs_sorted = generate_form_input_list(dict_inputs) choices_input = [] for each_input in list_inputs_sorted: if 'interfaces' not in dict_inputs[each_input]: choices_input.append('{inp},'.format(inp=each_input)) else: for each_interface in dict_inputs[each_input]['interfaces']: choices_input.append('{inp},{int}'.format(inp=each_input, int=each_interface)) for index, each_input in enumerate(choices_input): choice_name = each_input.split(',')[0] print( "test_add_all_data_devices_logged_in_as_admin: Adding and deleting Input ({}/{}): {}" .format(index + 1, len(choices_input), each_input)) response = add_data(testapp, data_type='input', input_type=each_input) # Verify success message flashed assert "{} Input with ID".format(choice_name) in response assert "successfully added" in response # Verify data was entered into the database input_count += 1 assert Input.query.count( ) == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format( Input.query.count(), input_count) input_dev = Input.query.filter(Input.id == input_count).first() assert choice_name == input_dev.device, "Input name doesn't match: {}".format( choice_name) # Delete input (speeds up further input addition checking) response = delete_data(testapp, data_type='input', device_dev=input_dev) assert "Delete input with ID: {}".format( input_dev.unique_id) in response input_count -= 1 # Add All Maths math_count = 0 for index, each_math in enumerate(MATH_INFO.keys()): print( "test_add_all_data_devices_logged_in_as_admin: Adding Math ({}/{}): {}" .format(index + 1, len(MATH_INFO.keys()), each_math)) response = add_data(testapp, data_type='math', input_type=each_math) # Verify success message flashed assert "{} Math with ID".format(each_math) in response assert "successfully added" in response # Verify data was entered into the database math_count += 1 actual_count = Math.query.count() assert actual_count == math_count, "Number of Maths don't match: In DB {}, Should be: {}".format( actual_count, math_count) math_dev = Math.query.filter(Math.id == math_count).first() assert each_math in math_dev.math_type, "Math type doesn't match: {}".format( each_math) # Delete input (speeds up further input addition checking) response = delete_data(testapp, data_type='math', device_dev=math_dev) assert "Delete math with ID: {}".format(math_dev.unique_id) in response math_count -= 1
def test_add_all_function_devices_logged_in_as_admin(_, testapp): """ Verifies adding all functions as a logged in admin user """ print("\nTest: test_add_all_function_devices_logged_in_as_admin") login_user(testapp, 'admin', '53CR3t_p4zZW0rD') # Add All Custom Functions function_count = 0 # choices_function = choices_custom_functions() list_function_tables = [ CustomController, Conditional, Function, PID, Trigger, ] choices_functions = [] for choice_function in FUNCTIONS: choices_functions.append({'value': choice_function[0], 'item': choice_function[1]}) choices_functions_cus = choices_custom_functions() # Combine function lists choices_function = choices_functions + choices_functions_cus for index, each_function in enumerate(choices_function): print("test_add_all_function_devices_logged_in_as_admin: Adding, saving, and deleting Function ({}/{}): {}".format( index + 1, len(choices_function), each_function["value"])) response = add_function(testapp, function_type=each_function["value"]) print(response.json['data']['messages']) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 # Verify data was entered into the database function_count += 1 total_count = (CustomController.query.count() + Conditional.query.count() + Function.query.count() + PID.query.count() + Trigger.query.count()) assert total_count == function_count, "Number of Functions doesn't match: In DB {}, Should be: {}".format( total_count, function_count) function_dev = None for each_table in list_function_tables: function_dev = each_table.query.filter(each_table.id == function_count).first() if function_dev: break # Save function response = save_data(testapp, 'function', device_dev=function_dev) print(response.json['data']['messages']) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert 'success' in response.json['data']['messages'] # Delete function (speeds up further function addition checking) response = delete_data(testapp, 'function', device_dev=function_dev) print(response.json['data']['messages']) assert 'data' in response.json assert 'messages' in response.json['data'] assert 'error' in response.json['data']['messages'] assert response.json['data']['messages']['error'] == [] assert 'success' in response.json['data']['messages'] assert len(response.json['data']['messages']['success']) == 1 function_count -= 1 total_count = (CustomController.query.count() + Conditional.query.count() + Function.query.count() + PID.query.count() + Trigger.query.count()) assert total_count == function_count, "Number of Functions doesn't match: In DB {}, Should be: {}".format( total_count, function_count)