Skip to content

Commit

Permalink
#476 Fix E266 too many leading ‘#’ for block comment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlittle committed Nov 3, 2019
1 parent efc9c97 commit 02a3b02
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 48 deletions.
2 changes: 1 addition & 1 deletion oppia/urls.py
Expand Up @@ -6,7 +6,7 @@
from oppia import views as oppia_views


#Custom HTTP response pages
# Custom HTTP response pages
handler403 = 'oppia.permissions.oppia_403_handler'

urlpatterns = [
Expand Down
6 changes: 3 additions & 3 deletions summary/models/user_course_summary.py
Expand Up @@ -37,7 +37,7 @@ def update_summary(self,
t = time.time()
self_trackers = Tracker.objects.filter(user=self.user, course=self.course, pk__gt=last_tracker_pk, pk__lte=newest_tracker_pk)

### Add the values that are directly obtained from the last pks
# Add the values that are directly obtained from the last pks
self.total_activity = (0 if first_tracker else self.total_activity) + self_trackers.count()
self.total_downloads = (0 if first_tracker else self.total_downloads) + self_trackers.filter(type='download').count()

Expand All @@ -53,14 +53,14 @@ def update_summary(self,
if new_points:
self.points = (0 if first_points else self.points) + new_points

### Values that need to be recalculated (as the course digests may vary)
# Values that need to be recalculated (as the course digests may vary)
self.pretest_score = Course.get_pre_test_score(self.course, self.user)
self.quizzes_passed = Course.get_no_quizzes_completed(self.course, self.user)
self.badges_achieved = Award.get_userawards(self.user, self.course)
self.completed_activities = Course.get_activities_completed(self.course, self.user)
self.media_viewed = Course.get_media_viewed(self.course, self.user)

### Update the data in the database
# Update the data in the database
self.save()

elapsed_time = time.time() - t
Expand Down
2 changes: 1 addition & 1 deletion tests/activitylog/test_permissions.py
Expand Up @@ -40,7 +40,7 @@ def assert_must_login(self, view, user=None, view_kwargs=None):
self.assertRedirects(res, login_url)
return res

############ upload activity log file #############
#upload activity log file
def test_anon_cantview_av_upload(self):
self.assert_must_login('oppia_activitylog_upload')

Expand Down
2 changes: 1 addition & 1 deletion tests/av/test_permissions.py
Expand Up @@ -42,7 +42,7 @@ def assert_must_login(self, view, user=None, view_kwargs=None):
self.assertRedirects(res, login_url)
return res

############ upload media file #############
#upload media file
def test_anon_cantview_av_upload(self):
self.assert_must_login('oppia_av_upload')

Expand Down
130 changes: 88 additions & 42 deletions tests/views/test_permissions.py
Expand Up @@ -16,7 +16,8 @@ def setUp(self):

def get_view(self, route, user=None):
if user is not None:
self.client.login(username=user['user'], password=user['password'])
self.client.login(username=user['user'],
password=user['password'])
return self.client.get(route)

def assert_response(self, view, status_code, user=None, view_kwargs=None):
Expand All @@ -43,9 +44,8 @@ def assert_unauthorized(self, view, user=None, view_kwargs=None):

def assert_not_found(self, view, user=None, view_kwargs=None):
return self.assert_response(view, 404, user, view_kwargs)
# Permissions tests (based on http://oppiamobile.readthedocs.io/en/latest/permissions/server.html)

############ Django admin #############
# Django admin

def test_anon_cantview_admin(self):
self.assert_must_login('admin:index')
Expand All @@ -61,8 +61,8 @@ def test_student_cantview_admin(self):
route = reverse('admin:index')
res = self.get_view(route, NORMAL_USER)
self.assertRedirects(res, route + 'login/?next=' + route)
############ Upload courses view #############

# Upload courses view
def test_anon_cantview_upload_courses(self):
self.assert_must_login('oppia_upload')

Expand All @@ -77,7 +77,8 @@ def test_student_cantview_upload_courses(self):

def test_user_with_canupload_canview_upload_courses(self):
self.assert_can_view('oppia_upload', TEACHER_USER)
############ Bulk upload users view #############

# Bulk upload users view

def test_anon_cantview_bulk_upload(self):
self.assert_must_login('profile_upload')
Expand All @@ -90,7 +91,8 @@ def test_staff_cantview_bulk_upload(self):

def test_student_cantview_bulk_upload(self):
self.assert_unauthorized('profile_upload', NORMAL_USER)
############ View cohort list #############

# View cohort list

def test_anon_cantview_cohorts(self):
self.assert_must_login('oppia_cohorts')
Expand All @@ -105,45 +107,60 @@ def test_student_cantview_cohorts(self):
self.assert_unauthorized('oppia_cohorts', NORMAL_USER)
# TODO: Define a teacher user to test cohort management

############ View a cohort ################
# View a cohort

def test_anon_cantview_cohort(self):
self.assert_must_login('oppia_cohort_view', view_kwargs={'cohort_id': 1})
self.assert_must_login('oppia_cohort_view',
view_kwargs={'cohort_id': 1})

def test_view_nonexisting_cohort(self):
self.assert_not_found('oppia_cohort_view', ADMIN_USER, view_kwargs={'cohort_id': 1000})
self.assert_not_found('oppia_cohort_view',
ADMIN_USER,
view_kwargs={'cohort_id': 1000})

def test_admin_canview_cohort(self):
self.assert_can_view('oppia_cohort_view', ADMIN_USER, view_kwargs={'cohort_id': 1})
self.assert_can_view('oppia_cohort_view',
ADMIN_USER,
view_kwargs={'cohort_id': 1})

def test_staff_canview_cohort(self):
self.assert_can_view('oppia_cohort_view', STAFF_USER, view_kwargs={'cohort_id': 1})
self.assert_can_view('oppia_cohort_view',
STAFF_USER,
view_kwargs={'cohort_id': 1})

def test_student_cantview_cohort(self):
self.assert_unauthorized('oppia_cohort_view', NORMAL_USER, view_kwargs={'cohort_id': 1})
self.assert_unauthorized('oppia_cohort_view',
NORMAL_USER,
view_kwargs={'cohort_id': 1})
# TODO: Teacher view cohort s/he is assigned into

############ View a cohort course activity ################
# View a cohort course activity

def test_anon_cantview_cohort_course(self):
self.assert_must_login('oppia_cohort_course_view', view_kwargs={'cohort_id': 1, 'course_id': 1})
self.assert_must_login('oppia_cohort_course_view',
view_kwargs={'cohort_id': 1, 'course_id': 1})

def test_view_nonexisting_cohort_course(self):
self.assert_not_found('oppia_cohort_course_view', ADMIN_USER,
view_kwargs={'cohort_id': 1000, 'course_id': 1000})
view_kwargs={'cohort_id': 1000,
'course_id': 1000})

def test_admin_canview_cohort_course(self):
self.assert_can_view('oppia_cohort_course_view', ADMIN_USER, view_kwargs={'cohort_id': 1, 'course_id': 1})
self.assert_can_view('oppia_cohort_course_view',
ADMIN_USER,
view_kwargs={'cohort_id': 1, 'course_id': 1})

def test_staff_canview_cohort_course(self):
self.assert_can_view('oppia_cohort_course_view', STAFF_USER, view_kwargs={'cohort_id': 1, 'course_id': 1})
self.assert_can_view('oppia_cohort_course_view',
STAFF_USER,
view_kwargs={'cohort_id': 1, 'course_id': 1})

def test_student_cantview_cohort_course(self):
self.assert_unauthorized('oppia_cohort_course_view', NORMAL_USER,
view_kwargs={'cohort_id': 1, 'course_id': 1})
# TODO: Teacher view cohort s/he is assigned into

############ Add new cohort #############
# Add new cohort

def test_anon_cantview_add_cohort(self):
self.assert_must_login('oppia_cohort_add')
Expand All @@ -156,7 +173,8 @@ def test_staff_canview_add_cohort(self):

def test_student_cantview_add_cohort(self):
self.assert_unauthorized('oppia_cohort_add', NORMAL_USER)
############ courses list view #############

# courses list view

def test_anon_cantview_courses_list(self):
self.assert_must_login('oppia_course')
Expand All @@ -175,72 +193,99 @@ def test_student_cantview_courses_list(self):
res = self.assert_can_view('oppia_course', NORMAL_USER)
# check that the number of courses dont include the draft ones
self.assertEqual(res.context['page'].paginator.count, 2)
############ View course recent activity #############

# View course recent activity

def test_anon_cantview_course_activity(self):
self.assert_must_login('oppia_recent_activity', view_kwargs={'course_id': 1})
self.assert_must_login('oppia_recent_activity',
view_kwargs={'course_id': 1})

def test_view_nonexisting_course_activity(self):
self.assert_not_found('oppia_recent_activity', ADMIN_USER, view_kwargs={'course_id': 1000})
self.assert_not_found('oppia_recent_activity',
ADMIN_USER,
view_kwargs={'course_id': 1000})

def test_admin_canview_course_activity(self):
self.assert_can_view('oppia_recent_activity', ADMIN_USER, view_kwargs={'course_id': 1})
self.assert_can_view('oppia_recent_activity',
ADMIN_USER,
view_kwargs={'course_id': 1})

def test_staff_canview_course_activity(self):
self.assert_can_view('oppia_recent_activity', STAFF_USER, view_kwargs={'course_id': 1})
self.assert_can_view('oppia_recent_activity',
STAFF_USER,
view_kwargs={'course_id': 1})

def test_student_canview_course_activity(self):
self.assert_unauthorized('oppia_recent_activity', NORMAL_USER, view_kwargs={'course_id': 1})
self.assert_unauthorized('oppia_recent_activity',
NORMAL_USER,
view_kwargs={'course_id': 1})
# TODO: Teacher view course activity for courses assigned to

############ View student activity (all activity) #####
# View student activity (all activity)

def test_anon_cantview_user_activity(self):
self.assert_must_login('profile_user_activity', view_kwargs={'user_id': 1})
self.assert_must_login('profile_user_activity',
view_kwargs={'user_id': 1})

def test_view_nonexisting_user_activity(self):
self.assert_not_found('profile_user_activity', ADMIN_USER, view_kwargs={'user_id': 1000})
self.assert_not_found('profile_user_activity',
ADMIN_USER,
view_kwargs={'user_id': 1000})

def test_admin_canview_user_activity(self):
self.assert_can_view('profile_user_activity', ADMIN_USER, view_kwargs={'user_id': 1})
self.assert_can_view('profile_user_activity',
ADMIN_USER,
view_kwargs={'user_id': 1})

def test_staff_canview_user_activity(self):
self.assert_can_view('profile_user_activity', STAFF_USER, view_kwargs={'user_id': 1})
self.assert_can_view('profile_user_activity',
STAFF_USER,
view_kwargs={'user_id': 1})

def test_student_cantview_user_activity(self):
self.assert_unauthorized('profile_user_activity', NORMAL_USER, view_kwargs={'user_id': 1})
self.assert_unauthorized('profile_user_activity',
NORMAL_USER,
view_kwargs={'user_id': 1})

def test_student_canview_self_activity(self):
self.assert_can_view('profile_user_activity', NORMAL_USER, view_kwargs={'user_id': 2})
self.assert_can_view('profile_user_activity',
NORMAL_USER,
view_kwargs={'user_id': 2})
# @TODO: Teacher view user activity of a user in a cohort he is assigned

############ View student activity (for a course) #####
# View student activity (for a course)

def test_anon_cantview_user_course_activity(self):
self.assert_must_login('profile_user_course_activity', view_kwargs={'course_id': 1, 'user_id': 1})
self.assert_must_login('profile_user_course_activity',
view_kwargs={'course_id': 1, 'user_id': 1})

def test_view_nonexisting_user_course_activity(self):
self.assert_not_found('profile_user_course_activity', ADMIN_USER,
view_kwargs={'course_id': 1000, 'user_id': 1000})
view_kwargs={'course_id': 1000,
'user_id': 1000})

def test_admin_canview_user_course_activity(self):
self.assert_can_view('profile_user_course_activity', ADMIN_USER,
self.assert_can_view('profile_user_course_activity',
ADMIN_USER,
view_kwargs={'course_id': 1, 'user_id': 1})

def test_staff_canview_user_course_activity(self):
self.assert_can_view('profile_user_course_activity', STAFF_USER,
self.assert_can_view('profile_user_course_activity',
STAFF_USER,
view_kwargs={'course_id': 1, 'user_id': 1})

def test_student_cantview_user_course_activity(self):
self.assert_unauthorized('profile_user_course_activity', NORMAL_USER,
self.assert_unauthorized('profile_user_course_activity',
NORMAL_USER,
view_kwargs={'course_id': 1, 'user_id': 1})

def test_student_canview_self_course_activity(self):
self.assert_can_view('profile_user_course_activity', NORMAL_USER,
self.assert_can_view('profile_user_course_activity',
NORMAL_USER,
view_kwargs={'course_id': 1, 'user_id': 2})
# TODO: Teacher view user activity of a user in a cohort he is assigned

############ analytics summary overview #############
# analytics summary overview

def test_anon_cantview_summary_overview(self):
self.assert_must_login('oppia_viz_summary')
Expand All @@ -252,6 +297,7 @@ def test_staff_canview_summary_overview(self):
self.assert_can_view('oppia_viz_summary', STAFF_USER)

def test_student_cantview_summary_overview(self):
self.client.login(username=NORMAL_USER['user'], password=NORMAL_USER['password'])
self.client.login(username=NORMAL_USER['user'],
password=NORMAL_USER['password'])
response = self.client.get(reverse('oppia_viz_summary'))
self.assertEqual(response.status_code, 302)

0 comments on commit 02a3b02

Please sign in to comment.