def test_admin_person_change_view_post(self): """ Validate that the person can be updated via the admin. """ user = UserFactory(is_staff=True, is_superuser=True) self.client.login(username=user.username, password="******") # Create a person, title will automaticaly be created person = PersonFactory() # create a new title new_title = PersonTitleFactory() # Get the admin change view url = reverse("admin:persons_person_change", args=[person.id]) data = { "person_title": new_title.id, "first_name": "New First Name", "last_name": "New Last Name", } response = self.client.post(url, data) self.assertEqual(response.status_code, 302) # Check that the person was updated as expected person.refresh_from_db() self.assertEqual(person.person_title, new_title) self.assertEqual(person.first_name, "New First Name") self.assertEqual(person.last_name, "New Last Name")
def test_cms_plugins_person_render_on_public_page(self): """ The person plugin should render as expected on a public page. """ # Create a filer fake image image = FilerImageFactory() # Create a Person person = PersonFactory( page_title={"en": "person title", "fr": "titre personne"}, first_name="Meimei", ) person_page = person.extended_object # Add portrait to related placeholder portrait_placeholder = person_page.placeholders.get(slot="portrait") add_plugin( portrait_placeholder, PicturePlugin, "en", **{"picture": image, "attributes": {"alt": "portrait description"}} ) add_plugin( portrait_placeholder, PicturePlugin, "fr", **{"picture": image, "attributes": {"alt": "description du portrait"}} ) # Add resume to related placeholder resume_placeholder = person_page.placeholders.get(slot="resume") resume_en = add_plugin( resume_placeholder, PlainTextPlugin, "en", **{"body": "public resume"} ) add_plugin( resume_placeholder, PlainTextPlugin, "fr", **{"body": "résumé public"} ) # 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, PersonPlugin, "en", **{"page": person.extended_object}) add_plugin(placeholder, PersonPlugin, "fr", **{"page": person.extended_object}) person_page.publish("en") person_page.publish("fr") person.refresh_from_db() page.publish("en") page.publish("fr") url = page.get_absolute_url(language="en") # The person plugin should not be visible on the public page before it is published person_page.unpublish("en") response = self.client.get(url) self.assertNotContains(response, "Meimei") # Republishing the plugin should not make it public person_page.publish("en") response = self.client.get(url) self.assertNotContains(response, "Meimei") # Now modify the person to have a draft different from the public version person.first_name = "Jiji" person.save() resume_en.body = "draft resume" resume_en.save() # Publishing the page again should make the plugin public page.publish("en") # Check the page content in English response = self.client.get(url) # Person's name 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 href="/en/person-title/" title="{name:s}">'.format( name=person.public_extension.get_full_name() ), status_code=200, ) # The person's full name should be wrapped in a h2 self.assertContains( response, '<h2 class="person-plugin__content__title">{:s}</h2>'.format( person.public_extension.get_full_name() ), html=True, ) self.assertContains(response, "Meimei") self.assertNotContains(response, "Jiji") # Person's portrait and its properties should be present # pylint: disable=no-member self.assertContains(response, image.file.name) # Short resume should be present self.assertContains( response, '<div class="person-plugin__content__text">public resume</div>', html=True, ) self.assertNotContains(response, "draft resume") # Same checks in French url = page.get_absolute_url(language="fr") response = self.client.get(url) self.assertContains( response, '<a href="/fr/titre-personne/" title="{name:s}">'.format( name=person.public_extension.get_full_name() ), status_code=200, ) # pylint: disable=no-member self.assertContains(response, image.file.name) self.assertContains( response, '<div class="person-plugin__content__text">résumé public</div>', html=True, )