def test_get_course_organization_multi_linked_orgs(self): """ Test that when a course is linked to multiple organizations, ``get_course_organization`` and ``get_course_organization_id`` return the first-linked one. """ # Use non-alphabetically-ordered org names to test that the # returned org was the first *linked*, not just the first *alphabetically*. api.add_organization_course( api.add_organization({ 'short_name': 'orgW', 'name': 'Org West' }), self.test_course_key, ) api.add_organization_course( api.add_organization({ 'short_name': 'orgN', 'name': 'Org North' }), self.test_course_key, ) api.add_organization_course( api.add_organization({ 'short_name': 'orgS', 'name': 'Org South' }), self.test_course_key, ) org_result = api.get_course_organization(self.test_course_key) assert org_result['short_name'] == 'orgW' org_id_result = api.get_course_organization_id(self.test_course_key) assert org_id_result assert org_id_result == org_result['id']
def test_get_course_organization_no_linked_orgs(self): """ Test that when a course is linked to no organizations, ``get_course_organization`` and ``get_course_organization_id`` return None. """ assert api.get_course_organization(self.test_course_key) is None assert api.get_course_organization_id(self.test_course_key) is None
def get_certificate_template(course_key, mode, language): """ Retrieves the custom certificate template based on course_key, mode, and language. """ template = None # fetch organization of the course org_id = get_course_organization_id(course_key) # only consider active templates active_templates = CertificateTemplate.objects.filter(is_active=True) if org_id and mode: # get template by org, mode, and key org_mode_and_key_templates = active_templates.filter( organization_id=org_id, mode=mode, course_key=course_key ) template = get_language_specific_template_or_default(language, org_mode_and_key_templates) # since no template matched that course_key, only consider templates with empty course_key empty_course_key_templates = active_templates.filter(course_key=CourseKeyField.Empty) if not template and org_id and mode: # get template by org and mode org_and_mode_templates = empty_course_key_templates.filter( organization_id=org_id, mode=mode ) template = get_language_specific_template_or_default(language, org_and_mode_templates) if not template and org_id: # get template by only org org_templates = empty_course_key_templates.filter( organization_id=org_id, mode=None ) template = get_language_specific_template_or_default(language, org_templates) if not template and mode: # get template by only mode mode_templates = empty_course_key_templates.filter( organization_id=None, mode=mode ) template = get_language_specific_template_or_default(language, mode_templates) return template if template else None