<commit_before>import unittest
#from dataactcore.models.jobTrackerInterface import JobTrackerInterface
from dataactcore.models.jobModels import JobStatus, JobDependency, Status, Type
import requests
from interfaces.jobTrackerInterface import JobTrackerInterface

class JobTests(unittest.TestCase):
    BASE_URL = "http://127.0.0.1:5000"
    JSON_HEADER = {"Content-Type": "application/json"}
    TABLE_POPULATED = False # Gets set to true by the first test to populate the tables

    def __init__(self,methodName):
        """ Run scripts to clear the job tables and populate with a defined test set """
        super(JobTests,self).__init__(methodName=methodName)
        if(not self.TABLE_POPULATED):
            # Clear job tables
            import dataactcore.scripts.clearJobs
            #assert(False),"Check tables empty"
            # Populate with a defined test set
            jobTracker = JobTrackerInterface()
            sqlStatements = ["INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (1, " + str(Status.getStatus("ready")) + "," + str(Type.getType("csv_record_validation")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (2, " + str(Status.getStatus("ready")) + "," + str(Type.getType("file_upload")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (3, " + str(Status.getStatus("ready")) + "," + str(Type.getType("csv_record_validation")) + ",1)",
            "INSERT INTO job_dependency (dependency_id, job_id, prerequisite_id) VALUES (1, 3, 2)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (4, " + str(Status.getStatus("ready")) + "," + str(Type.getType("external_validation")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (5, " + str(Status.getStatus("finished")) + "," + str(Type.getType("csv_record_validation")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (6, " + str(Status.getStatus("finished")) + "," + str(Type.getType("file_upload")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (7, " + str(Status.getStatus("ready")) + "," + str(Type.getType("csv_record_validation")) + ",1)",
            "INSERT INTO job_dependency (dependency_id, job_id, prerequisite_id) VALUES (2, 7, 6)",
            ]
            for statement in sqlStatements:
                jobTracker.runStatement(statement)
            JobTests.TABLE_POPULATED = True


    def test_valid_job(self):
        """ Test valid job """

        validResponse = self.validateJob(1)
        if(validResponse.status_code != 200):
            print(validResponse.status_code)
            print(validResponse.json()["errorType"])
            print(validResponse.json()["message"])
            print(validResponse.json()["trace"])
        assert(validResponse.status_code == 200)
        self.assertHeader(validResponse)
        # Check that job is correctly marked as finished
        jobTracker = JobTrackerInterface()
        assert(jobTracker.getStatus(1) == Status.getStatus("finished"))

    def test_bad_id_job(self):
        """ Test job ID not found in job status table """<commit_msg>Fixed submission table bug for jobTests<commit_after>import unittest
#from dataactcore.models.jobTrackerInterface import JobTrackerInterface
from dataactcore.models.jobModels import JobStatus, JobDependency, Status, Type
import requests
from interfaces.jobTrackerInterface import JobTrackerInterface
import os
import inspect
from dataactcore.aws.s3UrlHandler import s3UrlHandler
import json

class JobTests(unittest.TestCase):
    BASE_URL = "http://127.0.0.1:5000"
    JSON_HEADER = {"Content-Type": "application/json"}
    TABLE_POPULATED = False # Gets set to true by the first test to populate the tables

    def __init__(self,methodName):
        """ Run scripts to clear the job tables and populate with a defined test set """
        super(JobTests,self).__init__(methodName=methodName)
        if(not self.TABLE_POPULATED):
            # Clear job tables
            import dataactcore.scripts.clearJobs
            """
            # Get bucket name
            path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
            bucketFile = open(path+"/s3bucket.json","r").read()
            bucketDict = json.loads(bucketFile)
            bucketName = bucketDict["bucket"]

            # Upload needed files to S3
            user = 1
            s3manager = s3UrlHandler(bucketName,user)
            fnameValid = ""
            fnamePrereq = ""
            urlValid = s3manager.getSignedUrl(fnameValid)
            urlPrereq = s3manager.getSignedUrl(fnamePrereq)
            path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
            fullPathValid = path + fnameValid
            fullPathPrereq = path + fnamePrereq
            uploadResponseValid = requests.post(urlValid, files={fnameValid: open(fullPathValid, 'rb')})
            uploadResponsePrereq = requests.post(urlPrereq, files={fnamePrereq: open(fullPathPrereq, 'rb')})
            assert(uploadResponseValid.status_code == 200)
            assert(uploadResponsePrereq.status_code == 200)
            """
            s3FileNameValid = "a" #"/" + str(user) + "/" + fnameValid
            s3FileNamePrereq = "a" # "/" + str(user) + "/" + fnamePrereq

            # Populate with a defined test set
            jobTracker = JobTrackerInterface()
            sqlStatements = ["INSERT INTO submission (submission_id) VALUES (1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id, filename) VALUES (1, " + str(Status.getStatus("ready")) + "," + str(Type.getType("csv_record_validation")) + ",1, '" + s3FileNameValid + "')",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (2, " + str(Status.getStatus("ready")) + "," + str(Type.getType("file_upload")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (3, " + str(Status.getStatus("ready")) + "," + str(Type.getType("csv_record_validation")) + ",1)",
            "INSERT INTO job_dependency (dependency_id, job_id, prerequisite_id) VALUES (1, 3, 2)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (4, " + str(Status.getStatus("ready")) + "," + str(Type.getType("external_validation")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (5, " + str(Status.getStatus("finished")) + "," + str(Type.getType("csv_record_validation")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id) VALUES (6, " + str(Status.getStatus("finished")) + "," + str(Type.getType("file_upload")) + ",1)",
            "INSERT INTO job_status (job_id, status_id, type_id, submission_id, filename) VALUES (7, " + str(Status.getStatus("ready")) + "," + str(Type.getType("csv_record_validation")) + ",1, '" + s3FileNamePrereq + "')",
            "INSERT INTO job_dependency (dependency_id, job_id, prerequisite_id) VALUES (2, 7, 6)",
            ]
            for statement in sqlStatements:
                jobTracker.runStatement(statement)
            JobTests.TABLE_POPULATED = True


    def test_valid_job(self):
        """ Test valid job """

        validResponse = self.validateJob(1)
        if(validResponse.status_code != 200):
            print(validResponse.status_code)
            print(validResponse.json()["errorType"])
            print(validResponse.json()["message"])
            print(validResponse.json()["trace"])
        assert(validResponse.status_code == 200)
        self.assertHeader(validResponse)
        # Check that job is correctly marked as finished
        jobTracker = JobTrackerInterface()
        assert(jobTracker.getStatus(1) == Status.getStatus("finished"))

    def test_bad_id_job(self):
        """ Test job ID not found in job status table """
{'fraction_non_alphanumeric': 0.1277412959980176, 'fraction_numerical': 0.011894436872754306, 'mean_word_length': 3.286776420605417, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3553739', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2290, 'n_words': 530}