def test_course_change_view_get(self): """ The admin change view should include the editable and readonly fields as expected. In particular, the relation fields should only include options for related objects in their draft version. """ user = UserFactory(is_staff=True, is_superuser=True) self.client.login(username=user.username, password="******") # Create a course course = CourseFactory() # Create an organization and publish it organization = OrganizationFactory() organization.extended_object.publish("en") organization.refresh_from_db() # Create a subject and publish it subject = SubjectFactory() subject.extended_object.publish("en") subject.refresh_from_db() # Get the admin change view url = reverse("admin:courses_course_change", args=[course.id]) response = self.client.get(url) # Check that the page includes all our fields self.assertContains( response, course.extended_object.get_title(), status_code=200 ) self.assertContains(response, course.active_session) self.assertContains( response, course.organization_main.extended_object.get_title() ) # Only the draft organization and subject should be proposed as options in select boxes self.assertContains( response, '<option value="{:d}">{!s}'.format(subject.id, subject) ) self.assertNotContains( response, '<option value="{:d}">{!s}'.format( subject.public_extension.id, subject.public_extension ), ) self.assertContains( response, '<option value="{:d}">{!s}'.format(organization.id, organization) ) self.assertNotContains( response, '<option value="{:d}">{!s}'.format( organization.public_extension.id, organization.public_extension ), )
def test_cms_plugins_subject_render_on_public_page(self): """ The subject plugin should render as expected on a public page. """ # Create a filer fake image image = FilerImageFactory() # Create a Subject subject = SubjectFactory(page_title={ "en": "public title", "fr": "titre publique" }) subject_page = subject.extended_object # Add logo to related placeholder logo_placeholder = subject_page.placeholders.get(slot="logo") add_plugin( logo_placeholder, PicturePlugin, "en", **{ "picture": image, "attributes": { "alt": "logo description" } }) add_plugin( logo_placeholder, PicturePlugin, "fr", **{ "picture": image, "attributes": { "alt": "description du logo" } }) # Create a page to add the plugin to page = create_i18n_page({"en": "A page", "fr": "Une page"}) placeholder = page.placeholders.get(slot="maincontent") add_plugin(placeholder, SubjectPlugin, "en", **{"page": subject_page}) add_plugin(placeholder, SubjectPlugin, "fr", **{"page": subject_page}) subject_page.publish("en") subject_page.publish("fr") subject.refresh_from_db() page.publish("en") page.publish("fr") url = page.get_absolute_url(language="en") # The subject plugin should not be visible on the public page before it is published subject_page.unpublish("en") response = self.client.get(url) self.assertNotContains(response, "public title") # Republish the plugin subject_page.publish("en") # Now modify the subject to have a draft different from the public version title_obj = subject_page.get_title_obj(language="en") title_obj.tile = "draft title" title_obj.save() # Publishing the page again should make the plugin public page.publish("en") # Check the page content in English response = self.client.get(url) # Subject's title should be present as a link to the cms page # And CMS page title should be in title attribute of the link self.assertContains( response, '<a class="subject-plugin__body" href="/en/public-title/" title="{title:s}"' .format( title=subject.public_extension.extended_object.get_title()), status_code=200, ) # The subject's title should be wrapped in a div self.assertContains( response, '<div class="subject-plugin__title">{:s}</div>'.format( subject.public_extension.extended_object.get_title()), html=True, ) self.assertNotContains(response, "draft title") # Subject's logo should be present # pylint: disable=no-member self.assertContains(response, image.file.name) # Same checks in French url = page.get_absolute_url(language="fr") response = self.client.get(url) self.assertContains( response, '<a class="subject-plugin__body" href="/fr/titre-publique/" title="{title:s}"' .format( title=subject.public_extension.extended_object.get_title()), status_code=200, ) # pylint: disable=no-member self.assertContains(response, image.file.name)