Beispiel #1
0
    def test_use_autorisation_without_preloging(self):
        url = f"/authorize/?{FC_URL_PARAMETERS}"
        self.open_live_url(url)

        login_aidant(self)

        self.use_a_autorisation()
    def test_search_feature(self):
        self.open_live_url("/usagers/")
        login_aidant(self)

        user_with_valid_mandate = self.selenium.find_elements(
            By.CSS_SELECTOR, ".table.with-valid-mandate tbody tr")

        user_without_valid_mandate = self.selenium.find_elements(
            By.CSS_SELECTOR, ".table.without-valid-mandate tbody tr")

        self.assertEqual(len(user_with_valid_mandate), 2)
        self.assertEqual(len(user_without_valid_mandate), 1)

        self.selenium.find_element(By.ID, "filter-input").send_keys("Anne")

        anne_result = self.selenium.find_element(
            By.XPATH, "//*[normalize-space()='Anne Cécile Gertrude']")
        josephine_result = self.selenium.find_element(
            By.XPATH, "//*[normalize-space()='Joséphine']")
        corentin_result = self.selenium.find_element(
            By.XPATH, "//*[normalize-space()='Corentin']")

        self.assertTrue(anne_result.is_displayed())
        self.assertFalse(josephine_result.is_displayed())
        self.assertTrue(corentin_result.is_displayed())
Beispiel #3
0
    def test_search_feature(self):
        self.open_live_url(f"/authorize/?{self.url_parameters}")
        login_aidant(self)

        users = self.selenium.find_elements(By.CSS_SELECTOR,
                                            "#usagers .usager")

        self.assertEqual(len(users), 3)

        self.selenium.find_element(By.ID, "filter-input").send_keys("Anne")

        anne_result = self.selenium.find_element(
            By.XPATH, "//*[contains(text(), 'Anne Cécile Gertrude EVALOUS')]")
        josephine_result = self.selenium.find_element(
            By.XPATH, "//*[contains(text(), 'Joséphine ST-PIERRE')]")
        corentin_result = self.selenium.find_element(
            By.XPATH, "//*[contains(text(), 'Corentin Anne')]")

        self.assertTrue(anne_result.is_displayed())
        self.assertFalse(josephine_result.is_displayed())
        self.assertTrue(corentin_result.is_displayed())

        wait = WebDriverWait(self.selenium, 10)

        corentin_result.click()

        wait.until(url_contains("/select_demarche/?connection_id="))
Beispiel #4
0
    def test_use_autorisation_with_preloging(self):
        # prelogin
        self.open_live_url("/espace-aidant/")
        login_aidant(self)

        url = f"/authorize/?{FC_URL_PARAMETERS}"
        self.open_live_url(url)

        self.use_a_autorisation()
Beispiel #5
0
    def test_cancel_autorisation_of_active_mandat(self):
        self.open_live_url(f"/usagers/{self.usager_josephine.id}/")

        login_aidant(self)

        # See all mandats of usager page
        active_mandats_before = self.selenium.find_elements_by_id(
            "active-mandat-panel")
        self.assertEqual(len(active_mandats_before), 1)
        active_mandats_autorisations_before = self.selenium.find_elements_by_id(
            "active-mandat-autorisation-row")
        self.assertEqual(len(active_mandats_autorisations_before), 2)

        # Cancel first autorisation
        cancel_mandat_autorisation_button = active_mandats_autorisations_before[
            0].find_element_by_tag_name("a")
        cancel_mandat_autorisation_button.click()

        # Confirm cancellation
        submit_button = self.selenium.find_elements_by_tag_name("input")[1]
        submit_button.click()

        # See again all mandats of usager page
        active_autorisations_after = self.selenium.find_elements_by_id(
            "active-mandat-panel")
        self.assertEqual(len(active_autorisations_after), 1)
        active_mandats_autorisations_after = self.selenium.find_elements_by_id(
            "active-mandat-autorisation-row")
        self.assertEqual(len(active_mandats_autorisations_after), 2)
        self.assertIn("Révoqué", active_mandats_autorisations_after[0].text)

        # Check Journal
        last_journal_entry = Journal.objects.last()
        self.assertEqual(last_journal_entry.action, "cancel_autorisation")

        # Cancel second autorisation
        cancel_mandat_autorisation_button = active_mandats_autorisations_after[
            1].find_element_by_tag_name("a")
        cancel_mandat_autorisation_button.click()

        # Confirm cancellation
        submit_button = self.selenium.find_elements_by_tag_name("input")[1]
        submit_button.click()

        # See again all mandats of usager page
        active_autorisations_after = self.selenium.find_elements_by_id(
            "active-mandat-panel")
        self.assertEqual(len(active_autorisations_after), 0)
        inactive_autorisations_after = self.selenium.find_elements_by_id(
            "inactive-mandat-panel")
        self.assertEqual(len(inactive_autorisations_after), 1)
        inactive_mandats_autorisations_after = self.selenium.find_elements_by_id(
            "inactive-mandat-autorisation-row")
        self.assertEqual(len(inactive_mandats_autorisations_after), 2)
        self.assertIn("Révoqué", inactive_mandats_autorisations_after[0].text)
        self.assertIn("Révoqué", inactive_mandats_autorisations_after[1].text)
    def test_grouped_mandats(self):
        self.selenium.get(f"{self.live_server_url}/dashboard/")

        # Login
        login_aidant(self)

        # Dashboard
        self.selenium.find_element_by_id("view_mandats").click()

        # Mandat List
        self.assertEqual(
            len(self.selenium.find_elements_by_class_name("fake-table-row")),
            2)
    def test_grouped_autorisations(self):
        self.open_live_url("/espace-aidant/")

        # Login
        login_aidant(self)

        # Espace Aidant home
        self.selenium.find_element_by_id("view_mandats").click()

        # autorisation List
        self.assertEqual(
            len(
                self.selenium.find_element_by_tag_name(
                    "table").find_elements_by_css_selector("tbody tr")),
            2,
        )
    def test_grouped_autorisations(self):
        self.open_live_url("/espace-aidant/")

        # Login
        login_aidant(self)

        # Espace Aidant home
        self.selenium.find_element(By.ID, "view_mandats").click()

        results = []
        for el in self.selenium.find_elements(By.TAG_NAME, "table"):
            for tr in el.find_elements(By.CSS_SELECTOR, "tbody tr"):
                results.append(tr)

        # autorisation List
        self.assertEqual(len(results), 3)
    def test_create_new_mandat(self):
        wait = WebDriverWait(self.selenium, 10)

        self.open_live_url("/usagers/")

        login_aidant(self)

        welcome_aidant = self.selenium.find_element(By.TAG_NAME, "h1").text
        self.assertEqual(welcome_aidant, "Vos usagères et usagers")

        usagers_before = self.selenium.find_elements(By.TAG_NAME, "tr")
        self.assertEqual(len(usagers_before), 0)

        # Create new mandat
        add_usager_button = self.selenium.find_element(By.ID, "add_usager")
        add_usager_button.click()

        demarches_section = self.selenium.find_element(By.ID, "demarches")
        demarche_title = demarches_section.find_element(By.TAG_NAME, "h2").text
        self.assertEqual(demarche_title, "Étape 1 : Sélectionnez la ou les démarche(s)")

        demarches_grid = self.selenium.find_element(By.ID, "demarches_list")
        demarches = demarches_grid.find_elements(By.TAG_NAME, "input")
        self.assertEqual(len(demarches), 10)

        demarches_section.find_element(By.ID, "argent").find_element(
            By.TAG_NAME, "label"
        ).click()
        demarches_section.find_element(By.ID, "famille").find_element(
            By.TAG_NAME, "label"
        ).click()

        duree_section = self.selenium.find_element(By.ID, "duree")
        duree_section.find_element(By.ID, "SHORT").find_element(
            By.TAG_NAME, "label"
        ).click()

        # FranceConnect
        fc_button = self.selenium.find_element(By.ID, "submit_button")
        fc_button.click()
        fc_title = self.selenium.title
        self.assertEqual("Connexion - choix du compte", fc_title)
        time.sleep(2)

        # Nouvelle mire dialog
        if len(self.selenium.find_elements(By.ID, "message-on-login")) > 0:
            temp_test_nouvelle_mire_masquer = self.selenium.find_element(
                By.ID, "message-on-login-close"
            )
            temp_test_nouvelle_mire_masquer.click()

        # Click on the 'Démonstration' identity provider
        demonstration_hex = self.selenium.find_element(
            By.ID, "fi-identity-provider-example"
        )
        demonstration_hex.click()
        time.sleep(2)

        # FC - Use the Mélaine_trois credentials
        demo_title = self.selenium.find_element(By.TAG_NAME, "h3").text
        self.assertEqual(demo_title, "Fournisseur d'identité de démonstration")
        submit_button = self.selenium.find_elements(By.TAG_NAME, "input")[2]
        self.assertEqual(submit_button.get_attribute("type"), "submit")
        submit_button.click()
        wait.until(url_matches(r"https://.+franceconnect\.fr/api/v1/authorize.+"))

        # FC - Validate the information
        submit_button = self.selenium.find_element(By.TAG_NAME, "button")
        submit_button.click()
        time.sleep(2)

        # Recap all the information for the Mandat
        recap_title = self.selenium.find_element(By.TAG_NAME, "h1").text
        self.assertEqual(recap_title, "Récapitulatif du mandat")
        recap_text = self.selenium.find_element(By.ID, "recap_text").text
        self.assertIn("Angela Claire Louise DUBOIS ", recap_text)
        checkboxes = self.selenium.find_elements(By.TAG_NAME, "input")
        id_personal_data = checkboxes[1]
        self.assertEqual(id_personal_data.get_attribute("id"), "id_personal_data")
        id_personal_data.click()
        id_otp_token = checkboxes[2]
        self.assertEqual(id_otp_token.get_attribute("id"), "id_otp_token")
        id_otp_token.send_keys("123455")
        submit_button = checkboxes[-1]
        self.assertEqual(submit_button.get_attribute("type"), "submit")
        submit_button.click()

        # Success page
        success_title = self.selenium.find_element(By.TAG_NAME, "h1").text
        self.assertEqual(success_title, "Le mandat a été créé avec succès !")
        go_to_usager_button = self.selenium.find_element(
            By.CLASS_NAME, "tiles"
        ).find_elements(By.TAG_NAME, "a")[1]
        go_to_usager_button.click()

        # See all mandats of usager page
        active_mandats_after = self.selenium.find_elements(By.TAG_NAME, "table")[
            0
        ].find_elements(By.CSS_SELECTOR, "tbody tr")
        self.assertEqual(len(active_mandats_after), 2)
Beispiel #10
0
    def test_cancel_autorisation_of_active_mandat(self):
        self.open_live_url(f"/usagers/{self.mandat.usager.id}/")

        login_aidant(self)

        # See all mandats of usager page
        active_mandats = self.selenium.find_elements(By.ID, "active-mandat-panel")
        self.assertEqual(len(active_mandats), 1)

        # Cancel mandat
        cancel_mandat_button = self.selenium.find_element(By.ID, "cancel_mandat")
        cancel_mandat_button.click()

        remaining_autorisations = [
            it.text
            for it in self.selenium.find_elements(
                By.CSS_SELECTOR, ".remaining-autorisations strong"
            )
        ]
        self.assertEqual(
            remaining_autorisations,
            [
                "ARGENT: Crédit immobilier, Impôts, Consommation, "
                "Livret A, Assurance, Surendettement…",
                "FAMILLE: Allocations familiales, Naissance, Mariage, Pacs, Scolarité…",
            ],
        )

        # Confirm cancellation
        submit_button = self.selenium.find_elements(By.TAG_NAME, "input")[1]
        submit_button.click()

        # Display attestation
        attestation_link = self.selenium.find_element(
            By.XPATH,
            f'.//a[@href="/mandats/{self.mandat.id}/attestation_de_revocation"]',
        )
        attestation_link.click()

        wait = WebDriverWait(self.selenium, 10)
        wait.until(lambda driver: len(driver.window_handles) == 2)
        self.selenium.switch_to.window(self.selenium.window_handles[1])

        recap_title = self.selenium.find_element(By.TAG_NAME, "h1").text
        self.assertEqual(
            recap_title, "Révocation d'un mandat via le service « Aidants Connect »"
        )

        self.selenium.close()
        self.selenium.switch_to.window(self.selenium.window_handles[0])

        # See again all mandats of usager page

        user_link = self.selenium.find_element(
            By.XPATH, f'.//a[@href="/usagers/{self.mandat.usager.id}/"]'
        )
        user_link.click()

        inactive_mandats = self.selenium.find_elements(By.ID, "inactive-mandat-panel")
        self.assertEqual(len(inactive_mandats), 1)
        inactive_mandats_autorisations_after = self.selenium.find_elements(
            By.CLASS_NAME, "inactive-mandat-autorisation-row"
        )
        self.assertEqual(len(inactive_mandats_autorisations_after), 2)
        self.assertIn("Révoqué", inactive_mandats_autorisations_after[0].text)

        # Check Journal
        last_journal_entry = Journal.objects.last()
        self.assertEqual(last_journal_entry.action, "cancel_mandat")
Beispiel #11
0
    def test_create_new_mandat(self):
        login_aidant(self)

        welcome_aidant = self.selenium.find_element_by_tag_name("h1").text
        self.assertEqual(welcome_aidant, "Vos mandats")

        self.assertEqual(
            len(self.selenium.find_elements_by_class_name("fake-table-row")),
            0)

        # Create new mandat
        add_usager_button = self.selenium.find_element_by_id("add_usager")
        add_usager_button.click()

        demarches_section = self.selenium.find_element_by_id("demarches")
        demarche_title = demarches_section.find_element_by_tag_name("h2").text
        self.assertEqual(demarche_title,
                         "Étape 1 : Sélectionnez la ou les démarche(s)")

        demarches_grid = self.selenium.find_element_by_id("demarches_list")
        demarches = demarches_grid.find_elements_by_tag_name("input")
        self.assertEqual(len(demarches), 10)

        demarches_section.find_element_by_id(
            "argent").find_element_by_tag_name("label").click()
        demarches_section.find_element_by_id(
            "famille").find_element_by_tag_name("label").click()

        duree_section = self.selenium.find_element_by_id("duree")
        duree_section.find_element_by_id("long").find_element_by_tag_name(
            "label").click()

        # FranceConnect
        fc_button = self.selenium.find_element_by_id("submit_button")
        fc_button.click()
        fc_title = self.selenium.title
        self.assertEqual("Connexion - choix du compte", fc_title)
        time.sleep(2)

        # Click on the 'Démonstration' identity provider
        demonstration_hex = self.selenium.find_element_by_id(
            "fi-identity-provider-example")
        demonstration_hex.click()
        time.sleep(2)

        # FC - Use the Mélaine_trois credentials
        demo_title = self.selenium.find_element_by_tag_name("h3").text
        self.assertEqual(demo_title, "Fournisseur d'identité de démonstration")
        submit_button = self.selenium.find_elements_by_tag_name("input")[2]
        self.assertEqual(submit_button.get_attribute("type"), "submit")
        submit_button.click()

        # FC - Validate the information
        submit_button = self.selenium.find_element_by_tag_name("input")
        submit_button.click()
        time.sleep(2)

        # Recap all the information for the Mandat
        recap_title = self.selenium.find_element_by_tag_name("h1").text
        self.assertEqual(recap_title, "Récapitulatif du mandat")
        recap_text = self.selenium.find_element_by_id("recap_text").text
        self.assertIn("Angela Claire Louise DUBOIS ", recap_text)
        checkboxes = self.selenium.find_elements_by_tag_name("input")
        id_personal_data = checkboxes[2]
        self.assertEqual(id_personal_data.get_attribute("id"),
                         "id_personal_data")
        id_personal_data.click()
        id_brief = checkboxes[3]
        self.assertEqual(id_brief.get_attribute("id"), "id_brief")
        id_brief.click()
        id_otp_token = checkboxes[4]
        self.assertEqual(id_otp_token.get_attribute("id"), "id_otp_token")
        id_otp_token.send_keys("123456")
        submit_button = checkboxes[-1]
        self.assertEqual(submit_button.get_attribute("type"), "submit")
        submit_button.click()
        time.sleep(4)

        # back to dashboard
        self.assertEqual(welcome_aidant, "Vos mandats")
        self.selenium.find_element_by_id("view_mandats").click()

        # See all mandats page
        self.assertEqual(
            len(self.selenium.find_elements_by_class_name("fake-table-row")),
            1)

        # Select user
        user_link = self.selenium.find_elements_by_class_name(
            "fake-table-row")[0].find_element_by_tag_name("a")
        user_link.click()

        # See all mandats of usager page
        # Should find 3 table rows: 1 header row + 2 mandat rows
        self.assertEqual(len(self.selenium.find_elements_by_tag_name("tr")), 3)
    def test_cancel_autorisation_of_active_mandat(self):
        self.open_live_url(f"/usagers/{self.usager_josephine.id}/")

        login_aidant(self)

        # See all mandats of usager page
        active_mandats_before = self.selenium.find_elements(
            By.ID, "active-mandat-panel"
        )
        self.assertEqual(len(active_mandats_before), 1)
        active_mandats_autorisations_before = self.selenium.find_elements(
            By.CLASS_NAME, "active-mandat-autorisation-row"
        )
        self.assertEqual(len(active_mandats_autorisations_before), 2)

        # Cancel first autorisation
        cancel_mandat_autorisation_button = active_mandats_autorisations_before[
            0
        ].find_element(By.TAG_NAME, "a")
        cancel_mandat_autorisation_button.click()

        # Confirm cancellation
        submit_button = self.selenium.find_elements(By.TAG_NAME, "input")[1]
        submit_button.click()

        # Display attestation
        attestation_link = self.selenium.find_element(
            By.XPATH,
            f'.//a[@href="/usagers/{self.usager_josephine.id}'
            f'/autorisations/{self.money_authorization.id}/cancel_attestation"]',
        )
        attestation_link.click()

        wait = WebDriverWait(self.selenium, 10)
        wait.until(lambda driver: len(driver.window_handles) == 2)
        self.selenium.switch_to.window(self.selenium.window_handles[1])

        recap_title = self.selenium.find_element(By.TAG_NAME, "h1").text
        self.assertEqual(
            recap_title,
            "Révocation d'une autorisation via le service « Aidants Connect »",
        )

        self.selenium.close()
        self.selenium.switch_to.window(self.selenium.window_handles[0])

        # See again all mandats of usager page
        user_link = self.selenium.find_element(
            By.XPATH, f'.//a[@href="/usagers/{self.usager_josephine.id}/"]'
        )
        user_link.click()

        active_autorisations_after = self.selenium.find_elements(
            By.ID, "active-mandat-panel"
        )
        self.assertEqual(len(active_autorisations_after), 1)

        active_mandats_autorisations_after = self.selenium.find_elements(
            By.CLASS_NAME, "active-mandat-autorisation-row"
        )
        revoked_mandat_autorisation_after = self.selenium.find_element(
            By.ID, f"active-mandat-autorisation-{self.money_authorization.demarche}"
        )

        self.assertEqual(len(active_mandats_autorisations_after), 2)
        self.assertIn("Révoqué", revoked_mandat_autorisation_after.text)

        auth_revocation_attestation_button = self.selenium.find_elements(
            By.CSS_SELECTOR, ".button.auth-revocation-attestation"
        )
        self.assertEqual(len(auth_revocation_attestation_button), 1)
        self.assertIn("Voir la révocation", auth_revocation_attestation_button[0].text)

        # Check Journal
        last_journal_entry = Journal.objects.last()
        self.assertEqual(last_journal_entry.action, "cancel_autorisation")

        # Cancel second autorisation
        cancel_mandat_autorisation_button = self.selenium.find_element(
            By.ID, f"active-mandat-autorisation-{self.family_authorization.demarche}"
        ).find_element(By.TAG_NAME, "a")
        cancel_mandat_autorisation_button.click()

        # Confirm cancellation
        submit_button = self.selenium.find_elements(By.TAG_NAME, "input")[1]
        submit_button.click()

        # See again all mandats of usager page
        user_link = self.selenium.find_element(
            By.XPATH, f'.//a[@href="/usagers/{self.usager_josephine.id}/"]'
        )
        user_link.click()

        active_autorisations_after = self.selenium.find_elements(
            By.ID, "active-mandat-panel"
        )
        self.assertEqual(len(active_autorisations_after), 0)
        inactive_autorisations_after = self.selenium.find_elements(
            By.ID, "inactive-mandat-panel"
        )
        self.assertEqual(len(inactive_autorisations_after), 1)
        inactive_mandats_autorisations_after = self.selenium.find_elements(
            By.CLASS_NAME, "inactive-mandat-autorisation-row"
        )
        self.assertEqual(len(inactive_mandats_autorisations_after), 2)
        self.assertIn("Révoqué", inactive_mandats_autorisations_after[0].text)
        self.assertIn("Révoqué", inactive_mandats_autorisations_after[1].text)
Beispiel #13
0
    def test_grouped_autorisations(self):
        wait = WebDriverWait(self.selenium, 10)
        root_path = self.__get_live_url(self.organisation.id)

        self.open_live_url(root_path)

        # Login
        login_aidant(self, self.aidant_responsable.email)
        wait.until(url_matches(f"^.+{root_path}$"))

        # Check button text
        button = self.selenium.find_element(
            By.ID,
            f"remove-aidant-{self.aidant_with_multiple_orgs.id}-from-organisation",
        )
        self.assertEqual(
            f"Retirer l'aidant de {self.organisation.name}",
            button.text,
        )

        button = self.selenium.find_element(
            By.ID,
            f"remove-aidant-{self.aidant_with_one_org.id}-from-organisation")
        self.assertEqual("Désactiver l'aidant", button.text)

        with self.assertRaises(NoSuchElementException):
            self.selenium.find_element(
                By.ID,
                f"remove-aidant-{self.aidant_responsable.id}-from-organisation"
            )

        # Let's try those btns shall we?
        button.click()
        path = reverse(
            "espace_responsable_remove_aidant_from_organisation",
            kwargs={
                "organisation_id": self.organisation.id,
                "aidant_id": self.aidant_with_one_org.id,
            },
        )
        wait.until(url_matches(f"^.+{path}$"))

        self.selenium.find_element(
            By.XPATH,
            "//button[@type='submit' and normalize-space(text())='Confirmer']"
        ).click()

        wait.until(url_matches(f"^.+{root_path}$"))

        with self.assertRaises(NoSuchElementException):
            self.selenium.find_element(
                By.ID,
                f"remove-aidant-{self.aidant_with_one_org.id}-from-organisation"
            )

        self.selenium.find_element(
            By.ID,
            f"remove-aidant-{self.aidant_with_multiple_orgs.id}-from-organisation",
        ).click()
        path = reverse(
            "espace_responsable_remove_aidant_from_organisation",
            kwargs={
                "organisation_id": self.organisation.id,
                "aidant_id": self.aidant_with_multiple_orgs.id,
            },
        )
        wait.until(url_matches(f"^.+{path}$"))

        self.selenium.find_element(
            By.XPATH,
            "//button[@type='submit' and normalize-space(text())='Confirmer']"
        ).click()

        wait.until(url_matches(f"^.+{root_path}$"))

        with self.assertRaises(NoSuchElementException):
            self.selenium.find_element(
                By.ID,
                f"remove-aidant-{self.aidant_with_multiple_orgs.id}-from-organisation",
            )

        pass
Beispiel #14
0
    def test_renew_mandat(self):
        self.aidant = AidantFactory(email="*****@*****.**")
        device = self.aidant.staticdevice_set.create(id=1)
        device.token_set.create(token="123456")
        device.token_set.create(token="123455")

        self.usager = UsagerFactory(given_name="Fabrice")
        MandatFactory(
            organisation=self.aidant.organisation,
            usager=self.usager,
            expiration_date=timezone.now() + timedelta(days=5),
        )
        self.assertEqual(Mandat.objects.filter(usager=self.usager).count(), 1)

        self.open_live_url(f"/renew_mandat/{self.usager.pk}")

        login_aidant(self)

        demarches_section = self.selenium.find_element(By.ID, "demarches")
        demarche_title = demarches_section.find_element(By.TAG_NAME, "h2").text
        self.assertEqual(demarche_title,
                         "Étape 1 : Sélectionnez la ou les démarche(s)")

        demarches_grid = self.selenium.find_element(By.ID, "demarches_list")
        demarches = demarches_grid.find_elements(By.TAG_NAME, "input")
        self.assertEqual(len(demarches), 10)

        demarches_section.find_element(By.ID, "argent").find_element(
            By.TAG_NAME, "label").click()
        demarches_section.find_element(By.ID, "famille").find_element(
            By.TAG_NAME, "label").click()

        duree_section = self.selenium.find_element(By.ID, "duree")
        duree_section.find_element(By.ID,
                                   "SHORT").find_element(By.TAG_NAME,
                                                         "label").click()

        # Renew Mandat
        fc_button = self.selenium.find_element(By.ID, "submit_renew_button")
        fc_button.click()

        # Recap all the information for the Mandat
        recap_title = self.selenium.find_element(By.TAG_NAME, "h1").text
        self.assertEqual(recap_title, "Récapitulatif du mandat")
        recap_text = self.selenium.find_element(By.ID, "recap_text").text
        self.assertIn("Fabrice Simpson ", recap_text)
        checkboxes = self.selenium.find_elements(By.TAG_NAME, "input")
        id_personal_data = checkboxes[1]
        self.assertEqual(id_personal_data.get_attribute("id"),
                         "id_personal_data")
        id_personal_data.click()
        id_otp_token = checkboxes[2]
        self.assertEqual(id_otp_token.get_attribute("id"), "id_otp_token")
        id_otp_token.send_keys("123455")
        submit_button = checkboxes[-1]
        self.assertEqual(submit_button.get_attribute("type"), "submit")
        submit_button.click()

        # Success page
        success_title = self.selenium.find_element(By.TAG_NAME, "h1").text
        self.assertEqual(success_title, "Le mandat a été créé avec succès !")
        go_to_usager_button = self.selenium.find_element(
            By.CLASS_NAME, "tiles").find_elements(By.TAG_NAME, "a")[1]
        go_to_usager_button.click()

        self.assertEqual(Mandat.objects.filter(usager=self.usager).count(), 2)
    def test_create_new_mandat(self):
        self.open_live_url("/usagers/")

        login_aidant(self)

        welcome_aidant = self.selenium.find_element_by_tag_name("h1").text
        self.assertEqual(welcome_aidant, "Vos mandats")

        usagers_before = self.selenium.find_elements_by_tag_name("tr")
        self.assertEqual(len(usagers_before), 0)

        # Create new mandat
        add_usager_button = self.selenium.find_element_by_id("add_usager")
        add_usager_button.click()

        demarches_section = self.selenium.find_element_by_id("demarches")
        demarche_title = demarches_section.find_element_by_tag_name("h2").text
        self.assertEqual(demarche_title,
                         "Étape 1 : Sélectionnez la ou les démarche(s)")

        demarches_grid = self.selenium.find_element_by_id("demarches_list")
        demarches = demarches_grid.find_elements_by_tag_name("input")
        self.assertEqual(len(demarches), 10)

        demarches_section.find_element_by_id(
            "argent").find_element_by_tag_name("label").click()
        demarches_section.find_element_by_id(
            "famille").find_element_by_tag_name("label").click()

        duree_section = self.selenium.find_element_by_id("duree")
        duree_section.find_element_by_id("SHORT").find_element_by_tag_name(
            "label").click()

        # FranceConnect
        fc_button = self.selenium.find_element_by_id("submit_button")
        fc_button.click()
        fc_title = self.selenium.title
        self.assertEqual("Connexion - choix du compte", fc_title)
        time.sleep(2)

        # Click on the 'Démonstration' identity provider
        demonstration_hex = self.selenium.find_element_by_id(
            "fi-identity-provider-example")
        demonstration_hex.click()
        time.sleep(2)

        # FC - Use the Mélaine_trois credentials
        demo_title = self.selenium.find_element_by_tag_name("h3").text
        self.assertEqual(demo_title, "Fournisseur d'identité de démonstration")
        submit_button = self.selenium.find_elements_by_tag_name("input")[2]
        self.assertEqual(submit_button.get_attribute("type"), "submit")
        submit_button.click()

        # FC - Validate the information
        submit_button = self.selenium.find_element_by_tag_name("button")
        submit_button.click()
        time.sleep(2)

        # Recap all the information for the Mandat
        recap_title = self.selenium.find_element_by_tag_name("h1").text
        self.assertEqual(recap_title, "Récapitulatif du mandat")
        recap_text = self.selenium.find_element_by_id("recap_text").text
        self.assertIn("Angela Claire Louise DUBOIS ", recap_text)
        checkboxes = self.selenium.find_elements_by_tag_name("input")
        id_personal_data = checkboxes[1]
        self.assertEqual(id_personal_data.get_attribute("id"),
                         "id_personal_data")
        id_personal_data.click()
        id_brief = checkboxes[2]
        self.assertEqual(id_brief.get_attribute("id"), "id_brief")
        id_brief.click()
        id_otp_token = checkboxes[3]
        self.assertEqual(id_otp_token.get_attribute("id"), "id_otp_token")
        id_otp_token.send_keys("123455")
        submit_button = checkboxes[-1]
        self.assertEqual(submit_button.get_attribute("type"), "submit")
        submit_button.click()

        # Success page
        success_title = self.selenium.find_element_by_tag_name("h1").text
        self.assertEqual(success_title, "Le mandat a été créé avec succès !")
        go_to_usager_button = self.selenium.find_element_by_class_name(
            "tiles").find_elements_by_tag_name("a")[1]
        go_to_usager_button.click()

        # See all mandats of usager page
        active_mandats_after = self.selenium.find_elements_by_tag_name(
            "table")[0].find_elements_by_css_selector("tbody tr")
        self.assertEqual(len(active_mandats_after), 2)