Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions wger/weight/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def parse_weight_csv(request, cleaned_data):

# Process the CSV items first
for row in parsed_csv:
if not row:
continue

try:
parsed_date = make_aware(
datetime.datetime.strptime(row[0], cleaned_data['date_format'])
Expand Down
40 changes: 40 additions & 0 deletions wger/weight/tests/test_csv_blank_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.

# Standard Library
from types import SimpleNamespace

# Django
from django.contrib.auth.models import User

# wger
from wger.core.tests.base_testcase import WgerTestCase
from wger.weight.helpers import parse_weight_csv


class WeightCsvBlankLinesTestCase(WgerTestCase):
"""
Test that blank lines in the CSV are not reported as errors
"""

def test_blank_lines_are_ignored(self):
request = SimpleNamespace(user=User.objects.get(username='test'))
weights, errors = parse_weight_csv(
request,
{'csv_input': '2031-01-01,80\n\n2031-01-02,81\n', 'date_format': '%Y-%m-%d'},
)

self.assertEqual(len(weights), 2)
self.assertEqual(errors, [])