Beispiel #1
0
def test_with_invalid_phone():
    supplier = Supplier(data={
        'representative': 'foo bar',
        'email': '*****@*****.**',
        'phone': 'asd33333f'
    })
    errors = SupplierValidator(supplier).validate_representative()
    assert len(errors) == 1
    assert 'S013-phone' in [e['id'] for e in errors]

    supplier = Supplier(data={
        'representative': 'foo bar',
        'email': '*****@*****.**',
        'phone': 'aaaaa11111'
    })
    errors = SupplierValidator(supplier).validate_representative()
    assert len(errors) == 1
    assert 'S013-phone' in [e['id'] for e in errors]

    supplier = Supplier(data={
        'representative': 'foo bar',
        'email': '*****@*****.**',
        'phone': '11111aaaaa'
    })
    errors = SupplierValidator(supplier).validate_representative()
    assert len(errors) == 1
    assert 'S013-phone' in [e['id'] for e in errors]
Beispiel #2
0
 def has_supplier_errors(self):
     if self.user_role != 'supplier':
         return False
     supplier_validator = SupplierValidator(self.supplier)
     messages = supplier_validator.validate_all()
     if len(messages.errors) > 0:
         return True
     return False
Beispiel #3
0
def test_with_valid_data():
    supplier = Supplier(data={
        'representative': 'foo bar',
        'email': '*****@*****.**',
        'phone': '0123456789'
    })
    errors = SupplierValidator(supplier).validate_representative()

    assert len(errors) == 0

    supplier = Supplier(data={
        'representative': 'foo bar',
        'email': '*****@*****.**',
        'phone': '+(0)123456789'
    })
    errors = SupplierValidator(supplier).validate_representative()

    assert len(errors) == 0
Beispiel #4
0
def test_with_too_many_at_in_email():
    supplier = Supplier(data={
        'representative': 'foo bar',
        'email': 'a@@b.cm',
        'phone': '0123456789'
    })
    errors = SupplierValidator(supplier).validate_representative()

    assert len(errors) == 1
Beispiel #5
0
def get_supplier_messages(code, skip_application_check):
    applications = application_service.find(
        supplier_code=code,
        type='edit'
    ).all()

    supplier = suppliers.get_supplier_by_code(code)
    validation_result = SupplierValidator(supplier).validate_all()

    if any([a for a in applications if a.status == 'saved']):
        validation_result.warnings.append({
            'message': 'You have saved updates on your profile. '
                       'You must submit these changes to the Marketplace for review. '
                       'If you did not make any changes, select \'Discard all updates\'.',
            'severity': 'warning',
            'step': 'update',
            'id': 'SB001'
        })

    if not skip_application_check:
        if any([a for a in applications if a.status == 'submitted']):
            del validation_result.warnings[:]
            del validation_result.errors[:]

    if not has_signed_current_agreement(supplier):
        if get_current_agreement():
            message = (
                'Your authorised representative {must accept the new Master Agreement} '
                'before you can apply for opportunities.'
            )
            validation_result.errors.append({
                'message': message,
                'severity': 'error',
                'step': 'representative',
                'id': 'SB002',
                'links': {
                    'must accept the new Master Agreement': '/2/seller-edit/{}/representative'.format(code)
                }
            })
    else:
        new_master_agreement = get_new_agreement()
        if new_master_agreement:
            start_date = new_master_agreement.start_date.in_tz('Australia/Canberra').date()
            message = (
                'From {}, your authorised representative must '
                'accept the new Master Agreement '
                'before you can apply for opportunities.'
            ).format(start_date.strftime('%-d %B %Y'))

            validation_result.warnings.append({
                'message': message,
                'severity': 'warning',
                'step': 'representative',
                'id': 'SB002'
            })

    return validation_result
Beispiel #6
0
def test_can_get_no_errors_for_sa_no_expiry():
    supplier = Supplier(
        data={
            'recruiter': 'yes',
            'labourHire': {
                'sa': {
                    'licenceNumber': 'foobar-licence'
                }
            }
        }
    )
    errors = SupplierValidator(supplier).validate_recruiter()

    assert len(errors) == 0
Beispiel #7
0
def test_get_no_errors_from_expired_sa_and_empty_licence_number():
    supplier = Supplier(
        data={
            'recruiter': 'yes',
            'labourHire': {
                'sa': {
                    'expiry': '01/01/2019'
                }
            }
        }
    )
    errors = SupplierValidator(supplier).validate_recruiter()

    assert len(errors) == 0
Beispiel #8
0
def test_can_get_error_for_vic_licence_number():
    expiry_date = date.today() + timedelta(days=10)
    expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month, expiry_date.day)
    supplier = Supplier(
        data={
            'recruiter': 'yes',
            'labourHire': {
                'vic': {
                    'expiry': expiry
                }
            }
        }
    )
    errors = SupplierValidator(supplier).validate_recruiter()

    assert len(errors) == 1
Beispiel #9
0
def test_valid_for_recruiter_and_labour_hire_vic():
    expiry_date = date.today() + timedelta(days=10)
    expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month, expiry_date.day)
    supplier = Supplier(
        data={
            'recruiter': 'yes',
            'labourHire': {
                'vic': {
                    'expiry': expiry,
                    'licenceNumber': 'foobar-licence'
                }
            }
        }
    )
    errors = SupplierValidator(supplier).validate_recruiter()

    assert len(errors) == 0
def update_supplier(data, user_info):
    supplier_code = user_info.get('supplier_code')
    email_address = user_info.get('email_address')

    supplier = suppliers.find(code=supplier_code).one_or_none()
    mandatory_supplier_checks(supplier)

    whitelist_fields = ['representative', 'email', 'phone']
    for wf in whitelist_fields:
        if wf not in data.get('data'):
            raise ValidationError('{} is not recognised'.format(wf))

    if 'email' in data.get('data'):
        email = data['data']['email']
        data['data']['email'] = email.encode('utf-8').lower()

    supplier.update_from_json(data.get('data'))

    messages = SupplierValidator(supplier).validate_representative(
        'representative')
    if len([m for m in messages if m.get('severity', '') == 'error']) > 0:
        raise ValidationError(',\n'.join([
            m.get('message') for m in messages
            if m.get('severity', '') == 'error'
        ]))

    suppliers.save(supplier)

    publish_tasks.supplier.delay(publish_tasks.compress_supplier(supplier),
                                 'updated',
                                 updated_by=email_address)

    audit_service.log_audit_event(audit_type=audit_types.update_supplier,
                                  user=email_address,
                                  data={
                                      'supplierCode': supplier.code,
                                      'supplierData': supplier.data
                                  },
                                  db_object=supplier)

    process_auth_rep_email(supplier, data, user_info)
Beispiel #11
0
def test_can_get_errors_with_empty_string():
    supplier = Supplier(data={'representative': '', 'email': '', 'phone': ''})
    errors = SupplierValidator(supplier).validate_representative()

    assert len(errors) == 3