Instead of having another hardcoded SQL code embedded into the source code.
Signed-off-by: Cleber Rosa <[email protected]> --- frontend/tko/rpc_interface_unittest.py | 47 ++++++++-------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/frontend/tko/rpc_interface_unittest.py b/frontend/tko/rpc_interface_unittest.py index 839dace..5f43eff 100755 --- a/frontend/tko/rpc_interface_unittest.py +++ b/frontend/tko/rpc_interface_unittest.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import re, unittest +import os, re, unittest try: import autotest.common as common except ImportError: @@ -11,41 +11,6 @@ from autotest.client.shared.test_utils import mock from django.db import connection from autotest.frontend.tko import models, rpc_interface -# this will need to be updated when the view changes for the test to be -# consistent with reality -_CREATE_TEST_VIEW = """ -CREATE VIEW tko_test_view_2 AS -SELECT tko_tests.test_idx AS test_idx, - tko_tests.job_idx AS job_idx, - tko_tests.test AS test_name, - tko_tests.subdir AS subdir, - tko_tests.kernel_idx AS kernel_idx, - tko_tests.status AS status_idx, - tko_tests.reason AS reason, - tko_tests.machine_idx AS machine_idx, - tko_tests.started_time AS test_started_time, - tko_tests.finished_time AS test_finished_time, - tko_jobs.tag AS job_tag, - tko_jobs.label AS job_name, - tko_jobs.username AS job_owner, - tko_jobs.queued_time AS job_queued_time, - tko_jobs.started_time AS job_started_time, - tko_jobs.finished_time AS job_finished_time, - tko_jobs.afe_job_id AS afe_job_id, - tko_machines.hostname AS hostname, - tko_machines.machine_group AS platform, - tko_machines.owner AS machine_owner, - tko_kernels.kernel_hash AS kernel_hash, - tko_kernels.base AS kernel_base, - tko_kernels.printable AS kernel, - tko_status.word AS status -FROM tko_tests -INNER JOIN tko_jobs ON tko_jobs.job_idx = tko_tests.job_idx -INNER JOIN tko_machines ON tko_machines.machine_idx = tko_jobs.machine_idx -INNER JOIN tko_kernels ON tko_kernels.kernel_idx = tko_tests.kernel_idx -INNER JOIN tko_status ON tko_status.status_idx = tko_tests.status; -""" - # this will need to be updated if the table schemas change (or removed if we # add proper primary keys) _CREATE_ITERATION_ATTRIBUTES = """ @@ -66,6 +31,14 @@ CREATE TABLE tko_iteration_result ( ); """ +def get_create_test_view_sql(): + """ + Returns the SQL code that creates the test view + """ + dir_path = os.path.dirname(os.path.abspath(__file__)) + sql_path = os.path.join(dir_path, 'sql', 'test.sql') + return open(sql_path).read() + def setup_test_view(): """ @@ -74,7 +47,7 @@ def setup_test_view(): """ cursor = connection.cursor() cursor.execute('DROP VIEW IF EXISTS tko_test_view_2') - cursor.execute(_CREATE_TEST_VIEW) + cursor.execute(get_create_test_view_sql()) def fix_iteration_tables(): -- 1.7.11.7 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
