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'] == ["*****@*****.**", "*****@*****.**"]
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
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)
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
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!:
def validate_excel_importfile(filename) -> None: # may raise InvalidExcelError columnsdict = aue.read_excel_as_columnsdict(filename) _validate_room_declarations(columnsdict)