Ejemplo n.º 1
0
def consent_to_all_required_consents(person: Person) -> None:
    """
    Helper function shared by SuperuserMixin and TestBase
    """
    terms = (Term.objects.filter(required_type=Term.PROFILE_REQUIRE_TYPE).
             active().prefetch_active_options())
    old_consents = Consent.objects.filter(person=person,
                                          term__in=terms).active()
    old_consents_by_term_id = {
        consent.term_id: consent
        for consent in old_consents
    }
    for term in terms:
        old_consent = old_consents_by_term_id[term.id]
        Consent.reconsent(old_consent, term.options[0])
Ejemplo n.º 2
0
    def setUp(self):
        self.admin = Person.objects.create_superuser(
            username="******",
            personal="Super",
            family="User",
            email="*****@*****.**",
            password="******",
        )
        consent_to_all_required_consents(self.admin)
        self.admin.airport = Airport.objects.first()
        self.admin.save()

        self.event = Event.objects.create(
            slug="test-event",
            host=Organization.objects.first(),
            administrator=Organization.objects.first(),
            assigned_to=self.admin,
        )

        self.award = Award.objects.create(
            person=self.admin,
            badge=Badge.objects.first(),
            event=self.event,
        )
        self.term = Term.objects.active().prefetch_active_options()[0]
        old_consent = Consent.objects.filter(
            person=self.admin,
            term=self.term,
        ).active()[0]
        self.consent = Consent.reconsent(consent=old_consent,
                                         term_option=self.term.options[0])

        self.instructor_role = Role.objects.create(name="instructor")

        self.task = Task.objects.create(event=self.event,
                                        person=self.admin,
                                        role=self.instructor_role)

        self.client.login(username="******", password="******")
Ejemplo n.º 3
0
 def reconsent(person: Person, term: Term,
               term_option: Optional[TermOption]) -> Consent:
     consent = Consent.objects.get(person=person,
                                   term=term,
                                   archived_at__isnull=True)
     return Consent.reconsent(consent, term_option)
Ejemplo n.º 4
0
    def setUp(self):
        def get_option(term_slug: str, option_type: str) -> TermOption:
            return [
                option for option in terms_dict[term_slug].options
                if option.option_type == option_type
            ][0]

        def get_consent(term_slug: str, person: Person) -> Consent:
            return [
                consent for consent in old_consents
                if consent.term.slug == term_slug and consent.person == person
            ][0]

        self.admin_1 = Person.objects.create_superuser(
            username="******",
            personal="Super",
            family="User",
            email="*****@*****.**",
            password="******",
        )
        consent_to_all_required_consents(self.admin_1)
        self.admin_1.airport = Airport.objects.first()
        self.admin_1.save()

        self.admin_2 = Person.objects.create_superuser(
            username="******",
            personal="Super",
            family="User",
            email="*****@*****.**",
            password="******",
        )
        consent_to_all_required_consents(self.admin_2)
        self.admin_2.airport = Airport.objects.first()
        self.admin_2.save()

        terms = (Term.objects.filter(
            slug__in=["may-contact", "public-profile"
                      ]).active().prefetch_active_options())
        terms_dict = {term.slug: term for term in terms}
        may_contact_agree = get_option("may-contact", TermOption.AGREE)
        may_contact_decline = get_option("may-contact", TermOption.DECLINE)
        publish_profile_agree = get_option("public-profile", TermOption.AGREE)
        publish_profile_decline = get_option("public-profile",
                                             TermOption.DECLINE)

        old_consents = (Consent.objects.filter(
            person__in=[self.admin_1, self.admin_2],
            term__slug__in=["may-contact", "public-profile"],
        ).active().select_related("term", "person"))

        Consent.reconsent(
            consent=get_consent("may-contact", self.admin_1),
            term_option=may_contact_agree,
        )
        Consent.reconsent(
            consent=get_consent("may-contact", self.admin_2),
            term_option=may_contact_decline,
        )
        Consent.reconsent(
            consent=get_consent("public-profile", self.admin_1),
            term_option=publish_profile_agree,
        )
        Consent.reconsent(
            consent=get_consent("public-profile", self.admin_2),
            term_option=publish_profile_decline,
        )

        self.client.login(username="******", password="******")