diff --git a/unit-tests/files/windows-csv.csv b/unit-tests/files/windows-csv.csv new file mode 100644 index 0000000..e035d79 --- /dev/null +++ b/unit-tests/files/windows-csv.csv @@ -0,0 +1,3 @@ +category,subcategory,groupname,manager,member,schema_id +testcsv,testcsv,csvupload1,manager,member,default-3 +testcsv,testcsv,csvupload2,manager,member,default-3 diff --git a/unit-tests/test_importgroups.py b/unit-tests/test_importgroups.py index 730e463..467b5d8 100644 --- a/unit-tests/test_importgroups.py +++ b/unit-tests/test_importgroups.py @@ -160,6 +160,9 @@ def test_parse_csv(self): args = {"offline_check": True} parse_csv_file("files/csv-import-test.csv", args, "1.9") + # With carriage returns + parse_csv_file("files/windows-csv.csv", args, "1.9") + @patch('sys.stderr', new_callable=StringIO) def test_parse_csv_with_header_suffixes(self, mock_stderr): args = {"offline_check": True} diff --git a/yclienttools/importgroups.py b/yclienttools/importgroups.py index f419dd9..1af306c 100644 --- a/yclienttools/importgroups.py +++ b/yclienttools/importgroups.py @@ -68,11 +68,12 @@ def parse_csv_file(input_file, args, yoda_version): row_number += 1 d = {} for j in range(len(line)): - if len(line[j]): + item = line[j].strip() + if len(item): if header[j] not in d: d[header[j]] = [] - d[header[j]].append(line[j]) + d[header[j]].append(item) rowdata, error = _process_csv_line(d, args, yoda_version)