def test_models_organization_get_persons_public_organization_page(self): """ When a organization is added on a draft person, the person should not be visible on the public organization page until the person is published. """ organization = OrganizationFactory(should_publish=True) organization_page = organization.extended_object person = PersonFactory(page_title="my title", should_publish=True) person_page = person.extended_object # Add a organization to the person but don't publish the modification placeholder = person_page.placeholders.get(slot="organizations") add_plugin(placeholder, OrganizationPlugin, "en", page=organization_page) self.assertEqual(list(organization.get_persons()), [person]) self.assertEqual(list(organization.public_extension.get_persons()), []) # Now publish the modification and check that the person is displayed # on the public organization page person.extended_object.publish("en") self.assertEqual(list(organization.public_extension.get_persons()), [person.public_extension]) # If the person is unpublished, it should not be displayed on the public # page anymore person_page.unpublish("en") self.assertEqual(list(organization.get_persons()), [person]) self.assertEqual(list(organization.public_extension.get_persons()), [])
def test_models_organization_get_persons_several_languages(self): """ The persons should not be duplicated if they exist in several languages. """ organization = OrganizationFactory(should_publish=True) PersonFactory( page_title={ "en": "my title", "fr": "mon titre" }, fill_organizations=[organization], should_publish=True, ) self.assertEqual(Person.objects.count(), 2) self.assertEqual(organization.get_persons().count(), 1)
def test_models_organization_get_persons(self): """ It should be possible to retrieve the list of related persons on the organization instance. The number of queries should be minimal. """ organization = OrganizationFactory(should_publish=True) persons = PersonFactory.create_batch( 2, page_title="my title", should_publish=True, fill_organizations=[organization], ) retrieved_persons = organization.get_persons() with self.assertNumQueries(2): self.assertEqual(set(retrieved_persons), set(persons)) with self.assertNumQueries(0): for person in retrieved_persons: self.assertEqual( person.extended_object.prefetched_titles[0].title, "my title")