Exemplo n.º 1
0
    def create_large_educatives_and_seminar(cls):
        NUMBER_OF_KENS = 50
        NUMBER_OF_EDUCATIVES = 900
        NUMBER_OF_HUGS = 45
        NUMBER_OF_VEGETARIAN_HUGS = 8

        kens = []
        for i in xrange(NUMBER_OF_KENS):
            ken = Ken()
            ken.name = "Ken " + str(i)
            kens.append(ken)
            cls.session.add(ken)

        educatives = []
        for i in xrange(NUMBER_OF_EDUCATIVES):
            educative = Educative()
            if random.randint(0, 2) == 0:
                educative.gender = MALE
            else:
                educative.gender = FEMALE
            if random.randint(0, 9) == 0:
                educative.food = VEGETARIAN
            else:
                educative.food = MEAT
            educative.first_name = "Educative"
            educative.last_name = str(i)
            educative.ken = kens[random.randint(0, NUMBER_OF_KENS - 1)]
            educatives.append(educative)
            cls.session.add(educative)

        seminar = Seminar()
        seminar.name = 'Seminar'
        cls.session.add(seminar)

        camp1, camp2, camp3 = Camp(), Camp(), Camp()
        camp1.name = 'Camp 1'
        camp2.name = 'Camp 2'
        camp3.name = 'Camp3'
        seminar.camps += [camp1, camp2, camp3]
        [cls.session.add(c) for c in seminar.camps]

        hugs = []
        for i in xrange(NUMBER_OF_HUGS):
            hug = Hug()
            hug.name = "Hug " + str(i)
            hug.camp = seminar.camps[i % 3]
            if i < NUMBER_OF_VEGETARIAN_HUGS:
                hug.food = VEGETARIAN
            hugs.append(hug)
            cls.session.add(hug)
            for j in xrange(random.randint(1, 2)):
                madrich = Madrich()
                madrich.first_name = "Madrich"
                madrich.last_name = str(j)
                madrich.ken = kens[random.randint(0, NUMBER_OF_KENS - 1)]
                hug.madrichim.append(madrich)
                cls.session.add(madrich)

        return educatives, seminar
Exemplo n.º 2
0
    def test_madrich(self):
        ken = Ken()
        ken.name = 'Misgav'
        
        seminar = self.create_seminar(1, 1)
        hug = seminar.camps[0].hugs[0]

        aviad = Educative()
        aviad.first_name = 'Aviad'
        aviad.ken = ken
        aviad.hug = hug
        
        madrich = Madrich()
        madrich.first_name = 'Cool'
        madrich.last_name = 'Guy'
        madrich.ken = ken
        madrich.hug = hug
        
        constraint = MadrichHardConstraint()
        self.assertTrue(not constraint.is_valid(aviad, [aviad], seminar))