Exemplo n.º 1
0
def test_setitem_raise_on_invalid_value(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({})
    with pytest.raises(DataError):
        context['key'] = 'invalid'
    assert 'key' not in context
    assert context.get('key') is None
Exemplo n.º 2
0
def test_copy_should_copy_data_and_cleaned_data():
    context = Context({'key': 'value'})
    other = context.copy()
    other['key'] = 'other'
    assert context['key'] == 'value'
    context['key'] = 'again'
    assert other['key'] == 'other'
Exemplo n.º 3
0
def test_share_one(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition([
        "les codes naf de la formation contiennent au "
        "moins un des codes naf artisanat"
    ])
    assert condition.assess(
        Context({
            'nafs': ['123', '124'],
            'nafs_artisanat': ['123', '456']
        }))
    assert condition.assess(
        Context({
            'nafs': ['123', '124'],
            'nafs_artisanat': ['123']
        }))
    assert condition.assess(
        Context({
            'nafs': ['123'],
            'nafs_artisanat': ['123', '456']
        }))
    assert not condition.assess(
        Context({
            'nafs': ['123', '124'],
            'nafs_artisanat': ['125', '456']
        }))
    assert not condition.assess(Context({'nafs_artisanat': ['125', '456']}))
Exemplo n.º 4
0
def test_contains_condition_with_list_of_str(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition(
        ["le code naf du bénéficiaire fait partie des "
         "[«123»,«45»]"])
    assert condition.assess(Context({'naf': '123'}))
    assert not condition.assess(Context({'naf': 123}))
    assert not condition.assess(Context({'naf': '123,45'}))
Exemplo n.º 5
0
def test_le_int_condition(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition(
        ["l'âge du bénéficiaire "
         "est inférieur ou égal à 18"])
    assert condition.assess(Context({'age': 17}))
    assert condition.assess(Context({'age': 18}))
    assert not condition.assess(Context({'age': 19}))
Exemplo n.º 6
0
def test_inline_condition_with_AND(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition([
        "c'est un bénéficiaire inscrit, et l'âge du "
        "bénéficiaire est supérieur à 50"
    ])
    assert len(condition.terms) == 2
    assert condition.assess(Context({'inscrit': True, 'age': 60}))
    assert not condition.assess(Context({'inscrit': True, 'age': 49}))
Exemplo n.º 7
0
def test_contains_condition(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition([
        "le code naf du bénéficiaire fait partie des "
        "codes naf de la formation"
    ])
    assert condition.assess(Context({'naf': '123', 'nafs': ['123', '456']}))
    assert not condition.assess(Context({'naf': '123', 'nafs': ['456']}))
    assert not condition.assess(Context({'unknown': True}))
Exemplo n.º 8
0
def test_line_condition_with_OR(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition([
        "c'est un bénéficiaire inscrit, ou l'âge du "
        "bénéficiaire est supérieur à 50"
    ])
    assert len(condition.terms) == 2
    assert condition.assess(Context({'inscrit': True, 'age': 39}))
    assert condition.assess(Context({'inscrit': False, 'age': 51}))
    assert not condition.assess(Context({'inscrit': False, 'age': 39}))
Exemplo n.º 9
0
def test_equal_AND_combined_condition(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition([
        "c'est un bénéficiaire inscrit",
        "l'âge du bénéficiaire est supérieur à 50"
    ],
                          connective=Condition.AND)
    assert len(condition.terms) == 2
    assert condition.assess(Context({'inscrit': True, 'age': 60}))
    assert not condition.assess(Context({'inscrit': True, 'age': 49}))
Exemplo n.º 10
0
def test_check_none(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition(
        ["le type de contrat du bénéficiaire n'est pas "
         "défini"])
    assert condition.assess(Context({'contrat': None}))
    assert condition.assess(Context({'contrat': ''}))
    assert condition.assess(Context({'somethingelse': True}))
    assert not condition.assess(Context({'contrat': False}))
    assert not condition.assess(Context({'contrat': True}))
Exemplo n.º 11
0
async def test_preprocess_should_set_codes_cpf_of_de():
    with Path(__file__).parent.joinpath('data/formation.json').open('rb') as f:
        context = Context({'beneficiaire.inscrit_pe': True})
        await routine.populate_formation_from_json(context,
                                                   json.loads(f.read()))
        routine.extrapolate_context(context)
        routine.preprocess(context)
        assert context['formation.codes_cpf'] == {233155, 130805, 232054}
Exemplo n.º 12
0
async def test_populate_formation_from_json_edge_cases(path, key, value):
    path = Path(__file__).parent / f'data/{path}.json'
    data = json.loads(path.read_text())
    context = Context({})
    await routine.populate_formation_from_json(context, data)
    routine.extrapolate_context(context)
    routine.preprocess(context)
    assert context[key] == value
Exemplo n.º 13
0
def test_insee_commune_to_departement(input, expected):
    context = Context({"commune": input})
    if expected:
        insee_commune_to_departement(context, "commune", "beneficiaire.departement")
        assert context["beneficiaire.departement"] == expected
    else:
        with pytest.raises(DataError):
            insee_commune_to_departement(context, "commune", "beneficiaire.departement")
Exemplo n.º 14
0
def test_pointer_should_return_default_value_for_none_value(patch_schema):
    patch_schema(
        {'a_key': {
            'type': 'integer',
            'label': 'a label',
            'default': 123
        }})
    lv = Pointer('a label')
    assert lv.get(Context({'wrong': None})) == 123
Exemplo n.º 15
0
def test_insee_departement_to_region_with_alias(patch_schema):
    patch_schema(
        {
            "departement": {"type": "string", "alias": ["departement_habitation"]},
            "region": {"type": "string"},
        }
    )
    context = Context({"departement_habitation": "35"})
    insee_departement_to_region(context, "departement", "region")
    assert context["region"] == "53"
Exemplo n.º 16
0
def test_insee_commune_to_departement_with_alias(patch_schema):
    patch_schema(
        {
            "commune": {"type": "string", "alias": ["commune_habitation"]},
            "departement": {"type": "string"},
        }
    )
    context = Context({"commune_habitation": "35001"})
    insee_commune_to_departement(context, "commune", "departement")
    assert context["departement"] == "35"
Exemplo n.º 17
0
def test_insee_departement_to_region(input, expected):
    context = Context({"departement": input})
    if expected:
        insee_departement_to_region(context, "departement", "region")
        assert context["region"] == expected
    else:
        if expected is None:
            insee_departement_to_region(context, "departement", "region")
            assert "region" not in context
        else:
            with pytest.raises(DataError):
                insee_departement_to_region(context, "departement", "region")
Exemplo n.º 18
0
async def test_populate_formation_from_json():
    with Path(__file__).parent.joinpath('data/formation.json').open('rb') as f:
        context = Context({})
        await routine.populate_formation_from_json(context,
                                                   json.loads(f.read()))
        routine.extrapolate_context(context)
        routine.preprocess(context)

        assert context['formation.eligible_cpf'] is False
        assert context['formation.codes_naf'] == {
            '0162Z', '0520Z', '2361Z', '4399E', '7820Z', '9604Z', '9609Z'
        }
        assert context['formation.codes_formacode'] == {22403, 22402}
        assert context['formation.domaines_formacode'] == {224}
        assert context['formation.foad'] is False
        assert context['formation.niveau_sortie'] == 4
        assert context['formation.heures'] == 697
        assert context['formation.heures_entreprise'] == 112
        assert context['formation.heures_centre'] == 585
        assert context['formation.mois'] == 7
        assert context['formation.semaines'] == 31
        assert context['formation.duree_hebdo'] == 35
        assert context['formation.codes_financeur'] == {2}
        assert context['formation.certifiante'] is True
        assert context['formation.professionnalisante'] is False
        assert context['formation.codes_cpf'] == {
            233155, 167204, 222991, 18320, 1487, 130805, 227989, 222905
        }
        assert context['formation.codes_cpf_de'] == {233155, 130805, 232054}
        assert context['formation.code_certifinfo'] == 80735
        assert context['formation.code_rncp'] == 320
        assert context['formation.rncp'] is True
        assert context['formation.entrees_sorties_permanentes'] is False
        assert context['formation.contrat_apprentissage'] is False
        assert context['formation.contrat_professionnalisation'] is False
        assert context['formation.poec'] is False
        assert context['formation.departement'] == '37'
        assert context['formation.region'] == '24'
        assert context['formation.siret_organisme'] == 82436343600497
        assert context['formation.intitule'] == "Titre professionnel plaquiste"
Exemplo n.º 19
0
def test_equal_str_condition(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition(["le type de contrat du bénéficiaire est «CDD»"])
    assert condition.assess(Context({'contrat': 'CDD'}))
    assert not condition.assess(Context({'contrat': 'CDI'}))
    assert not condition.assess(Context({'inscrit': False}))
Exemplo n.º 20
0
def test_get_should_return_default_if_key_is_missing(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({})
    assert context.get('key') is None
Exemplo n.º 21
0
def test_gt_int_condition(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition(["l'âge du bénéficiaire est supérieur à 18"])
    assert condition.assess(Context({'age': 19}))
    assert not condition.assess(Context({'age': 17}))
    assert not condition.assess(Context({'age': 18}))
Exemplo n.º 22
0
def test_negative_boolean_condition(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition(["ce n'est pas un bénéficiaire inscrit"])
    assert condition.assess(Context({'inscrit': False}))
    assert not condition.assess(Context({'inscrit': True}))
    assert condition.assess(Context({'unknown': 'X'}))
Exemplo n.º 23
0
def test_get_should_return_default_if_dataerror(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({'key': 'invalid'})
    assert context.get('key') is None
Exemplo n.º 24
0
def test_getitem_should_raise_dataerror(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({'key': 'invalid'})
    with pytest.raises(DataError):
        context['key']
Exemplo n.º 25
0
def test_contains_condition_with_list_of_int(patch_schema):
    patch_schema(SCHEMA)
    condition = Condition(["le code certifinfo fait partie des " "[123,45]"])
    assert condition.assess(Context({'certifinfo': 123}))
    assert not condition.assess(Context({'certifinfo': '124'}))
    assert not condition.assess(Context({'certifinfo': '125.45'}))
Exemplo n.º 26
0
def test_getitem_should_raise_nodataerror_when_key_is_missing(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({})
    with pytest.raises(NoDataError):
        context['key']
Exemplo n.º 27
0
def test_setitem_should_validate_value(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({})
    context['key'] = '12'
    assert context['key'] == 12
Exemplo n.º 28
0
def test_getitem(patch_schema):
    patch_schema({'key': {'type': 'string'}})
    context = Context({'key': 'value'})
    assert context['key'] == 'value'
    assert context.get('key') == 'value'
Exemplo n.º 29
0
def test_should_consume_alias(patch_schema):
    patch_schema({'key': {'type': 'string', 'alias': ['key_alias']}})
    context = Context({'key_alias': 'foo'})
    assert context['key'] == 'foo'