Skip to content

Commit

Permalink
fix: fix issue with constructing an error message (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsprenkle authored Dec 21, 2022
1 parent aa9adcd commit aa038b3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Change Log
Unreleased

[1.0.1] - 2022-12-21
* Fix a bug in building error response messaging.

[1.0.0] - 2022-02-16
* Dropped Support for Django22, 30 and 31
* Added Support for Django40
Expand Down
2 changes: 1 addition & 1 deletion bulk_grades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Support for bulk scoring and grading.
"""

__version__ = '1.0.0'
__version__ = '1.0.1'

default_app_config = 'bulk_grades.apps.BulkGradesConfig' # pylint: disable=invalid-name
4 changes: 2 additions & 2 deletions bulk_grades/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def post(self, request, course_id, *args, **kwargs):
data = self.processor.status()
data['error_messages'] = []
for error_message in self.processor.error_messages:
line_numbers = [str(line_number+1) for line_number in self.processor.error_messages[error_message]]
is_plural = 's' if len(line_numbers) > 1 else ''
line_numbers = ', '.join(str(line_number+1) for line_number in self.processor.error_messages[error_message])
new_message = f'{error_message} (on line{is_plural} {line_numbers})'
new_message = f'{error_message} (on line{is_plural} {", ".join(line_numbers)})'

data['error_messages'].append(new_message)

Expand Down
30 changes: 30 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@ def test_post(self):
}
)

def test_post_error(self):
# Given bad CSV content
csv_content = 'bad'
csv_file = SimpleUploadedFile('test_file.csv', csv_content.encode('utf8'), content_type='text/csv')

# When I post the file
self.client.login(username=self.staff.username, password=self.password)
response = self.client.post(
reverse('bulk_grades', args=[self.course_id]),
{'csv': csv_file},
)

# Then I get an error response back
self.assertEqual(response.status_code, 200)
self.assertDictEqual(
response.json(),
{
'saved': 0,
'error_messages': ['Missing column: user_id (on line 1)'],
'can_commit': False,
'error_rows': [],
'waiting': False,
'processed': 0,
'saved_error_id': None,
'percentage': '0.0%',
'total': 0,
'result_id': None
}
)


class GradeOperationHistoryViewTests(ViewTestsMixin, TestCase):

Expand Down

0 comments on commit aa038b3

Please sign in to comment.