Features coming down the pipe will want to be able to: * Refer to enrollments before they are actually activated (approval step). * See what courses a user used to be enrolled in for when they re-enroll in the same course, or a different run of that course. * Have different "modes" of enrolling in a course, representing things like honor certificate enrollment, auditing (no certs), etc. This change adds an is_active flag and mode (with default being "honor"). The commit is only as large as it is because many parts of the codebase were manipulating enrollments by adding and removing CourseEnrollment objects directly. It was necessary to create classmethods on CourseEnrollment to encapsulate this functionality and then port everything over to using them. The migration to add columns has been tested on a prod replica, and seems to be fine for running on a live system with single digit millions of rows of enrollments.
44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
"""
|
|
Tests for instructor.basic
|
|
"""
|
|
|
|
from django.test import TestCase
|
|
from student.models import CourseEnrollment
|
|
from student.tests.factories import UserFactory
|
|
|
|
from analytics.basic import enrolled_students_features, AVAILABLE_FEATURES, STUDENT_FEATURES, PROFILE_FEATURES
|
|
|
|
|
|
class TestAnalyticsBasic(TestCase):
|
|
""" Test basic analytics functions. """
|
|
|
|
def setUp(self):
|
|
self.course_id = 'some/robot/course/id'
|
|
self.users = tuple(UserFactory() for _ in xrange(30))
|
|
self.ces = tuple(CourseEnrollment.enroll(user, self.course_id)
|
|
for user in self.users)
|
|
|
|
def test_enrolled_students_features_username(self):
|
|
self.assertIn('username', AVAILABLE_FEATURES)
|
|
userreports = enrolled_students_features(self.course_id, ['username'])
|
|
self.assertEqual(len(userreports), len(self.users))
|
|
for userreport in userreports:
|
|
self.assertEqual(userreport.keys(), ['username'])
|
|
self.assertIn(userreport['username'], [user.username for user in self.users])
|
|
|
|
def test_enrolled_students_features_keys(self):
|
|
query_features = ('username', 'name', 'email')
|
|
for feature in query_features:
|
|
self.assertIn(feature, AVAILABLE_FEATURES)
|
|
userreports = enrolled_students_features(self.course_id, query_features)
|
|
self.assertEqual(len(userreports), len(self.users))
|
|
for userreport in userreports:
|
|
self.assertEqual(set(userreport.keys()), set(query_features))
|
|
self.assertIn(userreport['username'], [user.username for user in self.users])
|
|
self.assertIn(userreport['email'], [user.email for user in self.users])
|
|
self.assertIn(userreport['name'], [user.profile.name for user in self.users])
|
|
|
|
def test_available_features(self):
|
|
self.assertEqual(len(AVAILABLE_FEATURES), len(STUDENT_FEATURES + PROFILE_FEATURES))
|
|
self.assertEqual(set(AVAILABLE_FEATURES), set(STUDENT_FEATURES + PROFILE_FEATURES))
|