コード例 #1
0
ファイル: test_csv_import.py プロジェクト: tonthon/autonomie
def test_identification_key(dbsession, association_handler, userdata):
    """
    Test if we use another key than "id" to identify the duplicate entries
    """
    from autonomie_celery.tasks.csv_import import CsvImporter
    from autonomie.models.user.userdatas import UserDatas

    association_dict = {
        'firstname': 'coordonnees_firstname',
        'email': "coordonnees_email1",
        'test': 'coordonnees_emergency_name',
    }
    association_handler.set_association_dict(association_dict)

    importer = CsvImporter(
        dbsession,
        UserDatas,
        get_buffer(),
        association_handler,
        action="update",
        id_key="coordonnees_email1",
    )
    # Ici on utilise le même mail
    new_datas = {
        'email': "*****@*****.**",
        'test': u"Emergency Contact"
    }
    res, msg = importer.import_line(new_datas)
    assert res.coordonnees_lastname == u'lastname'
    assert res.coordonnees_emergency_name == u"Emergency Contact"
コード例 #2
0
ファイル: test_csv_import.py プロジェクト: tonthon/autonomie
def test_override_line(dbsession, association_handler, userdata):
    from autonomie_celery.tasks.csv_import import CsvImporter
    from autonomie.models.user.userdatas import UserDatas

    association_dict = {
        'firstname': 'coordonnees_firstname',
        'email': 'coordonnees_email2',
    }
    association_handler.set_association_dict(association_dict)

    importer = CsvImporter(
        dbsession,
        UserDatas,
        get_buffer(),
        association_handler,
        action="override"
    )
    new_datas = {
        'id': str(userdata.id),
        'firstname': u"Jane",
        'email': "*****@*****.**"
    }
    res, msg = importer.import_line(new_datas)

    assert res.coordonnees_lastname == u'lastname'
    assert res.coordonnees_firstname == u'Jane'
    assert res.coordonnees_email2 == '*****@*****.**'
コード例 #3
0
ファイル: test_csv_import.py プロジェクト: tonthon/autonomie
def test_import_line(dbsession, csv_datas, association_handler,
                     cae_situation_option):
    from autonomie_celery.tasks.csv_import import CsvImporter, DEFAULT_ID_LABEL
    from autonomie.models.user.userdatas import UserDatas

    association_dict = {
        u"Status": u"situation_situation",
        u'PRénom': 'coordonnees_firstname',
        u'Nom': 'coordonnees_lastname',
        u'Email 1': 'coordonnees_email1',
    }
    association_handler.set_association_dict(association_dict)

    line = csv_datas.next()
    importer = CsvImporter(
        dbsession,
        UserDatas,
        get_buffer(),
        association_handler,
        action="insert",
    )
    res, msg = importer.import_line(line.copy())

    assert res.coordonnees_firstname == u'Bienaimé'
    assert res.coordonnees_lastname == u'Arthur'
    assert res.situation_situation.label == u"CaeSituationOption"
    assert sorted(importer.unhandled_datas[0].keys()) == sorted(
        [DEFAULT_ID_LABEL, 'Unknown']
    )
    assert importer.in_error_lines == []

    # We pop a mandatory argument
    association_dict.pop('Nom')
    association_handler.set_association_dict(association_dict)

    from autonomie_celery.exception import MissingMandatoryArgument

    with pytest.raises(MissingMandatoryArgument):
        importer = CsvImporter(
            dbsession,
            UserDatas,
            get_buffer(),
            association_handler,
            action="insert",
        )