def test_unique_is_unique(self):
     family1 = Family()
     family2 = Family()
     self.assertFalse(
         family1.unique == family2,
         "Instances of the Family models does have a unique value in the unique field"
     )
    def setUp(self):
        self.template = EmailTemplate(idname="TEST",
                                      name="TEMPLATE NAME",
                                      description="TEMPLATE DESCRIPTION",
                                      subject="TEMPLATE SUBJECT",
                                      body_html="TEMPLATE HTML",
                                      body_text="TEMPLATE TEXT")
        self.template.save()

        self.family = Family(email="*****@*****.**")
        self.family.save()

        self.person = Person(family=self.family)
        self.person.save()

        self.union = Union(name="",
                           region="S",
                           streetname="",
                           housenumber="1",
                           zipcode="1234",
                           city="")
        self.union.save()

        self.department = Department(
            union=self.union,
            name="",
            streetname="",
            housenumber="1",
            zipcode="1234",
            city="",
            responsible_contact="*****@*****.**")
        self.department.save()
class TestModelPerson(TestCase):
    def setUp(self):
        self.family = Family()
        self.family.save()

        self.person = Person(
            family=self.family
        )
        self.person.save()

    def mock_reference_time(self, time):
        def mock(timezone):
            pass

        return mock

    def test_age_years(self):
        with freeze_time(datetime(2010, 3, 2, 12, 0, 0)):
            self.person.birthday = datetime(2000, 1, 1, 12, 0, 0)
            self.person.save()
            self.assertEqual(self.person.age_years(), 10)

    def test_firstname(self):
        self.person.name = "Foo-Foo Bar Baz"
        self.person.save()
        self.assertEqual(self.person.firstname(), "Foo-Foo")
    def setUp(self):
        self.department = DepartmentFactory()

        self.activity = Activity(
            start_date=datetime.now(),
            end_date=datetime.now() +
            timedelta(days=365),  # Has to be long enough to be a season
            department=self.department,
        )
        self.activity.save()
        self.assertTrue(
            self.activity.is_season())  # If this fail increase the end_date

        self.family = Family(email="*****@*****.**")
        self.family.save()

        self.person = Person(family=self.family)
        self.person.save()

        self.member = Member(department=self.department,
                             person=self.person,
                             is_active=True)
        self.member.save()

        waitinglist = WaitingList(
            person=self.person,
            department=self.department,
            on_waiting_list_since=datetime.now() - timedelta(days=1),
        )
        waitinglist.save()
        self.waitinglist_id = waitinglist.id
Esempio n. 5
0
class TestModelWaitinglist(TestCase):
    def setUp(self):
        self.union = Union()
        self.union.save()

        self.department = Department(union=self.union)
        self.department.save()

        self.family = Family()
        self.family.save()

        self.person1 = Person(family=self.family)
        self.person1.save()
        self.person1_waitinglist = WaitingList(person=self.person1,
                                               department=self.department)
        self.person1_waitinglist.save()

        # Artifically wait 60 seconds with adding person2 to the waitinglist
        with freeze_time(datetime.now() + timedelta(seconds=60)):
            self.person2 = Person(family=self.family)
            self.person2.save()
            self.person2_waitinglist = WaitingList(person=self.person2,
                                                   department=self.department)
            self.person2_waitinglist.save()

    def test_waiting_list_position(self):
        self.assertEqual(self.person1_waitinglist.number_on_waiting_list(), 1)
        self.assertEqual(self.person2_waitinglist.number_on_waiting_list(), 2)
Esempio n. 6
0
class TestModelActivityParticipant(TestCase):
    # ToDo: Maybe test payment
    def setUp(self):
        self.union = Union()
        self.union.save()

        self.department = Department(
            union=self.union
        )
        self.department.save()

        self.activity = Activity(
            start_date=datetime.now(),
            end_date=datetime.now() + timedelta(days=365),  # Has to be long enough to be a season
            department=self.department
        )
        self.activity.save()
        self.assertTrue(self.activity.is_season())  # If this fail increase the end_date

        self.family = Family(
            email='*****@*****.**'
        )
        self.family.save()

        self.person = Person(
            family=self.family
        )
        self.person.save()

        self.member = Member(
            department=self.department,
            person=self.person,
            is_active=True
        )
        self.member.save()

        waitinglist = WaitingList(
            person=self.person,
            department=self.department,
            on_waiting_list_since=datetime.now() - timedelta(days=1)
        )
        waitinglist.save()
        self.waitinglist_id = waitinglist.id

    def test_save_waiting_list(self):
        self.participant = ActivityParticipant(
            activity=self.activity,
            member=self.member
        )
        self.participant.save()
        self.assertFalse(WaitingList.objects.filter(pk=self.waitinglist_id).exists())
    def setUp(self):
        self.family = Family()
        self.family.save()

        self.person = Person(
            family=self.family
        )
        self.person.save()
Esempio n. 8
0
    def setUp(self):
        self.template = EmailTemplate(
            idname="TEST",
            name="TEMPLATE NAME",
            description="TEMPLATE DESCRIPTION",
            subject="TEMPLATE SUBJECT",
            body_html="TEMPLATE HTML",
            body_text="TEMPLATE TEXT",
        )
        self.template.save()

        self.family = Family(email="*****@*****.**")
        self.family.save()

        self.person = Person(family=self.family)
        self.person.save()

        self.union = UnionFactory()
        self.department = DepartmentFactory(
            union=self.union, department_email="*****@*****.**"
        )
Esempio n. 9
0
    def setUp(self):
        self.union = Union()
        self.union.save()

        self.department = Department(
            union=self.union
        )
        self.department.save()

        self.activity = Activity(
            start_date=datetime.now(),
            end_date=datetime.now() + timedelta(days=365),  # Has to be long enough to be a season
            department=self.department
        )
        self.activity.save()
        self.assertTrue(self.activity.is_season())  # If this fail increase the end_date

        self.family = Family(
            email='*****@*****.**'
        )
        self.family.save()

        self.person = Person(
            family=self.family
        )
        self.person.save()

        waitinglist = WaitingList(
            person=self.person,
            department=self.department,
            on_waiting_list_since=datetime.now() - timedelta(days=1)
        )
        waitinglist.save()
        self.waitinglist_id = waitinglist.id

        self.emailtemplate = EmailTemplate(
            idname='ACT_INVITE',
            from_address='*****@*****.**'
        )
        self.emailtemplate.save()
Esempio n. 10
0
    def setUp(self):
        self.union = Union()
        self.union.save()

        self.department = Department(union=self.union)
        self.department.save()

        self.family = Family()
        self.family.save()

        self.person1 = Person(family=self.family)
        self.person1.save()
        self.person1_waitinglist = WaitingList(person=self.person1,
                                               department=self.department)
        self.person1_waitinglist.save()

        # Artifically wait 60 seconds with adding person2 to the waitinglist
        with freeze_time(datetime.now() + timedelta(seconds=60)):
            self.person2 = Person(family=self.family)
            self.person2.save()
            self.person2_waitinglist = WaitingList(person=self.person2,
                                                   department=self.department)
            self.person2_waitinglist.save()
class TestModelPerson(TestCase):
    def setUp(self):
        self.family = Family()
        self.family.save()

        self.person = Person(family=self.family)
        self.person.save()

    def mock_reference_time(self, time):
        def mock(timezone):
            pass

        return mock

    def test_age_years(self):
        with freeze_time(datetime(2010, 3, 2, 12, 0, 0)):
            self.person.birthday = datetime(2000, 1, 1, 12, 0, 0)
            self.person.save()
            self.assertEqual(self.person.age_years(), 10)

    def test_firstname(self):
        self.person.name = "Foo-Foo Bar Baz"
        self.person.save()
        self.assertEqual(self.person.firstname(), "Foo-Foo")
class TestEmailTemplate(TestCase):
    def setUp(self):
        self.template = EmailTemplate(idname="TEST",
                                      name="TEMPLATE NAME",
                                      description="TEMPLATE DESCRIPTION",
                                      subject="TEMPLATE SUBJECT",
                                      body_html="TEMPLATE HTML",
                                      body_text="TEMPLATE TEXT")
        self.template.save()

        self.family = Family(email="*****@*****.**")
        self.family.save()

        self.person = Person(family=self.family)
        self.person.save()

        self.union = Union(name="",
                           region="S",
                           streetname="",
                           housenumber="1",
                           zipcode="1234",
                           city="")
        self.union.save()

        self.department = Department(
            union=self.union,
            name="",
            streetname="",
            housenumber="1",
            zipcode="1234",
            city="",
            responsible_contact="*****@*****.**")
        self.department.save()

    def util_check_email(self, receivers):
        self.assertEqual(len(mail.outbox), len(receivers))
        self.assertEqual(mail.outbox[0].to,
                         receivers,
                         msg="Email receiver is incorrect")
        self.assertEqual(mail.outbox[0].from_email,
                         "TEST <*****@*****.**>",
                         msg="Email from address is incorrect")
        # Note: breaks if Django decides to swap plain text and html
        self.assertEqual(
            mail.outbox[0].content_subtype,
            "plain",
            msg=
            "Django changed how they handle mail with multiple types (Plain text version broke)"
        )
        self.assertEqual(mail.outbox[0].body, "TEMPLATE TEXT")
        self.assertEqual(
            mail.outbox[0].alternatives[0][1],
            "text/html",
            msg=
            "Django changed how they handle mail with multiple types (HTML version broke)"
        )
        self.assertEqual(mail.outbox[0].alternatives[0][0], "TEMPLATE HTML")

    @override_settings(SITE_CONTACT="TEST <*****@*****.**>")
    def test_send_email_family(self):
        self.template.makeEmail(self.family, {})
        EmailSendCronJob().do()
        self.util_check_email(["*****@*****.**"])

    @override_settings(SITE_CONTACT="TEST <*****@*****.**>")
    def test_send_email_family_no_to_email(self):
        self.family.dont_send_mails = True
        self.family.save()
        self.template.makeEmail(self.family, {})
        EmailSendCronJob().do()
        self.assertEqual(len(mail.outbox), 0)

    @override_settings(SITE_CONTACT="TEST <*****@*****.**>")
    def test_send_email_person(self):
        self.person.email = "*****@*****.**"
        self.person.save()
        self.template.makeEmail(self.person, {})
        EmailSendCronJob().do()
        self.util_check_email(["*****@*****.**"])

    @override_settings(SITE_CONTACT="TEST <*****@*****.**>")
    def test_send_email_person_no_to_email(self):
        self.family.dont_send_mails = True
        self.family.save()
        self.template.makeEmail(self.person, {})
        EmailSendCronJob().do()
        self.assertEqual(len(mail.outbox), 0)

    @override_settings(SITE_CONTACT="TEST <*****@*****.**>")
    def test_send_email_department(self):
        self.template.makeEmail(self.department, {})
        EmailSendCronJob().do()
        self.util_check_email(["*****@*****.**"])
    def setUp(self):
        self.family = Family()
        self.family.save()

        self.person = Person(family=self.family)
        self.person.save()
 def test_email_link(self):
     family = Family(email="*****@*****.**")
     family.save()
     family.send_link_email()
     EmailSendCronJob().do()
     self.assertEqual(len(mail.outbox), 1, msg="Email wasn't")
Esempio n. 15
0
class TestModelActivityInvite(TestCase):
    fixtures = ['templates']

    def setUp(self):
        self.union = Union()
        self.union.save()

        self.department = Department(
            union=self.union
        )
        self.department.save()

        self.activity = Activity(
            start_date=datetime.now(),
            end_date=datetime.now() + timedelta(days=365),  # Has to be long enough to be a season
            department=self.department
        )
        self.activity.save()
        self.assertTrue(self.activity.is_season())  # If this fail increase the end_date

        self.family = Family(
            email='*****@*****.**'
        )
        self.family.save()

        self.person = Person(
            family=self.family
        )
        self.person.save()

        waitinglist = WaitingList(
            person=self.person,
            department=self.department,
            on_waiting_list_since=datetime.now() - timedelta(days=1)
        )
        waitinglist.save()
        self.waitinglist_id = waitinglist.id

        self.emailtemplate = EmailTemplate(
            idname='ACT_INVITE',
            from_address='*****@*****.**'
        )
        self.emailtemplate.save()

    def test_own_email(self):
        self.person.email = '*****@*****.**'
        self.person.save()
        self.invite = ActivityInvite(
            activity=self.activity,
            person=self.person
        )
        self.invite.save()
        EmailSendCronJob().do()
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(len(list(filter(lambda email: email.to == ['*****@*****.**'], mail.outbox))), 1, msg="No email was send to the persons email address")
        self.assertEqual(len(list(filter(lambda email: email.to == ['*****@*****.**'], mail.outbox))), 1, msg="No email wes send to the families email address")

    def test_family_email(self):
        self.person.email = ''
        self.person.save()
        self.invite = ActivityInvite(
            activity=self.activity,
            person=self.person
        )
        self.invite.save()
        EmailSendCronJob().do()
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])

    def test_email_only_once(self):
        self.invite = ActivityInvite(
            activity=self.activity,
            person=self.person
        )
        self.invite.save()
        EmailSendCronJob().do()
        mail.outbox.clear()
        self.invite.save()
        EmailSendCronJob().do()
        self.assertEqual(len(mail.outbox), 0)

    def test_waiting_list(self):
        self.invite = ActivityInvite(
            activity=self.activity,
            person=self.person
        )
        self.invite.save()
        self.assertFalse(WaitingList.objects.filter(pk=self.waitinglist_id).exists())

    def test_clean_age_limit_min(self):
        self.person.birthday = datetime.now() - timedelta(days=365 * 2)
        self.activity.min_age = 4
        self.activity.max_age = 8
        self.invite = ActivityInvite(
            activity=self.activity,
            person=self.person
        )
        with self.assertRaises(ValidationError):
            self.invite.clean()

    def test_clean_age_limit_max(self):
        self.person.birthday = datetime.now() - timedelta(days=365 * 10)
        self.activity.min_age = 4
        self.activity.max_age = 6
        self.invite = ActivityInvite(
            activity=self.activity,
            person=self.person
        )
        with self.assertRaises(ValidationError):
            self.invite.clean()

    def test_clean_age_limit_inbounds(self):
        self.person.birthday = datetime.now() - timedelta(days=365 * 6)
        self.activity.min_age = 4
        self.activity.max_age = 8
        self.invite = ActivityInvite(
            activity=self.activity,
            person=self.person
        )
        self.invite.clean()