def test_models_person_get_full_name(self): """ The get_full_name method should return title, first name and last name separated by space. No SQL query should be generated. """ person1 = PersonFactory( first_name="Louise", last_name="Dupont", person_title__translation__title="Madam", person_title__translation__abbreviation="Mme", ) person2 = PersonFactory(first_name="Jacques", last_name="Martin", person_title=None) with self.assertNumQueries(1): self.assertEqual(person1.get_full_name(), "Madam Louise Dupont") self.assertEqual(person2.get_full_name(), "Jacques Martin")
def test_models_person_get_full_name(self): """ The get_full_name method should return title, first name and last name separated by space. No SQL query should be generated. """ person_title = PersonTitleFactory(title="Madam", abbreviation="Mme") person = PersonFactory( first_name="Louise", last_name="Dupont", person_title=person_title ) with self.assertNumQueries(0): self.assertEqual(person.get_full_name(), "Madam Louise Dupont")
def test_cms_plugins_person_form_page_choices(self): """ The form to create a person plugin should only list person pages in the select box. """ class PersonPluginModelForm(forms.ModelForm): """A form for testing the choices in the select box""" class Meta: model = PersonPluginModel exclude = () person = PersonFactory() other_page_title = "other page" create_page(other_page_title, "richie/fullwidth.html", settings.LANGUAGE_CODE) plugin_form = PersonPluginModelForm() self.assertIn(person.get_full_name(), plugin_form.as_table()) self.assertNotIn(other_page_title, plugin_form.as_table())
def test_cms_plugins_person_render(self): """ Test that a PersonPlugin correctly renders person's page specific information """ # Create a filer fake image staff = UserFactory(is_staff=True, is_superuser=True) image = FilerImageFactory(owner=staff) # Create a Person person = PersonFactory() 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" } }) # A resume to related placeholder resume_placeholder = person_page.placeholders.get(slot="resume") add_plugin(resume_placeholder, PlaintextPlugin, "en", **{"body": "A short resume"}) add_plugin(resume_placeholder, PlaintextPlugin, "fr", **{"body": "Un résumé court"}) # 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", **{"person": person}) add_plugin(placeholder, PersonPlugin, "fr", **{"person": person}) page.publish("en") page.publish("fr") # Check the page content in English url = page.get_absolute_url(language="en") 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="{url}" title="{page_title}">'.format( url=person_page.get_absolute_url(), page_title=person_page.get_title()), status_code=200, ) self.assertContains(response, person.get_full_name(), html=True) # 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">A short resume</div>', html=True, ) # The person's full name should be wrapped in a h2 self.assertContains( response, '<h2 class="person-plugin__content__title">{:s}</h2>'.format( person.get_full_name()), html=True, ) # Same checks in French url = page.get_absolute_url(language="fr") response = self.client.get(url) self.assertContains( response, '<a href="{url}" title="{page_title}">'.format( url=person_page.get_absolute_url(), page_title=person_page.get_title()), status_code=200, ) # pylint: disable=no-member self.assertContains(response, image.file.name) self.assertContains( response, '<div class="person-plugin__content__text">Un résumé court</div>', html=True, )