Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
EDUCATOR-570 Fix multi-course program grouping bug (#176)
Browse files Browse the repository at this point in the history
* Order CourseProgramMetadata by program_id

* Add programs tests for multi-course programs

* Fix linting errors

* Nevermind, just ignore it
  • Loading branch information
thallada authored Jul 6, 2017
1 parent 30c04bc commit 859d376
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion analytics_data_api/v0/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CourseProgramMetadata(BaseCourseModel):

class Meta(BaseCourseModel.Meta):
db_table = 'course_program_metadata'
ordering = ('course_id',)
ordering = ('program_id',)
unique_together = [('course_id', 'program_id',)]


Expand Down
51 changes: 47 additions & 4 deletions analytics_data_api/v0/tests/views/test_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,45 @@ def setUp(self):
def tearDown(self):
self.model.objects.all().delete()

def create_model(self, model_id):
G(self.model, course_id=self.course_id, program_id=model_id, program_type='Demo', program_title='Test')
def generate_data(self, ids=None, course_ids=None, **kwargs):
"""Generate program list data"""
if ids is None:
ids = self.default_ids

def expected_result(self, item_id):
if course_ids is None:
course_ids = [[self.course_id]] * len(ids)

for item_id, course_id in zip(ids, course_ids):
self.create_model(item_id, course_ids=course_id, **kwargs)

def create_model(self, model_id, course_ids=None, **kwargs):
if course_ids is None:
course_ids = [self.course_id]

for course_id in course_ids:
G(self.model, course_id=course_id, program_id=model_id, program_type='Demo', program_title='Test')

def all_expected_results(self, ids=None, course_ids=None, **kwargs):
if ids is None:
ids = self.default_ids

if course_ids is None:
course_ids = [[self.course_id]] * len(ids)

return [self.expected_result(item_id, course_ids=course_id, **kwargs)
for item_id, course_id in zip(ids, course_ids)]

# pylint: disable=arguments-differ
def expected_result(self, item_id, course_ids=None):
"""Expected program metadata to populate with data."""
if course_ids is None:
course_ids = [self.course_id]

program = super(ProgramsViewTests, self).expected_result(item_id)
program.update([
('program_type', 'Demo'),
('program_title', 'Test'),
('course_ids', [self.course_id])
('course_ids', course_ids)
])
return program

Expand All @@ -57,3 +86,17 @@ def test_one_course(self, program_id):
)
def test_fields(self, fields):
self._test_fields(fields)

@ddt.data(
(None, None),
(CourseSamples.program_ids, [[cid] for cid in CourseSamples.course_ids]),
(CourseSamples.program_ids, [CourseSamples.course_ids[1:3],
CourseSamples.course_ids[0:2],
CourseSamples.course_ids[0:3]]),
)
@ddt.unpack
def test_all_programs_multi_courses(self, program_ids, course_ids):
self.generate_data(ids=program_ids, course_ids=course_ids)
response = self.validated_request(ids=program_ids, exclude=self.always_exclude)
self.assertEquals(response.status_code, 200)
self.assertItemsEqual(response.data, self.all_expected_results(ids=program_ids, course_ids=course_ids))

0 comments on commit 859d376

Please sign in to comment.