Пример #1
0
def test_validate_content_length(config_file):
    config = load_config(config_file.name)
    response = requests.get('{}/v4/{}/jobs'.format(config['JOB_API_ROOT'],
                                                   "jobsproject"),
                            params={'status': 'AVAILABLE'})
    valid = add_production_jobs.validate_content_length(response)
    assert valid is True
Пример #2
0
def test_validate_content_length_returns_false(config_file):
    config = load_config(config_file.name)
    response = requests.get('{}/v4/{}/jobs'.format(config['JOB_API_ROOT'],
                                                   "jobsproject"),
                            params={'status': 'AVAILABLE'})
    # fake an uncomplete read of the data
    response.headers.update({"Content-Length": 99999999})
    valid = add_production_jobs.validate_content_length(response)
    assert valid is False
Пример #3
0
def processing_project(config_file):
    config = load_config(config_file.name)
    jobs_project = "jobsproject"
    odin_project = "odinproject"
    make_project(jobs_project, odin_project, config)
    make_jobs(jobs_project, odin_project, config_file.name)
    yield jobs_project
    # Cleanup
    assert not delete_project(jobs_project, config)
Пример #4
0
def test_main(mocked_claimed, mocked_level1_scans, mocked_level2_projects,
              config_file, processing_project):
    add_production_jobs.main(config_file=config_file.name)
    config = load_config(config_file.name)
    jobs_project = processing_project
    r = requests.get('{}/v4/{}/jobs'.format(config['JOB_API_ROOT'],
                                            jobs_project),
                     params={'status': 'AVAILABLE'})
    ids = [job['Id'] for job in r.json()['Jobs']]
    assert ids == ['1:101', '1:102', '1:103', '1:104', '1:105']
Пример #5
0
def get_jobs_counts(project):
    config = load_config(CONFIG_FILE)
    url = "{}/v4/{}/jobs/count".format(config['JOB_API_ROOT'], project)
    response = requests.get(url)
    response.raise_for_status()
    claimed = response.json()['Counts'][0]['JobsClaimed']
    failed = response.json()['Counts'][0]['JobsFailed']
    url = "{}/v4/{}/jobs?status=available".format(config['JOB_API_ROOT'],
                                                  project)
    response = requests.get(url)
    response.raise_for_status()
    available = len(response.json()['Jobs'])
    return available, claimed, failed
Пример #6
0
def delete_claim_projects(odin_and_microq):

    make_config(*odin_and_microq)
    config = load_config(CONFIG_FILE)

    jobsproject = "claimsjobsproject"
    nojobsproject = "claimsnojobsproject"
    make_projects(jobsproject, nojobsproject, config)

    make_jobs(jobsproject)

    jobids = claim_jobs(jobsproject, config)
    assert jobids
    fail_job(jobsproject, jobids[0], config)

    yield jobsproject, nojobsproject

    # Cleanup
    assert not delete_project(jobsproject, config)
    assert not delete_project(nojobsproject, config)
Пример #7
0
def test_delete_data_in_project(odin_and_microq):
    make_config(*odin_and_microq)
    config = load_config(CONFIG_FILE)
    jobsproject = "mytestproject"

    create_project_main([
        jobsproject, ODIN_PROJECT, WORKER, '--deadline',
        str(date.today() + timedelta(days=10))
    ], CONFIG_FILE)

    make_jobs(jobsproject)

    jobsurl = "{}/v4/{}/jobs".format(
        config['JOB_API_ROOT'],
        jobsproject,
    )
    auth = (config['JOB_API_USERNAME'], config['JOB_API_PASSWORD'])
    response = requests.get(jobsurl, auth=auth)
    response.raise_for_status()

    # post fake l2 data to odin-api
    auth = (config['ODIN_API_ROOT'], config['ODIN_SECRET'])
    for job in response.json()['Jobs']:
        freqmode = int(job["Id"].split(":")[0])
        scanid = int(job["Id"].split(":")[-1])
        data = {
            "L2": l2_prototype,
            "L2I": l2i_prototype,
            "L2C": 'dummystring',
        }
        data["L2"]['ScanID'] = scanid
        data["L2"]['FreqMode'] = freqmode
        data["L2I"]['ScanID'] = scanid
        data["L2I"]['FreqMode'] = freqmode
        url_string = encrypt(
            json.dumps({
                'ScanID': scanid,
                'FreqMode': freqmode,
                'Project': ODIN_PROJECT
            }), config['ODIN_SECRET'])
        post_response = requests.post(
            "{0}?d={1}".format(
                job["URLS"]["URL-Result"].split("/development")[0],
                url_string),
            headers={'Content-Type': "application/json"},
            json=data,
            auth=auth)
        post_response.raise_for_status()

    # check that l2 data are present
    for job in response.json()['Jobs']:
        get_response = requests.get("{0}/{1}".format(job['URLS']["URL-Result"],
                                                     "L2i"))
        get_response.raise_for_status()

    delete_project_data_main([jobsproject], CONFIG_FILE)

    # check l2 data are removed
    for job in response.json()['Jobs']:
        get_response = requests.get("{0}/{1}".format(job['URLS']["URL-Result"],
                                                     "L2i"))
        assert get_response.status_code == 404

    # check no data in jobproject
    auth = (config['JOB_API_USERNAME'], config['JOB_API_PASSWORD'])
    response = requests.get(jobsurl, auth=auth)
    assert len(response.json()['Jobs']) == 0
Пример #8
0
def test_delete_uservice_project_rasises(odin_and_microq):
    make_config(*odin_and_microq)
    config = load_config(CONFIG_FILE)
    jobsproject = "non/existing/project"
    with pytest.raises(BadProjectError):
        delete_uservice_project(jobsproject, config)
Пример #9
0
def test_load_config(config_file, config):
    assert utils.load_config(config_file) == config