def test_cupping_scores_required():
    c = CuppingModel({
        'name': 'Tester',
        'session_id': 10,
        'overall_score': '100',
    })
    with pytest.raises(DataError) as e:
        c.validate()

    errors = prettify_schematics_errors(e)
    assert errors == {'scores': 'This field is required.'}
def test_cupping_name_max_length():
    c = CuppingModel({
        'name': 'a' * 129,
        'session_id': 10,
        'overall_score': '100',
        'scores': {
            'Aroma': 12,
        },
    })
    with pytest.raises(DataError) as e:
        c.validate()

    errors = prettify_schematics_errors(e)
    assert errors == {'name': 'String value is too long.'}
def test_cupping_overall_score_max_value():
    c = CuppingModel({
        'name': 'Tester',
        'session_id': 10,
        'scores': {
            'aroma': 5
        },
        'overall_score': '100.1',
    })
    with pytest.raises(DataError) as e:
        c.validate()

    errors = prettify_schematics_errors(e)
    assert errors == {
        'overallScore': 'Value should be less than or equal to 100.'
    }
def cupping_model():
    return CuppingModel({
        'name': random.choice(('Guat', 'Kochere', 'Costa Rica', 'Brazilian')),
        'session_id': random.randint(1, 10000),
        'scores': {
            'Aroma': random.randint(1, 10),
            'Flavor': random.randint(1, 10),
        },
        'overall_score': round(random.randint(50, 99) + random.random(), 1),
    })
def test_cupping_invalid_overall_score():
    with pytest.raises(DataError) as e:
        CuppingModel({
            'name': 'Tester',
            'session_id': 10,
            'overall_score': 'abc',
        })

    errors = prettify_schematics_errors(e)
    assert errors == {'overallScore': "Value 'abc' is not decimal."}
def test_cupping_invalid_cupping_score():
    with pytest.raises(DataError) as e:
        CuppingModel({
            'name': 'Tester',
            'session_id': 10,
            'scores': {
                'Aroma': 'abc',
                'Flavor': '5',
            },
            'overall_score': 88.5,
        })

    errors = prettify_schematics_errors(e)
    assert errors == {
        'scores': {
            'Aroma': "Number 'abc' failed to convert to a decimal."
        }
    }