Beispiel #1
0
class GroupTestCompositionOperations(TestCase):

    fixtures = ['people1.json']

    def setUp(self):
        self.group1 = Group(gtype="gpe", gdomain="gen", gsource="man",
                      code="test1", abbr="test1", title="Test group 1",
                      description="")
        self.group1.save()
        self.group2 = Group(gtype="gpe", gdomain="gen", gsource="man",
                      code="test2", abbr="test2", title="Test group 2",
                      description="")
        self.group2.save()
        self.start = datetime.datetime.now(timezone.get_default_timezone())\
             - datetime.timedelta(days=30)
        self.end = self.start + datetime.timedelta(days=300)
        self.people1 = list(get_user_model().objects.all())
        self.people2 = list(get_user_model().objects.filter(pk__lte=2))
        self.people3 = list(get_user_model().objects.filter(pk__gt=2))
        self.people4 = list(get_user_model().objects.filter(pk=2))

    def test_group_composition_operations(self):
        self.group1.new_main_composition(self.people1, self.start, self.end)
        self.group1.update_current_composition(people=self.people4,
                                               operation="-",
                                               datestart=self.start)
        self.assertEqual(self.group1.get_people_by_date().count(), 3)

        self.group2.new_main_composition(self.people2, self.start, self.end)
        self.assertEqual(self.group2.get_people_by_date().count(), 3)
        self.group2.update_current_composition(people=self.people3,
                                               operation="U",
                                               datestart=self.start)
        self.assertEqual(self.group2.get_people_by_date().count(), 4)
        self.group2.update_current_composition(people=self.people3,
                                               operation="U",
                                               datestart=self.start)
        self.group2.update_current_composition(group=self.group1,
                                               operation="I",
                                               datestart=self.start)
        self.assertEqual(self.group2.get_people_by_date().count(), 3)
Beispiel #2
0
    def test_group_composition(self):
        group = Group(gtype="gpe", gdomain="gen", gsource="man",
                      code="test", abbr="test", title="Test group",
                      description="")
        group.save()
        start = datetime.datetime.now(timezone.get_default_timezone())\
             - datetime.timedelta(days=30)
        end = start + datetime.timedelta(days=300)
        people = list(get_user_model().objects.all())
        group.new_main_composition(people, start, end)
        self.assertEqual(group.get_people_by_date(
            start + datetime.timedelta(days=3)).count(), 4)
        self.assertEqual(group.get_people_by_date(
            start - datetime.timedelta(days=3)).count(), 0)
        self.assertEqual(group.get_people_by_date(
            start + datetime.timedelta(days=350)).count(), 0)
        self.assertEqual(DjangoGroup.objects.get(name="link_1").\
                         person_set.count(), 4)

        # Testing group main composition updates
        group.update_main_composition(people,
                                      start + datetime.timedelta(days=15),
                                      start + datetime.timedelta(days=200))

        people = list(get_user_model().objects.all().filter(pk__gt=1))
        group.update_main_composition(people,
                                      start + datetime.timedelta(days=20),
                                      start + datetime.timedelta(days=180))
        self.assertEqual(group.get_people_by_date(
            start + datetime.timedelta(days=10)).count(), 4)
        self.assertEqual(group.get_people_by_date(
            start + datetime.timedelta(days=17)).count(), 4)
        self.assertEqual(group.get_people_by_date(
            start + datetime.timedelta(days=23)).count(), 2)
        self.assertEqual(DjangoGroup.objects.get(name="link_1").\
                         person_set.count(), 2)