def test_evidence_validate_domain(domains, evidence):
    data = {}
    valid = EvidenceDataValidator(data, evidence[0]).validate_domain()
    assert valid

    valid = EvidenceDataValidator(data).validate_domain()
    assert not valid
Beispiel #2
0
def update_evidence(evidence_id):
    evidence = evidence_service.get_evidence_by_id(evidence_id)
    if not evidence or current_user.supplier_code != evidence.supplier_code:
        not_found("No evidence for id '%s' found" % (evidence_id))

    if evidence.status != 'draft':
        abort('Only draft submissions can be edited')

    data = get_json_from_request()

    publish = False
    if 'publish' in data and data['publish']:
        del data['publish']
        publish = True

    if 'maxDailyRate' in data:
        try:
            data['maxDailyRate'] = int(data['maxDailyRate'])
        except ValueError as e:
            data['maxDailyRate'] = 0

    # Validate the evidence request data
    errors = EvidenceDataValidator(data,
                                   evidence=evidence).validate(publish=publish)
    if len(errors) > 0:
        abort(', '.join(errors))

    if publish:
        evidence.submit()
        if current_app.config['JIRA_FEATURES']:
            create_evidence_assessment_in_jira.delay(evidence_id)
        try:
            send_evidence_assessment_requested_notification(
                evidence.domain_id, current_user.email_address)
        except Exception as e:
            current_app.logger.warn(
                'Failed to send requested assessment email for evidence id: {}, {}'
                .format(evidence_id, e))

    evidence.data = data
    evidence_service.save_evidence(evidence)

    try:
        publish_tasks.evidence.delay(publish_tasks.compress_evidence(evidence),
                                     'updated',
                                     name=current_user.name,
                                     domain=evidence.domain.name,
                                     supplier_code=current_user.supplier_code)

        if publish:
            publish_tasks.evidence.delay(
                publish_tasks.compress_evidence(evidence),
                'submitted',
                name=current_user.name,
                domain=evidence.domain.name,
                supplier_code=current_user.supplier_code)
    except Exception as e:
        pass

    return jsonify(evidence.serialize())
def test_evidence_validate_criteria(domains, evidence):
    ev = next(x for x in evidence if x.domain.id == 1)
    data = {'criteria': [1, 2]}
    valid = EvidenceDataValidator(data, ev).validate_criteria()
    assert valid

    data = {'criteria': [1, 2], 'maxDailyRate': 5}
    valid = EvidenceDataValidator(data, ev).validate_criteria()
    assert valid

    data = {'criteria': [1, 2, 3], 'maxDailyRate': 55555}
    valid = EvidenceDataValidator(data, ev).validate_criteria()
    assert valid

    data = {}
    valid = EvidenceDataValidator(data, ev).validate_criteria()
    assert not valid

    data = {'criteria': []}
    valid = EvidenceDataValidator(data, ev).validate_criteria()
    assert not valid

    data = {'criteria': [11, 22]}
    valid = EvidenceDataValidator(data, ev).validate_criteria()
    assert not valid

    data = {'criteria': [1, 2], 'maxDailyRate': 55555}
    valid = EvidenceDataValidator(data, ev).validate_criteria()
    assert not valid
def test_some_essential_criteria_have_responses(domains, evidence):
    platform_category = (next(domain for domain in domains
                              if domain.name == 'Platforms integration'))

    ev = next(x for x in evidence if x.domain.id == platform_category.id)

    data = {'criteria': [85, 86], 'evidence': {'86': {'response': 'bbbb'}}}

    valid = EvidenceDataValidator(data,
                                  ev).validate_essential_criteria_responses()
    assert not valid
def test_some_essential_criteria_have_been_selected(domains, evidence):
    platform_category = (next(domain for domain in domains
                              if domain.name == 'Platforms integration'))

    ev = next(x for x in evidence if x.domain.id == platform_category.id)

    data = {'criteria': [86]}

    valid = EvidenceDataValidator(data,
                                  ev).validate_selected_essential_criteria()
    assert not valid
def test_evidence_validate_max_rate(domains):
    data = {'maxDailyRate': 100}
    valid = EvidenceDataValidator(data).validate_max_rate()
    assert valid

    data = {}
    valid = EvidenceDataValidator(data).validate_max_rate()
    assert not valid

    data = {'maxDailyRate': 0}
    valid = EvidenceDataValidator(data).validate_max_rate()
    assert not valid

    data = {'maxDailyRate': -1}
    valid = EvidenceDataValidator(data).validate_max_rate()
    assert not valid

    data = {'maxDailyRate': ''}
    valid = EvidenceDataValidator(data).validate_max_rate()
    assert not valid

    data = {'maxDailyRate': 'abc'}
    valid = EvidenceDataValidator(data).validate_max_rate()
    assert not valid
def test_evidence_validate_evidence_response(domains, evidence):
    ev = next(x for x in evidence if x.domain.id == 1)
    data = {
        'criteria': [1, 2],
        'evidence': {
            '1': {
                'response': 'aaaa'
            },
            '2': {
                'response': 'bbbb'
            }
        }
    }
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert valid

    data = {
        'criteria': [1, 2],
        'maxDailyRate': 5,
        'evidence': {
            '1': {
                'response': 'aaaa'
            },
            '2': {
                'response': 'bbbb'
            }
        }
    }
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert valid

    data = {
        'criteria': [1, 2, 3],
        'maxDailyRate': 55555,
        'evidence': {
            '1': {
                'response': 'aaaa'
            },
            '2': {
                'response': 'bbbb'
            },
            '3': {
                'response': 'cccc'
            }
        }
    }
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert valid

    data = {}
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert not valid

    data = {'evidence': {}}
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert not valid

    data = {'criteria': [1, 2], 'evidence': {'1': {'response': 'aaaa'}}}
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert not valid

    data = {
        'criteria': [1, 2],
        'evidence': {
            '1': {
                'response': 'aaaa'
            },
            '2': {
                'response': ''
            }
        }
    }
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert not valid

    data = {
        'criteria': [1, 2],
        'maxDailyRate': 55555,
        'evidence': {
            '1': {
                'response': 'aaaa'
            },
            '2': {
                'response': 'bbbb'
            }
        }
    }
    valid = EvidenceDataValidator(data, ev).validate_evidence_responses()
    assert not valid