def prepare_data_with_new_responsable(): organisation_request = OrganisationRequestFactory( manager=ManagerFactory(is_aidant=False)) for _ in range(2): AidantRequestFactory(organisation=organisation_request) organisation_request.save() return organisation_request
def test_type_other_correctly_set_constraint(self): OrganisationRequestFactory(type_id=RequestOriginConstants.CCAS.value, type_other="") with self.assertRaises(IntegrityError) as cm: OrganisationRequestFactory( type_id=RequestOriginConstants.OTHER.value, type_other="") self.assertIn("type_other_correctly_set", str(cm.exception))
def prepare_data_for_org_with_type_other(): organisation_request = OrganisationRequestFactory( type_id=RequestOriginConstants.OTHER.value, type_other="My other type value", ) for _ in range(3): AidantRequestFactory(organisation=organisation_request) organisation_request.save() return organisation_request
def prepare_data_with_existing_aidant_responsable(): organisation_request = OrganisationRequestFactory( manager=ManagerFactory(is_aidant=False, email="*****@*****.**")) AidantFactory(username="******", can_create_mandats=True) for _ in range(2): AidantRequestFactory(organisation=organisation_request) organisation_request.save() return organisation_request
def test_no_redirect_on_confirmed_organisation_request(self): organisation = OrganisationRequestFactory( status=RequestStatusConstants.AC_VALIDATION_PROCESSING.name ) response = self.client.get(organisation.get_absolute_url()) self.assertEqual(response.status_code, 200) self.assertContains(response, organisation.name) self.assertContains( response, RequestStatusConstants.AC_VALIDATION_PROCESSING.value )
def test_issuer_can_post_a_message(self): organisation = OrganisationRequestFactory( status=RequestStatusConstants.AC_VALIDATION_PROCESSING.name ) response = self.client.get(organisation.get_absolute_url()) self.assertNotContains(response, "Bonjour bonjour") self.client.post( organisation.get_absolute_url(), {"content": "Bonjour bonjour"} ) response = self.client.get(organisation.get_absolute_url()) self.assertContains(response, "Bonjour bonjour")
def test_correct_message_is_shown_when_empty_messages_history(self): organisation = OrganisationRequestFactory( status=RequestStatusConstants.AC_VALIDATION_PROCESSING.name ) response = self.client.get(organisation.get_absolute_url()) self.assertContains(response, "Notre conversation démarre ici.") self.client.post( organisation.get_absolute_url(), {"content": "Bonjour bonjour"} ) response = self.client.get(organisation.get_absolute_url()) self.assertNotContains(response, "Notre conversation démarre ici.")
def prepare_data_with_existing_responsable(): organisation_request = OrganisationRequestFactory() # existing manager AidantFactory( email=organisation_request.manager.email, username=organisation_request.manager.email, can_create_mandats=False, ) for _ in range(3): AidantRequestFactory(organisation=organisation_request) organisation_request.save() return organisation_request
def prepare_data(): OrganisationFactory(data_pass_id=67245456, ) organisation_request = OrganisationRequestFactory( status=RequestStatusConstants.AC_VALIDATION_PROCESSING.name, data_pass_id=67245456, ) organisation_request.manager.is_aidant = True organisation_request.manager.save() for _ in range(3): AidantRequestFactory(organisation=organisation_request) organisation_request.save() return organisation_request
def test_redirects_on_unauthorized_request_status(self): unauthorized_statuses = set(RequestStatusConstants.values()) - { RequestStatusConstants.NEW.name, RequestStatusConstants.AC_VALIDATION_PROCESSING.name, RequestStatusConstants.VALIDATED.name, } for i, status in enumerate(unauthorized_statuses): organisation: OrganisationRequest = OrganisationRequestFactory( status=status ) response = self.client.get( self.__get_url(organisation.issuer.issuer_id, organisation.uuid) ) self.assertRedirects( response, self.__get_redirect_url( organisation.issuer.issuer_id, organisation.uuid ), ) messages = list(django_messages.get_messages(response.wsgi_request)) self.assertEqual(len(messages), i + 1) self.assertEqual( messages[i].message, "Il n'est pas possible d'ajouter de nouveaux aidants à cette demande.", )
def setUpTestData(cls): cls.client = Client() cls.pattern_name = "habilitation_organisation_view" cls.template_name = "view_organisation_request.html" cls.issuer = IssuerFactory() cls.organisation: OrganisationRequest = OrganisationRequestFactory( issuer=cls.issuer )
def test_add_aidant_button_shown_in_readonly_view_under_correct_conditions( self): authorized_statuses = { RequestStatusConstants.NEW.name, RequestStatusConstants.AC_VALIDATION_PROCESSING.name, RequestStatusConstants.VALIDATED.name, } unauthorized_statuses = (set(RequestStatusConstants.values()) - authorized_statuses) for status in unauthorized_statuses: organisation: OrganisationRequest = OrganisationRequestFactory( status=status) self.__open_readonly_view_url(organisation) self.selenium.find_element(By.CSS_SELECTOR, ".fr-container") previous_timeout = self.selenium.timeouts.implicit_wait # Change timeout for finding elements to shorten the test self.selenium.implicitly_wait(0.2) with self.assertRaises(NoSuchElementException): self.selenium.find_element(By.CSS_SELECTOR, "#add-aidants-btn") self.selenium.implicitly_wait(previous_timeout) for status in authorized_statuses: organisation: OrganisationRequest = OrganisationRequestFactory( status=status) self.__open_readonly_view_url(organisation) self.selenium.find_element(By.CSS_SELECTOR, "#add-aidants-btn").click() path = reverse( "habilitation_organisation_modify", kwargs={ "issuer_id": str(organisation.issuer.issuer_id), "uuid": str(organisation.uuid), }, ) WebDriverWait(self.selenium, 10).until(url_matches(f"^.+{path}$"))
def test_submitted_organisation_request_is_displayed_without_links(self): organisation = OrganisationRequestFactory( issuer=self.issuer, status=RequestStatusConstants.AC_VALIDATION_PROCESSING.name, ) response = self.client.get(self.get_url(self.issuer.issuer_id)) self.assertNotContains(response, RequestStatusConstants.NEW.value) self.assertContains( response, RequestStatusConstants.AC_VALIDATION_PROCESSING.value ) self.assertNotContains(response, "Soumettre la demande") self.assertContains(response, organisation.name)
def test_redirect_on_unverified_issuer_email(self): unverified_issuer: Issuer = IssuerFactory(email_verified=False) organisation = OrganisationRequestFactory(issuer=unverified_issuer) response = self.client.get( self.get_url(unverified_issuer.issuer_id, organisation.uuid) ) self.assertRedirects( response, reverse( "habilitation_issuer_email_confirmation_waiting", kwargs={"issuer_id": unverified_issuer.issuer_id}, ), )
def test_redirect_on_confirmed_organisation_request(self): organisation = OrganisationRequestFactory( status=RequestStatusConstants.AC_VALIDATION_PROCESSING.name ) response = self.client.get( self.get_url(organisation.issuer.issuer_id, organisation.uuid) ) self.assertRedirects( response, reverse( "habilitation_organisation_view", kwargs={ "issuer_id": organisation.issuer.issuer_id, "uuid": organisation.uuid, }, ), )
def test_404_on_bad_issuer_id(self): issuer_id = uuid4() organisation: OrganisationRequest = OrganisationRequestFactory() response: HttpResponse = self.client.get( self.get_url(issuer_id, organisation.uuid) ) self.assertEqual(response.status_code, 404) uuid = uuid4() cleaned_data = utils.get_form(OrganisationRequestForm).clean() response = self.client.post( self.get_url(organisation.issuer.issuer_id, uuid), cleaned_data, ) self.assertEqual(response.status_code, 404)
def test_send_default_email(self): self.assertEqual(len(mail.outbox), 0) # this is supposed to one email: org_request = OrganisationRequestFactory( status=RequestStatusConstants.VALIDATED.name, data_pass_id=67245456, ) for _ in range(3): AidantRequestFactory(organisation=org_request) # this is supposed to send another email: self.org_request_admin.send_acceptance_email(org_request) # so here we expect 2 emails here in outbox: self.assertEqual(len(mail.outbox), 2) acceptance_message = mail.outbox[1] # check subject and email contents self.assertIn(str(org_request.data_pass_id), acceptance_message.subject) self.assertTrue( all( str(aidant) in acceptance_message.body for aidant in org_request.aidant_requests.all() ) ) # check recipients are as expected self.assertEqual( len(acceptance_message.recipients()), 5 ) # 3 aidants + 1 issuer + 1 manager self.assertTrue( all( aidant.email in acceptance_message.recipients() for aidant in org_request.aidant_requests.all() ) ) self.assertTrue(org_request.manager.email in acceptance_message.recipients()) self.assertTrue(org_request.issuer.email in acceptance_message.recipients())
def test_send_email_with_custom_body_and_subject(self): self.assertEqual(len(mail.outbox), 0) # this is supposed to one email: org_request = OrganisationRequestFactory( status=RequestStatusConstants.VALIDATED.name, data_pass_id=67245456, ) for _ in range(3): AidantRequestFactory(organisation=org_request) # this is supposed to send another email: email_body = "Corps du mail iaculis, scelerisque felis non, rutrum purus." email_subject = "Objet du mail consequat nisl sed viverra laoreet." self.org_request_admin.send_acceptance_email( org_request, email_body, email_subject ) # so here we expect 2 emails here in outbox: self.assertEqual(len(mail.outbox), 2) acceptance_message = mail.outbox[1] # check subject and email contents self.assertEqual(email_subject, acceptance_message.subject) self.assertEqual(email_body, acceptance_message.body) # check recipients are as expected self.assertEqual( len(acceptance_message.recipients()), 5 ) # 3 aidants + 1 issuer + 1 manager self.assertTrue( all( aidant.email in acceptance_message.recipients() for aidant in org_request.aidant_requests.all() ) ) self.assertTrue(org_request.manager.email in acceptance_message.recipients()) self.assertTrue(org_request.issuer.email in acceptance_message.recipients())
def test_can_correctly_add_new_aidants(self): organisation: OrganisationRequest = OrganisationRequestFactory( status=RequestStatusConstants.NEW.name, post__aidants_count=2) self.assertEqual(organisation.aidant_requests.count(), 2) self.__open_form_url(organisation) for i in range(2): aidant_form: AidantRequestForm = get_form(AidantRequestForm) aidant_data = aidant_form.cleaned_data for field_name in aidant_form.fields: element = self.selenium.find_element( By.CSS_SELECTOR, f"#id_form-{i}-{field_name}", ) element.clear() element.send_keys(aidant_data[field_name]) self.selenium.find_element(By.CSS_SELECTOR, "#add-aidant-btn").click() self.selenium.find_element(By.CSS_SELECTOR, '[type="submit"]').click() path = reverse( "habilitation_organisation_view", kwargs={ "issuer_id": str(organisation.issuer.issuer_id), "uuid": str(organisation.uuid), }, ) WebDriverWait(self.selenium, 10).until(url_matches(f"^.+{path}$")) organisation.refresh_from_db() self.assertEqual(organisation.aidant_requests.count(), 4)
def test_professionals_only_checked_constraint(self): with self.assertRaises(IntegrityError) as cm: OrganisationRequestFactory(professionals_only=False) self.assertIn("professionals_only_checked", str(cm.exception))
def test_without_elected_checked_constraint(self): with self.assertRaises(IntegrityError) as cm: OrganisationRequestFactory(without_elected=False) self.assertIn("without_elected_checked", str(cm.exception))
def test_manager_set_constraint(self): with self.assertRaises(IntegrityError) as cm: OrganisationRequestFactory(manager=None) self.assertIn("manager_set", str(cm.exception))
def prepare_data_for_nominal_case(): organisation_request = OrganisationRequestFactory() for _ in range(3): AidantRequestFactory(organisation=organisation_request) organisation_request.save() return organisation_request
def test_metier_user_can_see_manager(self): org_request = OrganisationRequestFactory() url_root = f"admin:{OrganisationRequest._meta.app_label}_{OrganisationRequest.__name__.lower()}" # noqa url = reverse(url_root + "_change", args=(org_request.pk,)) response = self.amac_client.get(url) self.assertContains(response, "<h2>Responsable</h2>")