コード例 #1
0
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.'}
コード例 #2
0
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.'}
コード例 #3
0
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.'
    }
コード例 #4
0
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),
    })
コード例 #5
0
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."}
コード例 #6
0
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."
        }
    }