Beispiel #1
0
def test_for_no_errors_with_empty_product():
    assert len(ApplicationValidator(
        Application(
            data={
                'products': {}
            })).validate_products()) == 0

    assert len(ApplicationValidator(
        Application(data={})).validate_products()) == 0
Beispiel #2
0
def get_application_by_id(application_id):
    application = (Application.query.filter(
        Application.id == application_id).options(
            joinedload('supplier.domains'),
            joinedload('supplier.domains.assessments'),
            noload('supplier.domains.assessments.briefs')).first_or_404())
    if application.status == 'deleted':
        abort(404)

    agreement = get_current_agreement()

    # Maximum prices are used on the pricing page to encourage value for money
    result = Domain.query.all()
    domains = {'prices': {'maximum': {}}}
    domains['prices']['maximum'] = {
        domain.name: domain.price_maximum
        for domain in result
    }

    errors = ApplicationValidator(application).validate_all()

    return jsonify(application=application.serializable,
                   domains=domains,
                   agreement=agreement.serialize() if agreement else None,
                   application_errors=errors)
Beispiel #3
0
def update_application(application_id):
    application_json = get_application_json()

    application = Application.query.options(
        noload('supplier.*')).get(application_id)
    if application is None:
        abort(404, "Application '{}' does not exist".format(application_id))

    if application.status == 'submitted' and application_json.get(
            'status') == 'saved':
        db.session.add(
            AuditEvent(audit_type=AuditTypes.revert_application,
                       user='',
                       data={},
                       db_object=application))
        publish_tasks.application.delay(
            publish_tasks.compress_application(application), 'reverted')

    application.update_from_json(application_json)
    save_application(application)
    errors = ApplicationValidator(application).validate_all()
    agreement = get_current_agreement()

    return (jsonify(application=application.serializable,
                    agreement=agreement.serialize() if agreement else None,
                    application_errors=errors), 200)
def test_can_get_error_when_no_documents():
    application = Application(
        data={}
    )
    errors = ApplicationValidator(application).validate_documents()

    assert len(errors) == 1
def test_for_no_errors_as_non_recruiter_with_no_recruiter_info():
    assert len(
        ApplicationValidator(
            Application(data={
                'recruiter': 'no',
                'services': {
                    'service_1': True
                }
            })).validate_candidates()) == 0
def test_can_get_errors_with_empty_string():
    application = Application(
        data={
            'number_of_employees': ''
        }
    )
    errors = ApplicationValidator(application).validate_details()

    assert len(errors) == 1
def test_can_get_errors_as_recruiter_with_no_recruiter_info(recruiter):
    assert len(
        ApplicationValidator(
            Application(data={
                'recruiter': recruiter,
                'services': {
                    'service_1': True
                }
            })).validate_candidates()) == 1
Beispiel #8
0
def test_can_get_errors_with_unfilled_product():
    assert len(ApplicationValidator(
        Application(
            data={
                'products': {
                    '0': {}
                }
            }
        )).validate_products()) == 5
def test_for_no_errors_as_recruiter_with_no_pricing():
    assert len(ApplicationValidator(
        Application(
            data={
                'recruiter': 'yes',
                'services': {
                    'service_1': True
                }
            })).validate_pricing()) == 0
Beispiel #10
0
def test_get_no_errors_for_sa_past_date_and_no_licence_number():
    application = Application(data={
        'recruiter': 'yes',
        'labourHire': {
            'sa': {
                'expiry': '01/01/2019'
            }
        }
    })
    errors = ApplicationValidator(application).validate_recruiter()

    assert len(errors) == 0
def test_can_get_errors_as_non_recruiter_with_no_matching_service(recruiter):
    assert len(ApplicationValidator(
        Application(
            data={
                'recruiter': recruiter,
                'services': {
                    'service_1': True
                },
                'pricing': {
                    'service_2': {}
                }
            })).validate_pricing()) == 1
Beispiel #12
0
def test_can_get_error_for_no_expiry():
    application = Application(
        data={
            'recruiter': 'yes',
            'labourHire': {
                'vic': {
                    'licenceNumber': 'foobar-licence'
                }
            }
        })
    errors = ApplicationValidator(application).validate_recruiter()

    assert len(errors) == 1
def test_can_get_errors_with_empty_string():
    application = Application(
        data={
            'representative': '',
            'email': '',
            'phone': '',
            'contact_name': '',
            'contact_email': '',
            'contact_phone': ''
        }
    )
    errors = ApplicationValidator(application).validate_contacts()

    assert len(errors) == 6
Beispiel #14
0
def test_for_no_errors_with_filled_product():
    assert len(ApplicationValidator(
        Application(
            data={
                'products': {
                    '0': {
                        'name': '1',
                        'summary': '2',
                        'website': 'http://unsafe.site',
                        'pricing': 'https://www.google.com',
                        'support': 'http://www.google.com'
                    }
                }
            })).validate_products()) == 0
Beispiel #15
0
def test_for_errors_with_bad_url():
    assert len(ApplicationValidator(
        Application(
            data={
                'products': {
                    '0': {
                        'name': '1',
                        'summary': '2',
                        'website': '3',
                        'pricing': '4',
                        'support': '5'
                    }
                }
            })).validate_products()) == 3
Beispiel #16
0
def test_can_get_errors_with_yes():
    application = Application(
        data={
            'disclosures': {
                'structual_changes': 'yes',
                'investigations': 'yes',
                'legal_proceedings': 'yes',
                'insurance_claims': 'yes',
                'conflicts_of_interest': 'yes',
                'other_circumstances': 'yes'
            }
        })
    errors = ApplicationValidator(application).validate_disclosures()
    assert len([e for e in errors if e.get('field').endswith('details')]) == 6
    assert len(errors) == 6
Beispiel #17
0
def test_get_no_errors_from_sa_empty_licence_number():
    expiry_date = date.today() + timedelta(days=10)
    expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month,
                               expiry_date.day)
    application = Application(data={
        'recruiter': 'yes',
        'labourHire': {
            'sa': {
                'expiry': expiry
            }
        }
    })
    errors = ApplicationValidator(application).validate_recruiter()

    assert len(errors) == 0
Beispiel #18
0
def test_can_get_errors_with_empty_string():
    application = Application(
        data={
            'disclosures': {
                'structual_changes': '',
                'investigations': '',
                'legal_proceedings': '',
                'insurance_claims': '',
                'conflicts_of_interest': '',
                'other_circumstances': ''
            }
        })
    errors = ApplicationValidator(application).validate_disclosures()

    assert len(errors) == 6
Beispiel #19
0
def test_valid_for_recruiter_and_labour_hire():
    expiry_date = date.today() + timedelta(days=10)
    expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month,
                               expiry_date.day)
    application = Application(
        data={
            'recruiter': 'yes',
            'labourHire': {
                'vic': {
                    'expiry': expiry,
                    'licenceNumber': 'foobar-licence'
                }
            }
        })
    errors = ApplicationValidator(application).validate_recruiter()

    assert len(errors) == 0
def test_for_no_errors_as_recruiter_with_filled_recruiter_info(recruiter):
    assert len(
        ApplicationValidator(
            Application(
                data={
                    'recruiter': recruiter,
                    'services': {
                        'service_1': True
                    },
                    'recruiter_info': {
                        'service_1': {
                            'database_size': '1',
                            'active_candidates': '2',
                            'margin': '3',
                            'markup': '4',
                            'placed_candidates': '5'
                        }
                    }
                })).validate_candidates()) == 0
def test_can_get_error_for_no_filename():
    application = Application(
        data={
            'documents': {
                'liability': {
                    'filename': '',
                    'expiry': '2018/01/01'
                },
                'workers': {
                    'filename': '',
                    'expiry': '2018/01/01'
                },
                'financial': {
                    'filename': ''
                }
            }
        }
    )
    errors = ApplicationValidator(application).validate_documents()

    assert len(errors) == 5
Beispiel #22
0
def test_can_get_errors_with_empty_string():
    application = Application(
        data={
            'name':
            '',
            'abn':
            '',
            'summary':
            '',
            'website':
            '',
            'addresses': [{
                'address_line': '',
                'suburb': '',
                'state': '',
                'postal_code': ''
            }]
        })
    errors = ApplicationValidator(application).validate_basics()

    assert len(errors) == 8
Beispiel #23
0
def test_for_no_errors_with_correct_application():
    application = Application(
        data={
            'name':
            'Jogn',
            'abn':
            '123',
            'summary':
            'summary',
            'website':
            'https://',
            'addresses': [{
                'address_line': '8 some street',
                'suburb': 'City',
                'state': 'ACT',
                'postal_code': '2600'
            }],
            'linkedin':
            'http://'
        })
    errors = ApplicationValidator(application).validate_basics()

    assert len(errors) == 0
Beispiel #24
0
def test_can_get_errors_with_incorrect_url():
    application = Application(
        data={
            'name':
            None,
            'abn':
            None,
            'summary':
            None,
            'website':
            'foobar',
            'addresses': [{
                'address_line': None,
                'suburb': None,
                'state': None,
                'postal_code': None
            }],
            'linkedin':
            'ftp://'
        })
    errors = ApplicationValidator(application).validate_basics()

    assert len(errors) == 9
Beispiel #25
0
def test_no_errors_for_valid_recruiter():
    application = Application(data={'recruiter': 'yes'})
    errors = ApplicationValidator(application).validate_recruiter()

    assert len(errors) == 0
Beispiel #26
0
def submit_application(application_id):
    current_time = pendulum.now('UTC').to_iso8601_string(extended=True)

    application = Application.query.get(application_id)
    if application is None:
        abort(404, "Application '{}' does not exist".format(application_id))

    if application.status == 'submitted':
        abort(400, 'Application is already submitted')

    errors = ApplicationValidator(application).validate_all()
    if errors:
        abort(400, 'Application has errors')

    json_payload = get_json_from_request()
    json_has_required_keys(json_payload, ['user_id'])
    user_id = json_payload['user_id']

    user = User.query.get(user_id)

    if application.type != 'edit':
        if user.application_id != application.id:
            abort(400, 'User is not authorized to submit application')
    else:
        if user.supplier_code != application.supplier_code:
            abort(
                400,
                'User supplier code does not match application supplier code')

    agreement = get_current_agreement()
    if agreement is None:
        abort(404, 'Current master agreement not found')

    db.session.add(
        AuditEvent(audit_type=AuditTypes.submit_application,
                   user=user_id,
                   data={},
                   db_object=application))

    application.submit_for_approval()

    application.update_from_json({'submitted_at': current_time})

    signed_agreement = None
    if application.type != 'edit':
        # only create signed agreements on initial applications
        signed_agreement = SignedAgreement()
        signed_agreement.user_id = user_id
        signed_agreement.agreement_id = agreement.id
        signed_agreement.signed_at = current_time
        signed_agreement.application_id = application_id

        db.session.add(signed_agreement)

        if application.supplier_code:
            send_submitted_existing_seller_notification(application.id)
        else:
            send_submitted_new_seller_notification(application.id)

    db.session.commit()
    publish_tasks.application.delay(
        publish_tasks.compress_application(application), 'submitted')
    return jsonify(application=application.serializable,
                   signed_agreement=signed_agreement)
Beispiel #27
0
def test_can_get_errors_when_not_defined():
    application = Application(data={})
    errors = ApplicationValidator(application).validate_basics()

    assert len(errors) == 5
Beispiel #28
0
def test_get_no_errors_with_no_services():
    application = Application(data={'recruiter': 'no'})
    errors = ApplicationValidator(application).validate_services()

    assert len(errors) == 0
Beispiel #29
0
def test_can_get_errors_with_none_services():
    application = Application(data={'recruiter': 'yes', 'services': None})
    errors = ApplicationValidator(application).validate_services()

    assert len(errors) == 1
Beispiel #30
0
def test_can_get_errors_with_no_recruiter():
    application = Application(data={})
    errors = ApplicationValidator(application).validate_recruiter()

    assert len(errors) == 1