Esempio n. 1
0
def _validate_excel(excelbytes: bytes) -> None:
    with tempfile.NamedTemporaryFile(mode='w+b', suffix='.xlsx',
                                     delete=False) as fp:
        fp.write(excelbytes)
        fp.close()
        coldict = aue.read_excel_as_columnsdict(fp.name)
        os.remove(fp.name)
        assert coldict['email'] == ["*****@*****.**", "*****@*****.**"]
Esempio n. 2
0
def create_seats_from_excel(filename: str, user: aum.User) -> arm.Importstep:
    columnsdict = aue.read_excel_as_columnsdict(filename)
    _validate_room_declarations(columnsdict)
    importstep = _create_importstep(user)
    rooms, importstep.num_new_rooms, importstep.num_existing_rooms = \
        _find_or_create_rooms(columnsdict, importstep)
    seats, importstep.num_new_seats, importstep.num_existing_seats = \
        _find_or_create_seats(rooms)
    importstep.save()
    return importstep
Esempio n. 3
0
def test_write_excel_from_rowslists():
    TestTuple = collections.namedtuple('TestTuple', 'a b c dee')
    testdata = dict(test=[
        TestTuple(a="a1", b="b1", c="c1", dee="d1"),
        TestTuple(a="a2", b="b2", c="c2", dee="d2"),
    ])
    with tempfile.NamedTemporaryFile(prefix="test", suffix=".xlsx", 
                                     delete=False) as fh:
        filename = fh.name  # file is deleted in 'finally' clause
        print(filename)
    try:
        aue.write_excel_from_rowslists(filename, testdata)
        # import time
        # time.sleep(60)
        columns = aue.read_excel_as_columnsdict(filename)
        print(columns)
        assert list(columns.keys()) == ['a', 'b', 'c', 'dee']
        assert len(columns['dee']) == 2
        assert columns['c'][1] == "c2"
    finally:
        os.unlink(filename)
Esempio n. 4
0
def test_read_excel_as_columnsdict():
    cd = aue.read_excel_as_columnsdict(the_3by3_file)
    assert set(cd.keys()) == set(["A-str", "B-int", "C-str"])
    assert cd['A-str'] == ["string1", "string2"]
    assert cd['B-int'] == ['1', '4711']  # not [1, 4711], forced result
    assert cd['C-str'] == ['', '4711']  # not [None, 4711], forced result
Esempio n. 5
0
def test_read_excel_as_columnsdict():
    cd = aue.read_excel_as_columnsdict(the_3by3_file)
    assert set(cd.keys()) == set(["A-str", "B-int", "C-str"])
    assert cd['A-str'] == ["string1", "string2"]
    assert cd['B-int'] == [1, 4711]
    assert cd['C-str'] == [None, 4711]  # Ouch!:
Esempio n. 6
0
def validate_excel_importfile(filename) -> None:
    # may raise InvalidExcelError
    columnsdict = aue.read_excel_as_columnsdict(filename)
    _validate_room_declarations(columnsdict)