Skip to content

Commit

Permalink
Added tests for ParticipationRole and ParticipationTag CRUD.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhuang committed Oct 24, 2020
1 parent 65744eb commit 16bd4c3
Show file tree
Hide file tree
Showing 3 changed files with 605 additions and 6 deletions.
23 changes: 18 additions & 5 deletions course/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,8 +1176,14 @@ def edit_participation_tag(pctx, ptag_id):
form = EditParticipationTagForm(add_new, request.POST, instance=ptag)
try:
if form.is_valid():
form.save()
messages.add_message(request, messages.SUCCESS, _("Changes saved."))
# Ref: https://stackoverflow.com/q/21458387/3437454
with transaction.atomic():
form.save()
if add_new:
msg = _("New participation tag saved.")
else:
msg = _("Changes saved.")
messages.add_message(request, messages.SUCCESS, msg)
return redirect(
"relate-view_participation_tags", pctx.course.identifier)
except IntegrityError:
Expand Down Expand Up @@ -1299,14 +1305,21 @@ def edit_participation_role(pctx, prole_id):
form = EditParticipationRoleForm(add_new, request.POST, instance=prole)
try:
if form.is_valid():
form.save()
messages.add_message(request, messages.SUCCESS, _("Changes saved."))
# Ref: https://stackoverflow.com/q/21458387/3437454
with transaction.atomic():
form.save()

if add_new:
msg = _("New participation role saved.")
else:
msg = _("Changes saved.")
messages.add_message(request, messages.SUCCESS, msg)
return redirect(
"relate-view_participation_roles", pctx.course.identifier)
except IntegrityError:
messages.add_message(
request, messages.ERROR,
_("A participation role with that name already exists."))
_("A participation role with that identifier already exists."))

else:
form = EditParticipationRoleForm(add_new, instance=prole)
Expand Down
4 changes: 4 additions & 0 deletions tests/base_test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def assertResponseContextEqual(self, resp, context_name, expected_value): # noq
except Exception:
self.assertEqual(value, expected_value)

def assertResponseContextLengthEqual(self, resp, context_name, expected_length): # noqa
value = self.get_response_context_value_by_name(resp, context_name)
self.assertEqual(len(value), expected_length)

def assertResponseContextContains(self, resp, # noqa
context_name, expected_value, html=False,
in_bulk=False):
Expand Down
Loading

0 comments on commit 16bd4c3

Please sign in to comment.