Revert "Merge pull request #4545 from edx/renzo/bi-analytics-overhaul"

This reverts commit 252038c376, reversing
changes made to 7caf8c53b1.
This commit is contained in:
Julia Hansbrough
2014-07-29 17:41:46 +00:00
parent 4353e1e48f
commit 079808ee47
26 changed files with 58 additions and 244 deletions

View File

@@ -1,44 +0,0 @@
"""
Tests for instructor.basic
"""
from django.test import TestCase
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from instructor_analytics.basic import enrolled_students_features, AVAILABLE_FEATURES, STUDENT_FEATURES, PROFILE_FEATURES
class TestAnalyticsBasic(TestCase):
""" Test basic analytics functions. """
def setUp(self):
self.course_key = SlashSeparatedCourseKey('robot', 'course', 'id')
self.users = tuple(UserFactory() for _ in xrange(30))
self.ces = tuple(CourseEnrollment.enroll(user, self.course_key)
for user in self.users)
def test_enrolled_students_features_username(self):
self.assertIn('username', AVAILABLE_FEATURES)
userreports = enrolled_students_features(self.course_key, ['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_key, 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))

View File

@@ -1,124 +0,0 @@
""" Tests for analytics.csvs """
from django.test import TestCase
from nose.tools import raises
from instructor_analytics.csvs import create_csv_response, format_dictlist, format_instances
class TestAnalyticsCSVS(TestCase):
""" Test analytics rendering of csv files."""
def test_create_csv_response_nodata(self):
header = ['Name', 'Email']
datarows = []
res = create_csv_response('robot.csv', header, datarows)
self.assertEqual(res['Content-Type'], 'text/csv')
self.assertEqual(res['Content-Disposition'], 'attachment; filename={0}'.format('robot.csv'))
self.assertEqual(res.content.strip(), '"Name","Email"')
def test_create_csv_response(self):
header = ['Name', 'Email']
datarows = [['Jim', 'jim@edy.org'], ['Jake', 'jake@edy.org'], ['Jeeves', 'jeeves@edy.org']]
res = create_csv_response('robot.csv', header, datarows)
self.assertEqual(res['Content-Type'], 'text/csv')
self.assertEqual(res['Content-Disposition'], 'attachment; filename={0}'.format('robot.csv'))
self.assertEqual(res.content.strip(), '"Name","Email"\r\n"Jim","jim@edy.org"\r\n"Jake","jake@edy.org"\r\n"Jeeves","jeeves@edy.org"')
def test_create_csv_response_empty(self):
header = []
datarows = []
res = create_csv_response('robot.csv', header, datarows)
self.assertEqual(res['Content-Type'], 'text/csv')
self.assertEqual(res['Content-Disposition'], 'attachment; filename={0}'.format('robot.csv'))
self.assertEqual(res.content.strip(), '')
class TestAnalyticsFormatDictlist(TestCase):
""" Test format_dictlist method """
def test_format_dictlist(self):
dictlist = [
{
'label1': 'value-1,1',
'label2': 'value-1,2',
'label3': 'value-1,3',
'label4': 'value-1,4',
},
{
'label1': 'value-2,1',
'label2': 'value-2,2',
'label3': 'value-2,3',
'label4': 'value-2,4',
}
]
features = ['label1', 'label4']
header, datarows = format_dictlist(dictlist, features)
ideal_header = ['label1', 'label4']
ideal_datarows = [['value-1,1', 'value-1,4'],
['value-2,1', 'value-2,4']]
self.assertEqual(header, ideal_header)
self.assertEqual(datarows, ideal_datarows)
def test_format_dictlist_empty(self):
header, datarows = format_dictlist([], [])
self.assertEqual(header, [])
self.assertEqual(datarows, [])
def test_create_csv_response(self):
header = ['Name', 'Email']
datarows = [['Jim', 'jim@edy.org'], ['Jake', 'jake@edy.org'], ['Jeeves', 'jeeves@edy.org']]
res = create_csv_response('robot.csv', header, datarows)
self.assertEqual(res['Content-Type'], 'text/csv')
self.assertEqual(res['Content-Disposition'], 'attachment; filename={0}'.format('robot.csv'))
self.assertEqual(res.content.strip(), '"Name","Email"\r\n"Jim","jim@edy.org"\r\n"Jake","jake@edy.org"\r\n"Jeeves","jeeves@edy.org"')
class TestAnalyticsFormatInstances(TestCase):
""" test format_instances method """
class TestDataClass(object):
""" Test class to generate objects for format_instances """
def __init__(self):
self.a_var = 'aval'
self.b_var = 'bval'
self.c_var = 'cval'
@property
def d_var(self):
""" accessor to see if they work too """
return 'dval'
def setUp(self):
self.instances = [self.TestDataClass() for _ in xrange(5)]
def test_format_instances_response(self):
features = ['a_var', 'c_var', 'd_var']
header, datarows = format_instances(self.instances, features)
self.assertEqual(header, ['a_var', 'c_var', 'd_var'])
self.assertEqual(datarows, [[
'aval',
'cval',
'dval',
] for _ in xrange(len(self.instances))])
def test_format_instances_response_noinstances(self):
features = ['a_var']
header, datarows = format_instances([], features)
self.assertEqual(header, features)
self.assertEqual(datarows, [])
def test_format_instances_response_nofeatures(self):
header, datarows = format_instances(self.instances, [])
self.assertEqual(header, [])
self.assertEqual(datarows, [[] for _ in xrange(len(self.instances))])
@raises(AttributeError)
def test_format_instances_response_nonexistantfeature(self):
format_instances(self.instances, ['robot_not_a_real_feature'])

View File

@@ -1,93 +0,0 @@
""" Tests for analytics.distributions """
from django.test import TestCase
from nose.tools import raises
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from instructor_analytics.distributions import profile_distribution, AVAILABLE_PROFILE_FEATURES
class TestAnalyticsDistributions(TestCase):
'''Test analytics distribution gathering.'''
def setUp(self):
self.course_id = SlashSeparatedCourseKey('robot', 'course', 'id')
self.users = [UserFactory(
profile__gender=['m', 'f', 'o'][i % 3],
profile__year_of_birth=i + 1930
) for i in xrange(30)]
self.ces = [CourseEnrollment.enroll(user, self.course_id)
for user in self.users]
@raises(ValueError)
def test_profile_distribution_bad_feature(self):
feature = 'robot-not-a-real-feature'
self.assertNotIn(feature, AVAILABLE_PROFILE_FEATURES)
profile_distribution(self.course_id, feature)
def test_profile_distribution_easy_choice(self):
feature = 'gender'
self.assertIn(feature, AVAILABLE_PROFILE_FEATURES)
distribution = profile_distribution(self.course_id, feature)
self.assertEqual(distribution.type, 'EASY_CHOICE')
self.assertEqual(distribution.data['no_data'], 0)
self.assertEqual(distribution.data['m'], len(self.users) / 3)
self.assertEqual(distribution.choices_display_names['m'], 'Male')
def test_profile_distribution_open_choice(self):
feature = 'year_of_birth'
self.assertIn(feature, AVAILABLE_PROFILE_FEATURES)
distribution = profile_distribution(self.course_id, feature)
print distribution
self.assertEqual(distribution.type, 'OPEN_CHOICE')
self.assertTrue(hasattr(distribution, 'choices_display_names'))
self.assertEqual(distribution.choices_display_names, None)
self.assertNotIn('no_data', distribution.data)
self.assertEqual(distribution.data[1930], 1)
class TestAnalyticsDistributionsNoData(TestCase):
'''Test analytics distribution gathering.'''
def setUp(self):
self.course_id = SlashSeparatedCourseKey('robot', 'course', 'id')
self.users = [UserFactory(
profile__year_of_birth=i + 1930,
) for i in xrange(5)]
self.nodata_users = [UserFactory(
profile__year_of_birth=None,
profile__gender=[None, ''][i % 2]
) for i in xrange(4)]
self.users += self.nodata_users
self.ces = tuple(CourseEnrollment.enroll(user, self.course_id)
for user in self.users)
def test_profile_distribution_easy_choice_nodata(self):
feature = 'gender'
self.assertIn(feature, AVAILABLE_PROFILE_FEATURES)
distribution = profile_distribution(self.course_id, feature)
print distribution
self.assertEqual(distribution.type, 'EASY_CHOICE')
self.assertTrue(hasattr(distribution, 'choices_display_names'))
self.assertNotEqual(distribution.choices_display_names, None)
self.assertIn('no_data', distribution.data)
self.assertEqual(distribution.data['no_data'], len(self.nodata_users))
def test_profile_distribution_open_choice_nodata(self):
feature = 'year_of_birth'
self.assertIn(feature, AVAILABLE_PROFILE_FEATURES)
distribution = profile_distribution(self.course_id, feature)
print distribution
self.assertEqual(distribution.type, 'OPEN_CHOICE')
self.assertTrue(hasattr(distribution, 'choices_display_names'))
self.assertEqual(distribution.choices_display_names, None)
self.assertIn('no_data', distribution.data)
self.assertEqual(distribution.data['no_data'], len(self.nodata_users))