Commit 1018ced0 by Clinton Blackburn

Merge pull request #6 from edx/ordering

Sorting data chronologically
parents 6fc3d10a ef3cbc51
......@@ -42,7 +42,7 @@ class BaseCourseEnrollment(models.Model):
class CourseEnrollmentDaily(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_daily'
ordering = ('-date', 'course')
ordering = ('date', 'course')
unique_together = [('course', 'date',)]
......@@ -51,7 +51,7 @@ class CourseEnrollmentByBirthYear(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_birth_year'
ordering = ('-date', 'birth_year', 'course')
ordering = ('date', 'course', 'birth_year')
unique_together = [('course', 'date', 'birth_year')]
......@@ -71,7 +71,7 @@ class CourseEnrollmentByEducation(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_education_level'
ordering = ('-date', 'education_level', 'course')
ordering = ('date', 'course', 'education_level')
unique_together = [('course', 'date', 'education_level')]
......@@ -80,7 +80,7 @@ class CourseEnrollmentByGender(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_gender'
ordering = ('-date', 'gender', 'course')
ordering = ('date', 'course', 'gender')
unique_together = [('course', 'date', 'gender')]
......@@ -120,5 +120,5 @@ class CourseEnrollmentByCountry(BaseCourseEnrollment):
class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_location'
ordering = ('-date', 'country', 'course')
ordering = ('date', 'course', 'country')
unique_together = [('course', 'date', 'country')]
......@@ -84,6 +84,7 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
class CourseEnrollmentViewTestCase(object):
model = None
path = None
order_by = []
def _get_non_existent_course_id(self):
course_id = random.randint(100, 9999)
......@@ -108,8 +109,8 @@ class CourseEnrollmentViewTestCase(object):
response = self.authenticated_get('/api/v0/courses/%s%s' % (self.course.course_id, self.path,))
self.assertEquals(response.status_code, 200)
# Validate the actual data
expected = self.get_expected_response(*self.model.objects.filter(date=self.date))
# Validate the data is correct and sorted chronologically
expected = self.get_expected_response(*self.model.objects.filter(date=self.date).order_by('date', *self.order_by)) # pylint: disable=line-too-long
self.assertEquals(response.data, expected)
def test_get_csv(self):
......@@ -167,6 +168,7 @@ class CourseEnrollmentViewTestCase(object):
class CourseEnrollmentByBirthYearViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase):
path = '/enrollment/birth_year'
model = models.CourseEnrollmentByBirthYear
order_by = ['birth_year']
@classmethod
def setUpClass(cls):
......@@ -197,6 +199,7 @@ class CourseEnrollmentByBirthYearViewTests(TestCaseWithAuthentication, CourseEnr
class CourseEnrollmentByEducationViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase):
path = '/enrollment/education/'
model = models.CourseEnrollmentByEducation
order_by = ['education_level']
@classmethod
def setUpClass(cls):
......@@ -219,6 +222,7 @@ class CourseEnrollmentByEducationViewTests(TestCaseWithAuthentication, CourseEnr
class CourseEnrollmentByGenderViewTests(TestCaseWithAuthentication, CourseEnrollmentViewTestCase):
path = '/enrollment/gender/'
model = models.CourseEnrollmentByGender
order_by = ['gender']
@classmethod
def setUpClass(cls):
......
......@@ -91,6 +91,8 @@ class CourseEnrollmentByBirthYearView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive)
......@@ -109,6 +111,8 @@ class CourseEnrollmentByEducationView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive)
......@@ -131,6 +135,8 @@ class CourseEnrollmentByGenderView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive)
......@@ -146,6 +152,8 @@ class CourseEnrollmentView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive)
......@@ -168,6 +176,8 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
If no start or end dates are passed, the data for the latest date is returned. All dates should are in the UTC zone.
Data is sorted chronologically (earliest to latest).
Date format: YYYY-mm-dd (e.g. 2014-01-31)
start_date -- Date after which all data should be returned (inclusive)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment