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",
        )
Example #2
0
    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",
        )
Example #3
0
    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.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.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,
        )
Example #6
0
    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.mandat = MandatFactory(organisation=self.aidant_thierry.organisation)
        AutorisationFactory(
            mandat=self.mandat,
            demarche="argent",
        )
        AutorisationFactory(
            mandat=self.mandat,
            demarche="famille",
        )
    def setUp(self):
        self.aidant = AidantFactory(username="******")
        device = self.aidant.staticdevice_set.create(id=self.aidant.id)
        device.token_set.create(token="123456")

        self.usager_alice = UsagerFactory(given_name="Alice", family_name="Lovelace")
        self.usager_josephine = UsagerFactory(
            given_name="Joséphine", family_name="Dupont"
        )
        self.usager_corentin = UsagerFactory(
            given_name="Corentin", family_name="Dupont", preferred_username="******"
        )

        self.mandat_aidant_alice_no_autorisation = MandatFactory(
            organisation=self.aidant.organisation,
            usager=self.usager_alice,
            expiration_date=timezone.now() + timedelta(days=5),
        )

        self.mandat_aidant_josephine_6 = MandatFactory(
            organisation=self.aidant.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=self.mandat_aidant_josephine_6,
            demarche="social",
        )

        self.mandat_aidant_josephine_1 = MandatFactory(
            organisation=self.aidant.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=1),
        )

        AutorisationFactory(
            mandat=self.mandat_aidant_josephine_1,
            demarche="papiers",
        )

        self.mandat_aidant_corentin_365 = MandatFactory(
            organisation=self.aidant.organisation,
            usager=self.usager_corentin,
            expiration_date=timezone.now() + timedelta(days=365),
        )
        AutorisationFactory(
            mandat=self.mandat_aidant_corentin_365,
            demarche="famille",
        )
Example #8
0
    def setUpTestData(cls):
        cls.client = Client()

        cls.our_organisation = OrganisationFactory()
        cls.our_aidant = AidantFactory(organisation=cls.our_organisation)
        cls.our_usager = UsagerFactory()

        valid_mandat = MandatFactory(
            organisation=cls.our_organisation,
            usager=cls.our_usager,
        )
        cls.valid_autorisation = AutorisationFactory(mandat=valid_mandat,
                                                     demarche="Revenus")
        cls.revoked_autorisation = AutorisationFactory(
            mandat=valid_mandat,
            demarche="Papiers",
            revocation_date=timezone.now())

        expired_mandat = MandatFactory(
            organisation=cls.our_organisation,
            usager=cls.our_usager,
            expiration_date=timezone.now() - timedelta(days=6),
        )
        cls.expired_autorisation = AutorisationFactory(mandat=expired_mandat,
                                                       demarche="Logement")

        cls.other_organisation = OrganisationFactory(name="Other Organisation")
        cls.unrelated_usager = UsagerFactory()

        unrelated_mandat = MandatFactory(
            organisation=cls.other_organisation,
            usager=cls.unrelated_usager,
        )
        cls.unrelated_autorisation = AutorisationFactory(
            mandat=unrelated_mandat, demarche="Revenus")

        mandat_other_org_with_our_usager = MandatFactory(
            organisation=cls.other_organisation,
            usager=cls.our_usager,
        )

        cls.autorisation_other_org_with_our_usager = AutorisationFactory(
            mandat=mandat_other_org_with_our_usager, demarche="Logement")

        cls.good_combo = {
            "usager": cls.our_usager.id,
            "autorisation": cls.valid_autorisation.id,
        }
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
    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),
        )
Example #12
0
    def setUpTestData(cls):
        cls.client = Client()

        cls.our_organisation = OrganisationFactory()
        cls.our_aidant = AidantFactory(organisation=cls.our_organisation)
        cls.our_usager = UsagerFactory()

        cls.valid_mandat = MandatFactory(
            organisation=cls.our_organisation,
            usager=cls.our_usager,
            creation_date=datetime.datetime(
                2021, 2, 1, 13, 12, tzinfo=pytz.timezone("Europe/Paris")),
        )
        cls.valid_autorisation = AutorisationFactory(mandat=cls.valid_mandat,
                                                     demarche="Revenus")

        cls.cancelled_mandat = MandatFactory(
            organisation=cls.our_organisation,
            usager=cls.our_usager,
            creation_date=datetime.datetime(
                2021, 2, 1, 13, 12, tzinfo=pytz.timezone("Europe/Paris")),
        )
        AutorisationFactory(
            mandat=cls.cancelled_mandat,
            demarche="Revenus",
            revocation_date=timezone.now() - timedelta(minutes=5),
        )

        cls.expired_mandat = MandatFactory(
            organisation=cls.our_organisation,
            usager=cls.our_usager,
            creation_date=datetime.datetime(
                2021, 2, 1, 13, 12, tzinfo=pytz.timezone("Europe/Paris")),
            expiration_date=timezone.now() - timedelta(minutes=5),
        )
        AutorisationFactory(
            mandat=cls.expired_mandat,
            demarche="Revenus",
            revocation_date=timezone.now() - timedelta(minutes=5),
        )

        AutorisationFactory(
            mandat=cls.expired_mandat,
            demarche="Papiers",
        )
Example #13
0
    def setUp(self):
        self.aidant_1 = AidantFactory()
        device = self.aidant_1.staticdevice_set.create(id=self.aidant_1.id)
        device.token_set.create(token="123456")
        self.aidant_2 = AidantFactory(
            username="******",
            email="*****@*****.**",
            password="******",
            first_name="Jacqueline",
            last_name="Fremont",
        )
        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"
        )

        mandat_aidant_1_jo_6 = MandatFactory(
            organisation=self.aidant_1.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=mandat_aidant_1_jo_6, demarche="argent",
        )

        mandat_aidant_1_jo_12 = Mandat.objects.create(
            organisation=self.aidant_1.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=12),
        )

        AutorisationFactory(
            mandat=mandat_aidant_1_jo_12, demarche="famille",
        )

        mandat_aidant_2_jo_12 = Mandat.objects.create(
            organisation=self.aidant_2.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=12),
        )
        AutorisationFactory(
            mandat=mandat_aidant_2_jo_12, demarche="logement",
        )
Example #14
0
    def test_saving_and_retrieving_autorisation(self):
        first_autorisation = AutorisationFactory(
            mandat=self.mandat_marge_homer_6,
            demarche="Carte grise",
        )
        second_autorisation = AutorisationFactory(
            mandat=self.mandat_patricia_ned_6,
            demarche="Revenus",
        )
        self.assertEqual(Autorisation.objects.count(), 2)

        self.assertEqual(
            first_autorisation.mandat.organisation,
            self.mandat_marge_homer_6.organisation,
        )
        self.assertEqual(first_autorisation.demarche, "Carte grise")
        self.assertEqual(second_autorisation.mandat.usager.family_name,
                         "Flanders")
Example #15
0
    def test_get_valid_autorisation_method(self):
        # A valid mandat with one revoked autorisation
        usager_charles = UsagerFactory(given_name="Charles", sub="Charles")
        active_mandat = MandatFactory(
            organisation=self.aidant_marge.organisation,
            usager=usager_charles,
        )
        valid_autorisation = AutorisationFactory(
            mandat=active_mandat,
            demarche="papiers",
            revocation_date=None,
        )
        AutorisationFactory(
            mandat=active_mandat,
            demarche="transport",
            revocation_date=timezone.now() - timedelta(days=1),
        )
        self.assertEqual(
            self.aidant_marge.get_valid_autorisation("papiers",
                                                     usager_charles),
            valid_autorisation,
        )
        self.assertEqual(
            self.aidant_marge.get_valid_autorisation("transport",
                                                     usager_charles), None)

        # An expired Mandat
        expired_mandat = MandatFactory(
            organisation=self.aidant_marge.organisation,
            usager=usager_charles,
            expiration_date=timezone.now() - timedelta(days=1),
        )
        AutorisationFactory(
            mandat=expired_mandat,
            demarche="social",
            revocation_date=None,
        )

        self.assertEqual(
            self.aidant_marge.get_valid_autorisation("social", usager_charles),
            None)
    def setUpClass(cls):
        cls.aidant = AidantFactory()
        device = cls.aidant.staticdevice_set.create(id=cls.aidant.id)
        device.token_set.create(token="123456")

        cls.usager_josephine = UsagerFactory(given_name="Joséphine")
        cls.usager_corentin = UsagerFactory(given_name="Corentin")

        cls.mandat_aidant_josephine_6 = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_josephine_6,
            demarche="social",
        )

        cls.mandat_aidant_josephine_1 = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=1),
        )

        AutorisationFactory(
            mandat=cls.mandat_aidant_josephine_1,
            demarche="papiers",
        )

        cls.mandat_aidant_corentin_365 = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_corentin,
            expiration_date=timezone.now() + timedelta(days=365),
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_corentin_365,
            demarche="famille",
        )

        super().setUpClass()
Example #17
0
    def setUp(self):
        self.aidant_1 = AidantFactory(email="*****@*****.**")
        device = self.aidant_1.staticdevice_set.create(id=self.aidant_1.id)
        device.token_set.create(token="123456")
        self.aidant_2 = AidantFactory()
        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")

        mandat_aidant_1_jo_6 = MandatFactory(
            organisation=self.aidant_1.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=mandat_aidant_1_jo_6,
            demarche="argent",
        )

        mandat_aidant_1_jo_12 = Mandat.objects.create(
            organisation=self.aidant_1.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=12),
        )

        AutorisationFactory(
            mandat=mandat_aidant_1_jo_12,
            demarche="famille",
        )

        mandat_aidant_2_jo_12 = Mandat.objects.create(
            organisation=self.aidant_2.organisation,
            usager=self.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=12),
        )
        AutorisationFactory(
            mandat=mandat_aidant_2_jo_12,
            demarche="logement",
        )
Example #18
0
    def test_active_queryset_method_include_partially_revoked_mandat(self):
        partially_revoked_mandat = 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=partially_revoked_mandat,
            demarche="papiers",
            revocation_date=timezone.now() - timedelta(minutes=1),
        )
        AutorisationFactory(
            mandat=partially_revoked_mandat,
            demarche="loisirs",
        )
        active_mandats = Mandat.objects.active().count()
        inactive_mandats = Mandat.objects.inactive().count()

        self.assertEqual(active_mandats, 3)
        self.assertEqual(inactive_mandats, 0)
Example #19
0
    def setUpTestData(cls):
        cls.client = Client()

        cls.our_organisation = OrganisationFactory()
        cls.our_aidant = AidantFactory(organisation=cls.our_organisation)
        cls.our_usager = UsagerFactory()

        cls.valid_mandat = MandatFactory(
            organisation=cls.our_organisation,
            usager=cls.our_usager,
        )
        cls.valid_autorisation = AutorisationFactory(
            mandat=cls.valid_mandat, demarche=[*settings.DEMARCHES][0])
Example #20
0
    def setUpClass(cls):
        cls.aidant_thierry = AidantFactory()
        device = cls.aidant_thierry.staticdevice_set.create(
            id=cls.aidant_thierry.id)
        device.token_set.create(token="123456")
        cls.aidant_jacqueline = AidantFactory(
            username="******",
            email="*****@*****.**",
            password="******",
            first_name="Jacqueline",
            last_name="Fremont",
        )
        cls.usager_josephine = UsagerFactory(given_name="Joséphine")
        cls.mandat_thierry_josephine = MandatFactory(
            organisation=cls.aidant_thierry.organisation,
            usager=cls.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_thierry_josephine,
            demarche="argent",
        )
        AutorisationFactory(
            mandat=cls.mandat_thierry_josephine,
            demarche="famille",
        )

        cls.mandat_jacqueline_josephine = MandatFactory(
            organisation=cls.aidant_jacqueline.organisation,
            usager=cls.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=12),
        )
        AutorisationFactory(
            mandat=cls.mandat_jacqueline_josephine,
            demarche="logement",
        )
        super().setUpClass()
Example #21
0
    def test_log_autorisation_creation_complete(self):

        autorisation = AutorisationFactory(
            mandat=self.mandat_thierry_ned_365,
            demarche="logement",
        )
        Journal.log_autorisation_creation(autorisation, self.aidant_thierry)

        journal_entries = Journal.objects.all()
        self.assertEqual(len(journal_entries), 3)

        last_entry = journal_entries.last()
        self.assertEqual(last_entry.action, "create_autorisation")
        self.assertIn("Ned Flanders", last_entry.usager)
        self.assertEqual(last_entry.autorisation, autorisation.id)
Example #22
0
    def setUpTestData(cls):
        cls.client = Client()
        cls.usager = UsagerFactory(
            given_name="Joséphine",
            family_name="ST-PIERRE",
            preferred_username="******",
            birthdate=date(1969, 12, 25),
            gender=Usager.GENDER_FEMALE,
            birthplace="70447",
            birthcountry=Usager.BIRTHCOUNTRY_FRANCE,
            sub="test_sub",
            email="*****@*****.**",
            creation_date="2019-08-05T15:49:13.972Z",
            phone="0 800 840 800",
        )
        cls.aidant_thierry = AidantFactory()
        cls.mandat_thierry_usager = MandatFactory(
            organisation=cls.aidant_thierry.organisation,
            usager=cls.usager,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        cls.autorisation = AutorisationFactory(
            mandat=cls.mandat_thierry_usager,
            demarche="transports",
        )

        cls.access_token = "test_access_token"
        cls.access_token_hash = make_password(cls.access_token,
                                              settings.FC_AS_FI_HASH_SALT)
        cls.connection = Connection.objects.create(
            state="avalidstate123",
            code="test_code",
            nonce="avalidnonde456",
            usager=cls.usager,
            access_token=cls.access_token_hash,
            expires_on=datetime(2012,
                                1,
                                14,
                                3,
                                21,
                                34,
                                0,
                                tzinfo=pytz_timezone("Europe/Paris")),
            aidant=cls.aidant_thierry,
            organisation=cls.aidant_thierry.organisation,
            autorisation=cls.autorisation,
        )
Example #23
0
    def setUpTestData(cls):
        cls.aidant = AidantFactory(username="******",
                                   email="*****@*****.**")
        device = cls.aidant.staticdevice_set.create(id=cls.aidant.id)
        device.token_set.create(token="123456")

        cls.usager_philomene = UsagerFactory(given_name="Philomène",
                                             family_name="Smith")

        cls.mandat_aidant_phillomene = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_philomene,
            expiration_date=timezone.now() - timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_phillomene,
            demarche="social",
        )
Example #24
0
    def test_active_queryset_method_excludes_expired_mandat(self):
        expired_mandat = 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=expired_mandat,
            demarche="papiers",
        )

        active_mandats = Mandat.objects.active().count()
        inactive_mandats = Mandat.objects.inactive().count()

        self.assertEqual(active_mandats, 2)
        self.assertEqual(inactive_mandats, 1)
Example #25
0
 def test_autorisation_expiration_date_setting(self):
     mandat = MandatFactory(
         organisation=self.aidant_marge.organisation,
         usager=self.usager_homer,
         expiration_date=timezone.now() + timedelta(days=3),
     )
     autorisation = AutorisationFactory(
         mandat=mandat,
         demarche="Carte grise",
     )
     self.assertEqual(
         autorisation.creation_date,
         datetime(2019, 1, 14, tzinfo=pytz_timezone("Europe/Paris")),
     )
     self.assertEqual(
         autorisation.mandat.expiration_date,
         datetime(2019, 1, 17, tzinfo=pytz_timezone("Europe/Paris")),
     )
Example #26
0
    def test_know_error_cases(self):
        def error_case_tester(mandat_id):
            self.client.force_login(self.our_aidant)
            response = self.client.get(f"/mandats/{mandat_id}/cancel_confirm")
            url = "/espace-aidant/"
            self.assertRedirects(response, url, fetch_redirect_response=False)

        expired_mandat = MandatFactory(expiration_date=timezone.now() -
                                       timedelta(hours=6))
        revoked_mandat = MandatFactory()
        AutorisationFactory(mandat=revoked_mandat,
                            revocation_date=timezone.now() -
                            timedelta(hours=6))
        other_org = OrganisationFactory(name="not our organisation")
        unrelated_mandat = MandatFactory(organisation=other_org,
                                         usager=self.our_usager)
        non_existing_mandat_id = Mandat.objects.last().id + 1

        error_case_tester(non_existing_mandat_id)
        error_case_tester(expired_mandat.id)
        error_case_tester(revoked_mandat.id)
        error_case_tester(unrelated_mandat.id)
Example #27
0
    def setUpTestData(cls):
        cls.aidant = AidantFactory()
        device = cls.aidant.staticdevice_set.create(id=cls.aidant.id)
        device.token_set.create(token="123456")

        cls.usager_alice = UsagerFactory(given_name="Alice",
                                         family_name="Lovelace")
        cls.usager_josephine = UsagerFactory(given_name="Joséphine",
                                             family_name="Dupont")
        cls.usager_corentin = UsagerFactory(given_name="Corentin",
                                            family_name="Dupont",
                                            preferred_username="******")
        cls.usager_philomene = UsagerFactory(given_name="Philomène",
                                             family_name="Smith")

        cls.usager_pierre = UsagerFactory(given_name="Pierre",
                                          family_name="Etienne",
                                          preferred_username="******")

        cls.mandat_aidant_phillomene = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_philomene,
            expiration_date=timezone.now() - timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_phillomene,
            demarche="social",
        )

        cls.mandat_aidant_alice_no_autorisation = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_alice,
            expiration_date=timezone.now() + timedelta(days=5),
        )

        cls.mandat_aidant_josephine_6 = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_josephine_6,
            demarche="social",
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_josephine_6,
            demarche="papiers",
            revocation_date=timezone.now() - timedelta(days=6),
        )

        cls.mandat_aidant_josephine_1 = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_josephine,
            expiration_date=timezone.now() + timedelta(days=1),
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_josephine_1,
            demarche="famille",
            revocation_date=timezone.now() - timedelta(days=6),
        )

        AutorisationFactory(
            mandat=cls.mandat_aidant_josephine_1,
            demarche="papiers",
        )

        cls.mandat_aidant_corentin_365 = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_corentin,
            expiration_date=timezone.now() + timedelta(days=365),
        )
        AutorisationFactory(
            mandat=cls.mandat_aidant_corentin_365,
            demarche="famille",
        )

        cls.mandat_inactif_aidant_corentin = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_corentin,
            expiration_date=timezone.now() - timedelta(days=2),
        )
        AutorisationFactory(
            mandat=cls.mandat_inactif_aidant_corentin,
            demarche="famille",
        )

        cls.mandat_sans_autorisations_aidant_corentin = MandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_corentin,
            expiration_date=timezone.now() + timedelta(days=366),
        )

        cls.mandat_aidant_pierre_revoked_over_a_year = RevokedOverYearMandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_pierre,
            expiration_date=timezone.now() + timedelta(days=5),
            post__create_authorisations=["argent", "famille", "logement"],
        )

        cls.mandat_aidant_pierre_expired_over_a_year = ExpiredOverYearMandatFactory(
            organisation=cls.aidant.organisation,
            usager=cls.usager_pierre,
        )

        AutorisationFactory(
            mandat=cls.mandat_aidant_pierre_expired_over_a_year,
            demarche="famille",
        )
Example #28
0
    def setUpTestData(cls):
        mairie_de_houlbec = OrganisationFactory()
        aidant_thierry = AidantFactory()
        CarteTOTPFactory(aidant=aidant_thierry)
        usager_homer = UsagerFactory()
        mandat_houlbec_homer = MandatFactory(organisation=mairie_de_houlbec,
                                             usager=usager_homer)
        autorisation_justice_houlbec_homer = AutorisationFactory(
            mandat=mandat_houlbec_homer)

        Journal.objects.create(
            aidant=aidant_thierry,
            organisation=aidant_thierry.organisation,
            usager=usager_homer,
            action="use_autorisation",
            demarche="justice",
            autorisation=autorisation_justice_houlbec_homer.id,
        )
        Journal.objects.create(
            aidant=aidant_thierry,
            organisation=aidant_thierry.organisation,
            usager=usager_homer,
            action="use_autorisation",
            demarche="justice",
            autorisation=autorisation_justice_houlbec_homer.id,
        )

        # An Aidant from Stafforg is among us !
        staff_organisation = Organisation.objects.create(
            name=settings.STAFF_ORGANISATION_NAME)
        aidant_staff_organisation = AidantFactory(
            username="******", organisation=staff_organisation)
        CarteTOTPFactory(aidant=aidant_staff_organisation)

        # an aidant staff_organisation has an attestation
        # with an usager also helped by another aidant

        mandat_stafforg_homer = MandatFactory(organisation=staff_organisation,
                                              usager=usager_homer)
        autorisation_justice_stafforg_homer = AutorisationFactory(
            mandat=mandat_stafforg_homer)

        Journal.objects.create(
            aidant=aidant_staff_organisation,
            organisation=aidant_staff_organisation.organisation,
            usager=usager_homer,
            action="use_autorisation",
            demarche="justice",
            autorisation=autorisation_justice_stafforg_homer.id,
        )
        # An aidant staff_organisation has an exclusive autorisation with a user
        usager_laurent = UsagerFactory(given_name="Laurent",
                                       sub="sub for laurent")

        mandat_stafforg_laurent = MandatFactory(
            organisation=staff_organisation, usager=usager_homer)
        autorisation_justice_stafforg_laurent = AutorisationFactory(
            mandat=mandat_stafforg_laurent, )

        Journal.objects.create(
            action="use_autorisation",
            aidant=aidant_staff_organisation,
            organisation=aidant_staff_organisation.organisation,
            usager=usager_laurent,
            demarche="justice",
            autorisation=autorisation_justice_stafforg_laurent.id,
        )

        # jacqueline has an expired autorisation and no active autorisations
        usager_jacqueline = UsagerFactory(
            given_name="Jacqueline",
            creation_date=datetime(year=2000,
                                   month=1,
                                   day=1,
                                   tzinfo=timezone.utc),
            sub="new_sub_for_jacqueline",
        )
        mandat_houlbec_jacqueline = MandatFactory(
            organisation=mairie_de_houlbec,
            usager=usager_jacqueline,
            expiration_date=datetime(year=2000,
                                     month=1,
                                     day=1,
                                     tzinfo=timezone.utc),
        )

        autorisation_justice_houlbec_jacqueline = AutorisationFactory(
            mandat=mandat_houlbec_jacqueline, )

        Journal.objects.create(
            action="use_autorisation",
            aidant=aidant_thierry,
            organisation=aidant_thierry.organisation,
            usager=usager_jacqueline,
            demarche=autorisation_justice_houlbec_jacqueline.demarche,
            duree=1,
            autorisation=autorisation_justice_houlbec_jacqueline.id,
        )
        Journal.objects.filter(usager=usager_jacqueline).update(
            creation_date=datetime(
                year=2000, month=1, day=1, tzinfo=timezone.utc))
Example #29
0
    def setUpTestData(cls):
        cls.aidant_marge = AidantFactory(username="******")
        cls.aidant_lisa = AidantFactory(
            username="******", organisation=cls.aidant_marge.organisation)
        cls.aidant_patricia = AidantFactory(username="******")
        cls.usager_homer = UsagerFactory(given_name="Homer")
        cls.usager_ned = UsagerFactory(given_name="Ned")
        cls.usager_bart = UsagerFactory(given_name="Bart")

        cls.mandat_marge_homer_1 = MandatFactory(
            organisation=cls.aidant_marge.organisation,
            usager=cls.usager_homer,
            expiration_date=timezone.now() - timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_homer_1,
            demarche="Carte grise",
        )

        cls.mandat_marge_homer_2 = MandatFactory(
            organisation=cls.aidant_marge.organisation,
            usager=cls.usager_homer,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_homer_2,
            demarche="Revenus",
        )

        cls.mandat_marge_homer_3 = MandatFactory(
            organisation=cls.aidant_marge.organisation,
            usager=cls.usager_homer,
            expiration_date=timezone.now() + timedelta(days=365),
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_homer_3,
            demarche="social",
        )

        cls.mandat_marge_ned_1 = MandatFactory(
            organisation=cls.aidant_marge.organisation,
            usager=cls.usager_ned,
            expiration_date=timezone.now() - timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_ned_1,
            demarche="Logement",
        )

        cls.mandat_marge_ned_2 = MandatFactory(
            organisation=cls.aidant_marge.organisation,
            usager=cls.usager_ned,
            expiration_date=timezone.now() + timedelta(days=6),
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_ned_2,
            demarche="transports",
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_ned_2,
            demarche="famille",
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_ned_2,
            demarche="social",
        )
        AutorisationFactory(
            mandat=cls.mandat_marge_ned_2,
            demarche="travail",
        )

        AutorisationFactory(
            demarche="papiers",
            mandat=cls.mandat_marge_ned_2,
            revocation_date=timezone.now(),
        )