def test_get_by_child(self):
        departments = [DepartmentFactory(), DepartmentFactory()]
        persons = [PersonFactory(), PersonFactory()]

        # Not on wainting list yet
        self.assertEqual(len(WaitingList.get_by_child(persons[0])), 0)

        # Sign up for waiting LIst
        WaitingListFactory(person=persons[0], department=departments[0])
        WaitingListFactory(person=persons[1], department=departments[0])

        self.assertEqual(WaitingList.get_by_child(persons[0]),
                         [(departments[0], 1)])
        self.assertEqual(WaitingList.get_by_child(persons[1]),
                         [(departments[0], 2)])

        # Sign up for more
        WaitingListFactory(person=persons[1], department=departments[1])
        WaitingListFactory(person=persons[0], department=departments[1])

        # Checks for Ordering
        self.assertEqual(
            WaitingList.get_by_child(persons[0]),
            [(departments[0], 1), (departments[1], 1)],
        )
        self.assertEqual(
            WaitingList.get_by_child(persons[1]),
            [(departments[0], 2), (departments[1], 2)],
        )
Example #2
0
    def test_saving_and_retrieving_family(self):
        family = FamilyFactory()
        PersonFactory(family=family)
        PersonFactory(family=family, membertype=Person.CHILD)

        self.assertEqual(family, Family.objects.first())
        self.assertEqual(1, Family.objects.count())
        self.assertEqual(2, Person.objects.count())
Example #3
0
    def test_saving_and_retrieving_persons(self):
        PersonFactory(name="Jane Doe",
                      added=datetime(2018, 1, 1, tzinfo=TIMEZONE))
        PersonFactory(name="John Doe",
                      added=datetime(2017, 1, 1, tzinfo=TIMEZONE))

        saved_persons = Person.objects.all()
        self.assertEqual(saved_persons.count(), 2)

        # retrieved in order of 'added' field
        self.assertEqual(saved_persons[0].name, "John Doe")
        self.assertEqual(saved_persons[1].name, "Jane Doe")
    def test_different_waitinglists_does_not_interfere(self):
        department0 = DepartmentFactory()
        department1 = DepartmentFactory()
        person = PersonFactory()
        subscription0 = WaitingListFactory(person=person,
                                           department=department0)
        subscription1 = WaitingListFactory(person=person,
                                           department=department1)

        self.assertEqual(1, subscription0.number_on_waiting_list())
        self.assertEqual(1, subscription1.number_on_waiting_list())

        fake = faker.Faker()

        # Add a lot of people with random sign-up dates to the second
        # list.
        # NB. fake.date_time() only returns past datetimes, thus all
        # subscriptions will be added infront of our new person, not
        # after
        n = 30
        for i in range(n):
            WaitingListFactory(person__added=fake.date_time(tzinfo=TIMEZONE),
                               department=department1)

        # Should not interfere with position on the first list
        self.assertEqual(1, subscription0.number_on_waiting_list())

        # We are placed last on the second waiting list
        self.assertEqual(n + 1, subscription1.number_on_waiting_list())
Example #5
0
 def setUp(self):
     self.person = PersonFactory.create()
     self.password = "******"
     self.name = "kaptajn hack"
     self.admin = User.objects.create_superuser(self.name,
                                                "*****@*****.**",
                                                self.password)
     self.browser = webdriver.Remote("http://selenium:4444/wd/hub",
                                     DesiredCapabilities.CHROME)
Example #6
0
 def setUp(self):
     self.email = "*****@*****.**"
     self.browser = webdriver.Remote("http://selenium:4444/wd/hub",
                                     DesiredCapabilities.CHROME)
     self.family = FamilyFactory()
     self.person = PersonFactory.create(family=self.family)
     self.first_kid = PersonFactory.create(family=self.family,
                                           membertype="CH")
     self.second_kid = PersonFactory.create(family=self.family,
                                            membertype="CH")
     self.activity = ActivityFactory.create(
         start_date=date.today(),
         signup_closing=date.today(),
         open_invite=True,
         max_participants=2,
         min_age=0,
         max_age=100,
     )
 def test_get_children(self):
     family = FamilyFactory()
     kids = [
         PersonFactory(membertype=Person.CHILD, family=family)
         for i in range(randint(1, 10))
     ]
     family_kids = family.get_children()
     for kid in kids:
         self.assertTrue(kid in family_kids)
     self.assertEqual(len(kids), len(family_kids))
Example #8
0
 def test_defaults_to_parent(self):
     person = PersonFactory()
     self.assertEqual(person.membertype, Person.PARENT)
Example #9
0
    def setUp(self):
        self.email = "*****@*****.**"
        self.password = "******"
        self.member = MemberFactory.create(person=PersonFactory.create(
            birthday=Faker("date_between", start_date="-50y", end_date="-10y"),
            user=UserFactory.create(
                username=self.email, email=self.email, password=self.password),
        ))
        self.member.person.user.set_password(self.password)
        self.member.person.user.save()
        self.member.person.birthday = datetime.date(1980, 1, 10)

        self.activity_arrangement = ActivityFactory.create(
            open_invite=True,
            signup_closing=Faker("future_datetime", end_date="+100d"),
            min_age=5,
            max_age=90,
            name="Arrangement",
            activitytype_id="ARRANGEMENT",
        )
        self.activity_arrangement.save()
        self.activity_arrangement_participate = ActivityFactory.create(
            name="Arrangement deltagelse", activitytype_id="ARRANGEMENT")
        self.activity_arrangement_participate.save()
        ActivityParticipantFactory.create(
            activity=self.activity_arrangement_participate,
            member=self.member).save()
        self.activity_forløb = ActivityFactory.create(
            open_invite=True,
            signup_closing=Faker("future_datetime", end_date="+100d"),
            min_age=5,
            max_age=90,
            name="Forløb",
            activitytype_id="FORLØB",
        )
        self.activity_forløb.save()
        self.activity_forløb_participate = ActivityFactory.create(
            name="Forløb deltagelse", activitytype_id="FORLØB")
        self.activity_forløb_participate.save()
        ActivityParticipantFactory.create(
            activity=self.activity_forløb_participate,
            member=self.member).save()
        self.activity_foreningsmedlemskab = ActivityFactory.create(
            open_invite=True,
            signup_closing=Faker("future_datetime", end_date="+100d"),
            min_age=5,
            max_age=90,
            name="Foreningsmedlemskab",
            activitytype_id="FORENINGSMEDLEMSKAB",
        )
        self.activity_foreningsmedlemskab.save()
        self.activity_foreningsmedlemskab_participate = ActivityFactory.create(
            name="Foreningsmedlemskab deltagelse",
            activitytype_id="FORENINGSMEDLEMSKAB")
        self.activity_foreningsmedlemskab_participate.save()
        ActivityParticipantFactory.create(
            activity=self.activity_foreningsmedlemskab_participate,
            member=self.member).save()
        self.activity_støttemedlemskab = ActivityFactory.create(
            open_invite=True,
            signup_closing=Faker("future_datetime", end_date="+100d"),
            min_age=5,
            max_age=90,
            name="Støttemedlemskab",
            activitytype_id="STØTTEMEDLEMSKAB",
        )
        self.activity_støttemedlemskab.save()
        self.activity_støttemedlemskab_participate = ActivityFactory.create(
            name="Støttemedlemskab deltagelse",
            activitytype_id="STØTTEMEDLEMSKAB")
        self.activity_støttemedlemskab_participate.save()
        ActivityParticipantFactory.create(
            activity=self.activity_støttemedlemskab_participate,
            member=self.member).save()

        self.browser = webdriver.Remote("http://*****:*****@value='Log ind']").click()
        self.browser.save_screenshot("test-screens/activities_logged_in.png")
 def test_cannot_create_person_with_no_name(self):
     with self.assertRaises(ValidationError):
         person = PersonFactory(name="")
         person.full_clean()
 def test_firstname_allows_dash_in_names(self):
     person = PersonFactory(name="Hans-Christian Jensen Eriksen")
     self.assertEqual(person.firstname(), "Hans-Christian")
 def test_build_many(self):
     persons = PersonFactory.build_batch(size=20)
     self.assertEqual(len(persons), 20)
     self.assertEqual(Person.objects.count(), 0)
     self.assertFalse(Person.objects.exists())
def _create_person_with_id(id):
    if len(Person.objects.filter(pk=id)) == 0:
        return PersonFactory(pk=id)
Example #14
0
 def test_get_first_parent(self):
     family = FamilyFactory()
     p1 = PersonFactory(family=family, membertype=Person.PARENT)
     PersonFactory(family=family, membertype=Person.PARENT)
     PersonFactory(family=family, membertype=Person.CHILD)
     self.assertEqual(p1, family.get_first_parent())
Example #15
0
 def test_defaults_to_not_deleted(self):
     person = PersonFactory()
     self.assertEqual(person.deleted_dtm, None)
Example #16
0
 def test_can_create_person(self):
     PersonFactory()  # no error should be thrown
Example #17
0
 def test_age_years(self):
     with freeze_time(datetime(2010, 3, 2)):
         person = PersonFactory(birthday=datetime(2000, 1, 1))
         self.assertEqual(person.age_years(), 10)
Example #18
0
 def test_defaults_to_no_certificate(self):
     person = PersonFactory()
     self.assertEqual(person.has_certificate, None)
Example #19
0
 def test_build_many(self):
     persons = PersonFactory.build_batch(size=20)
     self.assertEqual(len(persons), 20)
     self.assertEqual(Person.objects.count(), 0)
     self.assertFalse(Person.objects.exists())
Example #20
0
 def test_get_first_parent_none_when_no_parents(self):
     family = FamilyFactory()
     PersonFactory(family=family, membertype=Person.CHILD)
     self.assertIsNone(family.get_first_parent())
Example #21
0
 def test_creating_many(self):
     PersonFactory.create_batch(size=20)
     self.assertEqual(Person.objects.count(), 20)
Example #22
0
 def test_get_first_parent_when_guardian(self):
     family = FamilyFactory()
     p1 = PersonFactory(family=family, membertype=Person.GUARDIAN)
     PersonFactory(family=family, membertype=Person.PARENT)
     PersonFactory(family=family, membertype=Person.PARENT)
     self.assertEqual(p1, family.get_first_parent())
Example #23
0
 def test_firstname_allows_dash_in_names(self):
     person = PersonFactory(name="Hans-Christian Jensen Eriksen")
     self.assertEqual(person.firstname(), "Hans-Christian")
 def test_age_years(self):
     with freeze_time(datetime(2010, 3, 2)):
         person = PersonFactory(birthday=datetime(2000, 1, 1))
         self.assertEqual(person.age_years(), 10)
Example #25
0
 def test_firstname_no_lastname(self):
     person = PersonFactory(name="Margrethe")
     self.assertEqual(person.firstname(), "Margrethe")
 def test_creating_many(self):
     PersonFactory.create_batch(size=20)
     self.assertEqual(Person.objects.count(), 20)
Example #27
0
 def test_cannot_create_person_with_no_name(self):
     with self.assertRaises(ValidationError):
         person = PersonFactory(name="")
         person.full_clean()
 def test_firstname_no_lastname(self):
     person = PersonFactory(name="Margrethe")
     self.assertEqual(person.firstname(), "Margrethe")
Example #29
0
 def test_cannot_change_person_to_unnamed(self):
     person = PersonFactory()
     with self.assertRaises(ValidationError):
         person.name = ""
         person.full_clean()
 def test_cannot_change_person_to_unnamed(self):
     person = PersonFactory()
     with self.assertRaises(ValidationError):
         person.name = ""
         person.full_clean()
Example #31
0
 def test_string_representation(self):
     person = PersonFactory()
     self.assertEqual(person.name, str(person))