def test_program_details(self, use_org_name, credential_title): """ Verify the method returns the details of program associated with the ProgramCertificate. """ program_certificate = ProgramCertificateFactory(site=self.site, use_org_name=use_org_name, title=credential_title) program_uuid = program_certificate.program_uuid.hex courses = [ {'key': 'ACMEx/101x'}, {'key': 'FakeX/101x'}, ] expected = ProgramDetails( uuid=program_uuid, title='Test Program', subtitle='Test Subtitle', type='MicroFakers', credential_title=credential_title, course_count=len(courses), organizations=[ OrganizationDetails( uuid=uuid.uuid4().hex, key='ACMEx', name='ACME University', display_name='ACME University' if use_org_name else 'ACMEx', certificate_logo_image_url='http://example.com/acme.jpg' ), OrganizationDetails( uuid=uuid.uuid4().hex, key='FakeX', name='Fake University', display_name='Fake University' if use_org_name else 'FakeX', certificate_logo_image_url='http://example.com/fakex.jpg' ) ], hours_of_effort=None ) body = { 'uuid': expected.uuid, 'title': expected.title, 'subtitle': expected.subtitle, 'type': expected.type, 'authoring_organizations': [ { 'uuid': organization.uuid, 'key': organization.key, 'name': organization.name, 'certificate_logo_image_url': organization.certificate_logo_image_url, } for organization in expected.organizations ], 'courses': courses } with mock.patch.object(SiteConfiguration, 'get_program', return_value=body) as mock_method: self.assertEqual(program_certificate.program_details, expected) mock_method.assert_called_with(program_certificate.program_uuid)
def get_context_data(self, **kwargs): program_type = self.request.GET.get('program_type', 'Professional Certificate') context = super(ExampleCredential, self).get_context_data(**kwargs) program_details = ProgramDetails( uuid=uuid.uuid4(), title='Completely Example Program', subtitle='Example Subtitle', type=program_type, course_count=3, organizations=[ OrganizationDetails( uuid=uuid.uuid4(), key='ExampleX', name='Example University', display_name='Absolutely Fake University', certificate_logo_image_url='https://placehold.it/204x204') ], hours_of_effort=None) context.update({ 'user_credential': { 'modified': timezone.now(), 'uuid': uuid.uuid4(), 'credential': { 'program_uuid': uuid.uuid4(), 'signatories': { # NOTE (CCB): This is a small hack to workaround the fact that the template expects a QuerySet. 'all': [{ 'name': 'Pseudo McFakerson', 'title': 'Professor...really just Some Guy', 'organization_name_override': 'Parts Unknown', 'image': { 'url': 'https://placehold.it/720x280' } }] }, 'program_details': program_details, }, }, 'user_data': { 'name': 'John Doe', }, 'child_templates': { 'credential': self.select_theme_template([ 'credentials/programs/{type}/certificate.html'.format( type=slugify(program_type)) ]), 'footer': self.select_theme_template(['_footer.html']), 'header': self.select_theme_template(['_header.html']), }, 'page_title': program_details.type, 'program_name': program_details.title, 'render_language': settings.LANGUAGE_CODE, }) return context
def get_context_data(self, **kwargs): context = super(ExampleCredential, self).get_context_data(**kwargs) context.update({ 'user_credential': { 'modified': timezone.now(), 'uuid': uuid.uuid4(), 'credential': { 'signatories': { # NOTE (CCB): This is a small hack to workaround the fact that the template expects a QuerySet. 'all': [{ 'name': 'Pseudo McFakerson', 'title': 'Professor...really just Some Guy', 'organization_name_override': 'Parts Unknown', 'image': { 'url': 'http://placehold.it/720x280' } }] }, } }, 'certificate_context': { 'credential_type': 'Demo Certificate', 'credential_title': 'Completely Example Program', 'user_data': { 'name': 'John Doe', }, 'program_details': ProgramDetails( uuid=uuid.uuid4(), title='Completely Example Program', type='Fake', course_count=3, organizations=[ OrganizationDetails( uuid=uuid.uuid4(), key='ExampleX', name='Example University', display_name='Absolutely Fake University', logo_image_url='http://placehold.it/204x204') ]), 'credential_template': 'credentials/program_certificate.html', }, }) return context
def test_program_details(self, use_org_name): """ Verify the method returns the details of program associated with the ProgramCertificate. """ program_certificate = ProgramCertificateFactory( site=self.site, use_org_name=use_org_name) program_uuid = program_certificate.program_uuid.hex courses = [ { 'key': 'ACMEx/101x' }, { 'key': 'FakeX/101x' }, ] expected = ProgramDetails( uuid=program_uuid, title='Test Program', type='MicroFakers', course_count=len(courses), organizations=[ OrganizationDetails( uuid=uuid.uuid4().hex, key='ACMEx', name='ACME University', display_name='ACME University' if use_org_name else 'ACMEx', logo_image_url='http://example.com/acme.jpg'), OrganizationDetails( uuid=uuid.uuid4().hex, key='FakeX', name='Fake University', display_name='Fake University' if use_org_name else 'FakeX', logo_image_url='http://example.com/fakex.jpg') ]) program_endpoint = 'programs/{uuid}/'.format(uuid=program_uuid) body = { 'uuid': expected.uuid, 'title': expected.title, 'type': expected.type, 'authoring_organizations': [{ 'uuid': organization.uuid, 'key': organization.key, 'name': organization.name, 'logo_image_url': organization.logo_image_url, } for organization in expected.organizations], 'courses': courses } self.mock_access_token_response() self.mock_catalog_api_response(program_endpoint, body) self.assertEqual(program_certificate.program_details, expected)