def login_admin(self): self.aidant = AidantFactory( username="******", is_superuser=True, is_staff=True, ) self.aidant.set_password("laisser-passer-a38") self.aidant.save() device = self.aidant.staticdevice_set.create() device.token_set.create(token="123456") WebDriverWait(self.selenium, 10) self.open_live_url(self.login_url) login_field = self.selenium.find_element(By.ID, "id_username") login_field.send_keys("*****@*****.**") otp_field = self.selenium.find_element(By.ID, "id_otp_token") otp_field.send_keys("123456") pwd_field = self.selenium.find_element(By.ID, "id_password") pwd_field.send_keys("laisser-passer-a38") submit_button = self.selenium.find_element(By.XPATH, "//input[@type='submit']") submit_button.click() django_admin_title = self.selenium.find_element(By.TAG_NAME, "h1").text self.assertEqual(django_admin_title, "Administration de Django")
def setUpTestData(cls): cls.amac_user = AidantFactory( is_staff=True, is_superuser=False, ) cls.amac_user.set_password("password") cls.amac_user.save() amac_device = StaticDevice.objects.create(user=cls.amac_user, name="Device") cls.amac_client = Client() cls.amac_client.force_login(cls.amac_user) # we need do this : # https://docs.djangoproject.com/en/3.1/topics/testing/tools/#django.test.Client.session amac_session = cls.amac_client.session amac_session[DEVICE_ID_SESSION_KEY] = amac_device.persistent_id amac_session.save() cls.atac_user = AidantFactory( is_staff=True, is_superuser=True, ) cls.atac_user.set_password("password") cls.atac_user.save() atac_device = StaticDevice.objects.create(user=cls.atac_user, name="Device") cls.atac_client = Client() cls.atac_client.force_login(cls.atac_user) # we need do this : # https://docs.djangoproject.com/en/3.1/topics/testing/tools/#django.test.Client.session atac_session = cls.atac_client.session atac_session[DEVICE_ID_SESSION_KEY] = atac_device.persistent_id atac_session.save()
def setUp(self): self.aidant_thierry = AidantFactory(email="*****@*****.**") device = self.aidant_thierry.staticdevice_set.create(id=self.aidant_thierry.id) device.token_set.create(token="123456") self.aidant_jacqueline = AidantFactory() self.usager_josephine = UsagerFactory(given_name="Joséphine") self.mandat_thierry_josephine = MandatFactory( organisation=self.aidant_thierry.organisation, usager=self.usager_josephine, expiration_date=timezone.now() + timedelta(days=6), ) self.money_authorization = AutorisationFactory( mandat=self.mandat_thierry_josephine, demarche="argent", ) self.family_authorization = AutorisationFactory( mandat=self.mandat_thierry_josephine, demarche="famille", ) self.mandat_jacqueline_josephine = MandatFactory( organisation=self.aidant_jacqueline.organisation, usager=self.usager_josephine, expiration_date=timezone.now() + timedelta(days=12), ) AutorisationFactory( mandat=self.mandat_jacqueline_josephine, demarche="logement", )
def test_responsable_cannot_change_an_unrelated_organisation_on_their_aidants( self): responsable = self.responsable_of_2 respo_org_1, respo_org_2 = responsable.responsable_de.all() aidant = AidantFactory() aidant_initial_org = aidant.organisation aidant.organisations.add(respo_org_1) self.assertIn(aidant_initial_org, aidant.organisations.all()) self.assertIn(respo_org_1, aidant.organisations.all()) self.assertEqual(len(aidant.organisations.all()), 2) self.client.force_login(responsable) self.client.post( self.get_form_url(aidant), {"organisations": [respo_org_1.id, respo_org_2.id]}, ) aidant.refresh_from_db() self.assertIn(aidant_initial_org, aidant.organisations.all()) self.assertIn(respo_org_1, aidant.organisations.all()) self.assertIn(respo_org_2, aidant.organisations.all()) self.assertEqual( len(aidant.organisations.all()), 3, "Aidant’s organisations should contain 3 organisations.", ) self.assertEqual(aidant.organisation, aidant_initial_org)
def setUp(self): self.client = Client() self.aidant_1 = AidantFactory() self.aidant_2 = AidantFactory(username="******", email="*****@*****.**") self.usager_1 = UsagerFactory() self.usager_2 = UsagerFactory() mandat_1 = MandatFactory( organisation=self.aidant_1.organisation, usager=self.usager_1, expiration_date=timezone.now() + timedelta(days=6), ) self.autorisation_1_1 = AutorisationFactory(mandat=mandat_1, demarche="Revenus") self.autorisation_1_2 = AutorisationFactory( mandat=mandat_1, demarche="Papiers", revocation_date=timezone.now()) mandat_2 = MandatFactory( organisation=self.aidant_1.organisation, usager=self.usager_1, expiration_date=timezone.now() - timedelta(days=6), ) self.autorisation_2_1 = AutorisationFactory(mandat=mandat_2, demarche="Logement") mandat_3 = MandatFactory( organisation=self.aidant_2.organisation, usager=self.usager_2, expiration_date=timezone.now() + timedelta(days=6), ) self.autorisation_3_1 = AutorisationFactory(mandat=mandat_3, demarche="Revenus")
def setUp(self): self.client = Client() self.organisation = OrganisationFactory() self.aidant_thierry = AidantFactory(organisation=self.organisation) device = self.aidant_thierry.staticdevice_set.create(id=1) device.token_set.create(token="123456") device.token_set.create(token="223456") self.aidant_monique = AidantFactory( first_name="Monique", username="******", organisation=self.organisation, ) device = self.aidant_monique.staticdevice_set.create(id=2) device.token_set.create(token="323456") self.organisation_nantes = OrganisationFactory(name="Association Aide'o'Web") self.aidant_marge = AidantFactory( first_name="Marge", username="******", organisation=self.organisation_nantes ) device = self.aidant_marge.staticdevice_set.create(id=3) device.token_set.create(token="423456") self.test_usager_sub = ( "46df505a40508b9fa620767c73dc1d7ad8c30f66fa6ae5ae963bf9cccc885e8dv1" ) self.test_usager = UsagerFactory( given_name="Fabrice", birthplace="95277", sub=self.test_usager_sub, )
def setUpTestData(cls): cls.client = Client() # Create one responsable cls.responsable_tom = AidantFactory(username="******") cls.responsable_tom.responsable_de.add( cls.responsable_tom.organisation) # Create one aidant cls.aidant_tim = AidantFactory( username="******", organisation=cls.responsable_tom.organisation, first_name="Tim", last_name="Onier", ) # Create one carte TOTP cls.carte = CarteTOTPFactory(serial_number="A123", seed="FA169F10A9", aidant=cls.aidant_tim) cls.org_id = cls.responsable_tom.organisation.id # Create one TOTP Device cls.device = TOTPDevice(tolerance=30, key=cls.carte.seed, user=cls.aidant_tim, step=60) cls.device.save() cls.organisation_url = f"/espace-responsable/organisation/{cls.org_id}" cls.aidant_url = f"/espace-responsable/aidant/{cls.aidant_tim.id}/" cls.validation_url = ( f"/espace-responsable/aidant/{cls.aidant_tim.id}/valider-carte")
def setUpTestData(cls): cls.aidant_thierry = AidantFactory() cls.responsable_georges = AidantFactory( organisation=cls.aidant_thierry.organisation, can_create_mandats=False, ) cls.responsable_georges.responsable_de.add( cls.aidant_thierry.organisation)
def test_unrelated_aidant_cannot_become_responsable(self): self.aidante_bidule = AidantFactory() self.client.force_login(self.respo) self.assertFalse(self.aidante_bidule.is_responsable_structure()) self.client.post(self.url, data={"candidate": self.aidante_bidule.id}) self.aidante_bidule.refresh_from_db() self.assertFalse(self.aidante_bidule.is_responsable_structure()) self.assertNotIn(self.orga, self.aidante_bidule.responsable_de.all())
class RegionFilterTestCase(FunctionalTestCase): def setUp(self): self.login_url = f"/{settings.ADMIN_URL}login/" self.organisation_url = ( f"/{settings.ADMIN_URL}aidants_connect_web/organisation/") self.login_admin() if DatavizRegion.objects.filter(name="Île-de-France").exists(): return region_idf = DatavizRegionFactory(name="Île-de-France") region_mayotte = DatavizRegionFactory(name="Mayotte") region_grandest = DatavizRegionFactory(name="Grand Est") dep_yvelines = DatavizDepartmentFactory(dep_name="Yvelines", zipcode="78") dep_mayotte = DatavizDepartmentFactory(dep_name="Mayotte", zipcode="976") dep_basrhin = DatavizDepartmentFactory(dep_name="Bas-Rhin", zipcode="67") dep_hautrhin = DatavizDepartmentFactory(dep_name="Haut-Rhin", zipcode="68") DatavizDepartmentsToRegionFactory(region=region_idf, department=dep_yvelines) DatavizDepartmentsToRegionFactory(department=dep_mayotte, region=region_mayotte) DatavizDepartmentsToRegionFactory(department=dep_basrhin, region=region_grandest) DatavizDepartmentsToRegionFactory(department=dep_hautrhin, region=region_grandest) def login_admin(self): self.aidant = AidantFactory( username="******", is_superuser=True, is_staff=True, ) self.aidant.set_password("laisser-passer-a38") self.aidant.save() device = self.aidant.staticdevice_set.create() device.token_set.create(token="123456") WebDriverWait(self.selenium, 10) self.open_live_url(self.login_url) login_field = self.selenium.find_element(By.ID, "id_username") login_field.send_keys("*****@*****.**") otp_field = self.selenium.find_element(By.ID, "id_otp_token") otp_field.send_keys("123456") pwd_field = self.selenium.find_element(By.ID, "id_password") pwd_field.send_keys("laisser-passer-a38") submit_button = self.selenium.find_element(By.XPATH, "//input[@type='submit']") submit_button.click() django_admin_title = self.selenium.find_element(By.TAG_NAME, "h1").text self.assertEqual(django_admin_title, "Administration de Django")
def setUpTestData(cls): # Riri has never validated any CGU cls.aidant_riri = AidantFactory(username="******") # Fifi has validated previous a previous CGU version cls.aidant_fifi = AidantFactory(username="******", validated_cgu_version="0.1") # Loulou is up to date cls.aidant_loulou = AidantFactory( username="******", validated_cgu_version=settings.CGU_CURRENT_VERSION)
def setUpTestData(cls): cls.client = Client() cls.responsable_tom = AidantFactory() cls.responsable_tom.responsable_de.add( cls.responsable_tom.organisation) cls.aidant_tim = AidantFactory( organisation=cls.responsable_tom.organisation) cls.aidant_tim_url = f"/espace-responsable/aidant/{cls.aidant_tim.id}/" cls.autre_organisation = OrganisationFactory() cls.autre_aidant = AidantFactory()
def setUp(self): self.client = Client() self.aidant_thierry = AidantFactory() self.aidant_yasmina = AidantFactory( username="******", organisation=self.aidant_thierry.organisation, ) self.usager = UsagerFactory(given_name="Joséphine") self.connection = Connection.objects.create( state="avalidstate123", nonce="avalidnonce456", usager=self.usager, ) date_further_away_minus_one_hour = datetime( 2019, 1, 9, 8, tzinfo=pytz_timezone("Europe/Paris")) self.connection_2 = Connection.objects.create( state="test_expiration_date_triggered", nonce="test_nonce", usager=self.usager, expires_on=date_further_away_minus_one_hour, ) mandat_creation_date = datetime(2019, 1, 5, 3, 20, 34, 0, tzinfo=pytz_timezone("Europe/Paris")) self.mandat_thierry_usager_1 = MandatFactory( organisation=self.aidant_thierry.organisation, usager=self.usager, expiration_date=mandat_creation_date + timedelta(days=6), creation_date=mandat_creation_date, ) AutorisationFactory( mandat=self.mandat_thierry_usager_1, demarche="transports", ) AutorisationFactory( mandat=self.mandat_thierry_usager_1, demarche="famille", ) self.mandat_thierry_usager_2 = MandatFactory( organisation=self.aidant_thierry.organisation, usager=self.usager, expiration_date=mandat_creation_date + timedelta(days=3), creation_date=mandat_creation_date, ) AutorisationFactory( mandat=self.mandat_thierry_usager_2, demarche="logement", )
def setUp(self): self.aidant_thierry = AidantFactory( is_superuser=True, is_staff=True, is_active=True, post__with_otp_device=True ) self.aidante_fatimah = AidantFactory() self.mandate_1 = MandatFactory(organisation=self.aidant_thierry.organisation) self.mandate_2 = MandatFactory(organisation=self.aidant_thierry.organisation) self.mandate_3 = MandatFactory(organisation=self.aidant_thierry.organisation) self.mandate_4 = MandatFactory(organisation=self.aidant_thierry.organisation)
def setUpTestData(cls): cls.client = Client() responsable = AidantFactory() responsable.responsable_de.add(responsable.organisation) responsable.responsable_de.add(OrganisationFactory()) cls.responsable_of_2 = responsable responsable = AidantFactory() responsable.responsable_de.add(responsable.organisation) cls.responsable_of_1 = responsable
def test_mail_is_sent_to_the_manager(self): aidant = AidantFactory(first_name="Henri", last_name="Tournelle") responsable = AidantFactory(first_name="Hervé", last_name="Gétal", organisation=aidant.organisation) responsable.responsable_de.add(aidant.organisation) call_command("notify_no_totp_workers") self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertIn(f"{aidant}", message.body) self.assertIn("vous-même", message.body) self.assertIn(responsable.email, message.recipients())
def setUp(self): super().setUp() self.aidant_url = f"/{settings.ADMIN_URL}aidants_connect_web/aidant/" orga_basrhin = OrganisationFactory(zipcode=67999, name="Orga du Bas-Rhin") orga_other = OrganisationFactory(zipcode=0, name="Sans Code Postal") self.aidant_basrhin = AidantFactory(last_name="Du Bas-Rhin", organisation=orga_basrhin) self.aidant_other = AidantFactory(last_name="D'on ne sait où", organisation=orga_other)
def test_display_all_active_aidants(self): self.client.force_login(self.responsable_tom) aidant_a = AidantFactory( first_name="Premier-Aidant", organisation=self.responsable_tom.organisation) aidant_b = AidantFactory(first_name="Second-Aidant") aidant_b.organisations.set( (aidant_b.organisation, self.responsable_tom.organisation)) response = self.client.get( f"/espace-responsable/organisation/{self.id_organisation}/") self.assertContains(response, aidant_a.first_name) self.assertContains(response, aidant_b.first_name)
def setUp(self) -> None: self.organisation = OrganisationFactory(id=4444) self.aidant = AidantFactory( username="******", is_superuser=True, is_staff=True, ) self.aidant.set_password("laisser-passer-a38") self.aidant.save() device = self.aidant.staticdevice_set.create() device.token_set.create(token="123456") WebDriverWait(self.selenium, 10) self.login_admin()
def setUpTestData(cls): cls.client = Client() organisation = OrganisationFactory(name="Beta Gouv") responsable = AidantFactory(organisation=organisation) responsable.responsable_de.add(responsable.organisation) responsable.responsable_de.add(OrganisationFactory()) cls.responsable_of_2 = responsable aidant = AidantFactory(organisation=responsable.organisation) aidant.organisations.set(responsable.responsable_de.all()) aidant.organisations.add(OrganisationFactory()) cls.aidant = aidant
def setUp(self): self.client = Client() self.aidant_thierry = AidantFactory() self.aidant_jacques = AidantFactory(username="******", email="*****@*****.**") self.usager = UsagerFactory(given_name="Joséphine", sub="123") mandat_1 = MandatFactory( organisation=self.aidant_thierry.organisation, usager=self.usager, expiration_date=timezone.now() + timedelta(days=6), ) AutorisationFactory( mandat=mandat_1, demarche="Revenus", revocation_date=timezone.now() - timedelta(days=1), ) mandat_2 = MandatFactory( organisation=self.aidant_thierry.organisation, usager=self.usager, expiration_date=timezone.now() + timedelta(days=12), ) AutorisationFactory( mandat=mandat_2, demarche="Famille", ) AutorisationFactory( mandat=mandat_2, demarche="Revenus", ) mandat_3 = MandatFactory( organisation=self.aidant_jacques.organisation, usager=self.usager, expiration_date=timezone.now() + timedelta(days=12), ) AutorisationFactory( mandat=mandat_3, demarche="Logement", ) date_further_away_minus_one_hour = datetime( 2019, 1, 9, 8, tzinfo=pytz_timezone("Europe/Paris")) self.connection = Connection.objects.create( state="test_expiration_date_triggered", nonce="avalidnonce456", usager=self.usager, expires_on=date_further_away_minus_one_hour, )
def setUpTestData(cls): cls.client = Client() # Tom is responsable of 2 structures cls.responsable_tom = AidantFactory() cls.responsable_tom.responsable_de.add( cls.responsable_tom.organisation) cls.responsable_tom.responsable_de.add(OrganisationFactory()) cls.responsable_tom.can_create_mandats = False # Tim is responsable of only one structure cls.responsable_tim = AidantFactory() cls.responsable_tim.responsable_de.add( cls.responsable_tim.organisation) # John is a simple aidant cls.aidant_john = AidantFactory()
def setUpTestData(cls): cls.rf = RequestFactory() cls.organisation1 = OrganisationFactory(name="MAIRIE", siret="121212121") cls.organisation2 = OrganisationFactory(name="MAIRIE2", siret="121212122") cls.organisation3 = OrganisationFactory(name="MAIRIE3", siret="121212123") cls.aidant_marge = AidantFactory(first_name="Marge", organisation=cls.organisation1) cls.aidant_homer = AidantFactory(first_name="Homer", organisation=cls.organisation2) cls.habilit_bowser = HabilitationRequestFactory( first_name="Bowser", organisation=cls.organisation3)
def test_do_not_destroy_unrelated_totp_device(self): aidant_tim = AidantFactory() aidant_tom = AidantFactory() totp_device = TOTPDeviceFactory(user=aidant_tim) card = CarteTOTPFactory(aidant=aidant_tom, seed=totp_device.key) card_dissociate_url = reverse( "otpadmin:aidants_connect_web_carte_totp_dissociate", args=(card.id, ), ) response = self.bizdev_client.post(card_dissociate_url) self.assertNotEqual(response.status_code, 500) card_db = CarteTOTP.objects.get(id=card.id) self.assertIsNone(card_db.aidant) # device should be deleted only if it is associated with the same aidant self.assertEqual(1, TOTPDevice.objects.filter(user=aidant_tim).count())
def setUp(self): self.aidant = AidantFactory(email="*****@*****.**", post__with_otp_device=True) self.usager_josephine = UsagerFactory(given_name="Joséphine", family_name="ST-PIERRE") self.usager_anne = UsagerFactory(given_name="Anne Cécile Gertrude", family_name="EVALOUS") self.usager_corentin = UsagerFactory(given_name="Corentin", family_name="Dupont", preferred_username="******") MandatFactory( organisation=self.aidant.organisation, usager=self.usager_josephine, post__create_authorisations=["argent", "famille"], ) ExpiredMandatFactory( organisation=self.aidant.organisation, usager=self.usager_corentin, post__create_authorisations=["argent", "famille", "logement"], ) MandatFactory( organisation=self.aidant.organisation, usager=self.usager_anne, post__create_authorisations=["argent", "famille", "logement"], )
def setUpTestData(cls): cls.entry1 = Journal.objects.create(action="connect_aidant", initiator="ABC") cls.aidant_thierry = AidantFactory( username="******", email="*****@*****.**", first_name="Thierry", last_name="Martin", organisation=OrganisationFactory(name="Commune de Vernon"), ) cls.usager_ned = UsagerFactory(given_name="Ned", family_name="Flanders") cls.first_mandat = MandatFactory( organisation=cls.aidant_thierry.organisation, usager=cls.usager_ned, expiration_date=timezone.now() + timedelta(days=6), ) cls.first_autorisation = AutorisationFactory( mandat=cls.first_mandat, demarche="Revenus", ) Journal.log_autorisation_creation(cls.first_autorisation, aidant=cls.aidant_thierry) cls.mandat_thierry_ned_365 = MandatFactory( organisation=cls.aidant_thierry.organisation, usager=cls.usager_ned, expiration_date=timezone.now() + timedelta(days=365), )
def setUp(self): self.organisation_1 = OrganisationFactory() self.aidant_1 = AidantFactory(username="******") self.usager_1 = UsagerFactory() self.mandat_1 = Mandat.objects.create( organisation=self.organisation_1, usager=self.usager_1, creation_date=timezone.now(), duree_keyword="SHORT", expiration_date=timezone.now() + timedelta(days=1), ) AutorisationFactory( mandat=self.mandat_1, demarche="justice", ) self.usager_2 = UsagerFactory(sub="anothersub") self.mandat_2 = Mandat.objects.create( organisation=self.organisation_1, usager=self.usager_2, creation_date=timezone.now(), duree_keyword="SHORT", expiration_date=timezone.now() + timedelta(days=1), ) AutorisationFactory( mandat=self.mandat_2, demarche="argent", ) AutorisationFactory( mandat=self.mandat_2, demarche="transport", )
def setUpTestData(cls): cls.client = Client() cls.aidant = AidantFactory() cls.usager = UsagerFactory() cls.mandat = MandatFactory(organisation=cls.aidant.organisation, usager=cls.usager) AutorisationFactory(mandat=cls.mandat)
def test_avoid_oracle_for_other_organisations_aidants(self): self.client.force_login(self.responsable_tom) other_aidant = AidantFactory() response = self.client.post( self.add_aidant_url, data={ "organisation": self.org_a.id, "email": other_aidant.email, "first_name": "Bob", "last_name": "Dubois", "profession": "Assistant social", }, ) self.assertRedirects( response, self.organisation_url, fetch_redirect_response=False ) response = self.client.get(self.organisation_url) response_content = response.content.decode("utf-8") self.assertIn( "La requête d’habilitation pour Bob Dubois a bien été enregistrée.", response_content, "Confirmation message should be displayed.", ) self.assertIn( other_aidant.email, response_content, "New habilitation request should be displayed on organisation page.", )
def setUp(self): self.client = Client() self.aidant = AidantFactory() self.usager = UsagerFactory() self.mandat = MandatFactory(organisation=self.aidant.organisation, usager=self.usager) AutorisationFactory(mandat=self.mandat)