This would consolidate the logic in one place:
```
user = get_student_from_identifier(unique_student_identifier)
user_roles = user.roles.filter(course_id=self.course.id).values_list("name", flat=True)
if action == 'allow':
  self.assertIn(role_name, user_roles)
elif action == 'revoke':
   self.assertNotIn(role_name, user_roles)
```