예제 #1
0
    def setUp(self):
        self.connection = get_test_conn()
        ep.set_context(self.connection)
        ep.start_session()

        class Ingredient(ep.Object):
            name = ep.f.CharacterVarying(20)

        class Meal(ep.Object):
            name = ep.f.CharacterVarying(20)
            ingredients = ep.rel.OneToMany(Ingredient, dependent=False)

        for meal_name, ingredient_set in [
            ('meal1', ['spam', 'bacon']),
            ('meal2', ['spam', 'eggs', 'bacon']),
            ('meal3', ['spam', 'bacon', 'sausage']),
        ]:
            ingredients = [
                Ingredient(name = ing) for ing in ingredient_set
            ]
            ep.add(*ingredients)
            new_meal = Meal(name = meal_name, ingredients = ingredients)
            ep.add(new_meal)

        ep.commit()

        self.Ingredient = Ingredient
        self.Meal = Meal
예제 #2
0
    def setUp(self):
        class Skit(ep.Object):
            title = ep.f.CharacterVarying(length=16)
            content = ep.f.FileField()

        class Jpeg(ep.Object):
            title = ep.f.CharacterVarying(length=16)
            content = ep.f.FileField(mimetype='image/jpeg')

        self.Skit = Skit
        self.Jpeg = Jpeg
        self.conn = get_test_conn()
        ep.set_context(self.conn)
        ep.start_session()
        parrot = Skit(title='parrot')
        ep.add(parrot)
        parrot.content.filename='parrot.txt'
        parrot.content.write(CONTENT_PARROT)
        hungarian = Skit(title='hungarian')
        ep.add(hungarian)
        hungarian.content.filename='hungarian.txt'
        hungarian.content.mimetype='text/x-rst'
        hungarian.content.write(CONTENT_HUNGARIAN)
        img = Jpeg(title='pythons')
        ep.add(img)
        img.content.import_(os.path.join(HERE, 'pythons.yotpeg'))
        inquisition = Skit(title='inquisition')
        ep.add(inquisition)
        inquisition.content.filename='inquisition'
        inquisition.content.write(CONTENT_INQUISITION)
        ep.commit()
예제 #3
0
 def test_delete(self):
     """Check if no garbage is left after we delete object containg lobject
     """
     ep.start_session()
     parrot = self.Skit.get(1)
     oid = parrot.content.oid
     parrot.delete()
     ep.commit()
     self.assertRaises(OperationalError, lambda: self.conn.lobject(oid))
예제 #4
0
 def test_unlink(self):
     """Check if unlinking an lobject is handled by None'ing a field"""
     ep.start_session()
     parrot = self.Skit.get(1)
     parrot.content.unlink()
     ep.commit()
     ep.start_session()
     parrot = self.Skit.get(1)
     self.assertEqual(parrot.content.read(), '')
예제 #5
0
 def test_non_dependent(self):
     """Test if the orphaned object persists"""
     ep.start_session()
     meal = self.Meal.get(1)
     ing = meal.ingredients[0]
     ing_id = ing.get_pk_value()
     meal.ingredients.pop(0)
     ep.commit()
     ep.start_session()
     ing2 = self.Ingredient.get(ing_id)
     self.assertEqual(ing2.meal, None)
예제 #6
0
 def test_dependent(self):
     """Test if the orphaned object is removed"""
     ep.start_session()
     meal = self.Meal.get(1)
     ing = meal.ingredients[0]
     ing_id = ing.get_pk_value()
     meal.ingredients.pop(0)
     self.assertEqual(ing._status, ORPHANED)
     ep.commit()
     ep.start_session()
     def wrong():
         return self.Ingredient.get(ing_id)
     self.assertRaises(NotFound, wrong)
예제 #7
0
 def test_swap(self):
     """Test if swappin elements from a list from fixture works"""
     ep.start_session()
     meal = self.Meal.get(self.Meal.id == 3)
     ing = meal.ingredients.pop(0)
     meal.ingredients.append(ing)
     ep.commit()
     ep.start_session
     meal = self.Meal.get(self.Meal.id == 3)
     self.assertListEqual(
         [ingredient.name for ingredient in meal.ingredients],
         ['bacon', 'sausage', 'spam'],
     )
예제 #8
0
 def test_replace(self):
     """Replacing full list so __set__ is called"""
     ep.start_session()
     meal = self.Meal.get(1)
     eggs = self.Ingredient.get(2)
     bacon = self.Ingredient.get(3)
     meal.ingredients = [eggs, bacon]
     del meal.ingredients[1]
     ep.commit()
     ep.start_session()
     self.assertSetEqual(
         set([i.name for i in meal.ingredients]),
         set(['eggs'])
     )
예제 #9
0
    def setUp(self):
        class Image(ep.Object):
            image = ep.f.Image()
            thumb = ep.f.Thumb(origin=image, size=(100, 100))

        self.Image = Image
        self.conn = get_test_conn()
        ep.set_context(self.conn)
        ep.start_session()
        img = pystacia.read(os.path.join(HERE, 'pythons.yotpeg'))
        img.filename = 'pythons.jpeg'
        pythons = Image(image=img)
        ep.add(pythons)
        ep.commit()
예제 #10
0
 def test_swap_as_new(self):
     """Test swapping, but this time we set a completely new list"""
     ep.start_session()
     meal = self.Meal.get(self.Meal.id == 3)
     new_ings = meal.ingredients[:]
     ing = new_ings.pop(0)
     new_ings.append(ing)
     meal.ingredients = new_ings
     ep.commit()
     ep.start_session
     meal = self.Meal.get(self.Meal.id == 3)
     self.assertListEqual(
         [ingredient.name for ingredient in meal.ingredients],
         ['bacon', 'sausage', 'spam'],
     )
예제 #11
0
 def test_move(self):
     """Test if you can safely move a dependent object without it getting
     deleted"""
     ep.start_session()
     meal1 = self.Meal.get(1)
     meal2 = self.Meal.get(2)
     ing = meal1.ingredients.pop(0)
     ing_id = ing.id
     meal2.ingredients.append(ing)
     ep.commit()
     ep.start_session()
     meal1 = self.Meal.get(1)
     meal2 = self.Meal.get(2)
     ing = self.Ingredient.get(ing_id)
     self.assertEqual(len(meal1.ingredients), 1)
     self.assertEqual(len(meal2.ingredients), 4)
예제 #12
0
    def setUp(self):
        @ep.object.tree
        class Thing(Object):
            name = ep.field.CharacterVarying(30)

        self.connection = get_test_conn()
        ep.set_context(self.connection)
        animals = Thing(name='Animals')
        birds = Thing(name = 'Birds', parent=animals)
        mammals = Thing(name = 'Mammals', parent=animals)
        tiger = Thing(name = 'Tiger', parent=mammals)
        swallow = Thing(name = 'Swallow', parent=birds)
        european = Thing(name = 'European Swallow', parent=swallow)
        african = Thing(name = 'African Swallow', parent=swallow)
        ep.start_session()
        ep.add(animals, birds, mammals, tiger, swallow, european, african)
        ep.commit() 
        self.Thing = Thing
    def setUp(self):
        self.connection = get_test_conn()
        ep.set_context(self.connection)
        ep.start_session()
        class Food(ep.Object):
            name = ep.f.CharacterVarying(20)
            ingredients = ep.rel.ManyToMany()

        spam = Food(name='spam')
        eggs = Food(name='eggs')
        bacon = Food(name='bacon')
        sausage = Food(name='sausage')

        meal1 = Food(name='meal1', ingredients=[spam, bacon])
        meal2 = Food(name='meal2', ingredients=[spam, eggs, bacon])
        meal3 = Food(name='meal3', ingredients=[spam, bacon, sausage])
        ep.add(spam, eggs, bacon, sausage, meal1, meal2, meal3)
        self.Food = Food
        ep.commit()
 def setUp(self):
     class Character(Object):
         name = f.CharacterVarying(length = 20)
         
     class Knight(Character):
         nickname = f.CharacterVarying(length = 20)
         
     
     self.connection = get_test_conn()
     ep.set_context(self.connection)
     ep.start_session()
     
     ep.add(Character(name = 'Arthur'))
     ep.add(Character(name = 'Patsy'))
     ep.add(Knight(name = 'Robin', nickname = 'The Brave'))
     ep.add(Knight(name = 'Galahad', nickname = 'The Pure'))
     ep.commit()
     
     self.Character = Character
     self.Knight = Knight
    def test_eaft_relation(self):
        """
        This is a special test to create a related table when object depending
        on it (but with foreign key = NULL) is flushed
        """

        class Movie(ep.Object):
            title = ep.f.CharacterVarying(30)

        class Character(ep.Object):
            name = ep.f.CharacterVarying(30)
            movie = ep.rel.ManyToOne(Movie)

        c = Character(name="Nobody important", movie = None)

        self.connection = get_test_conn()
        ep.set_context(self.connection)
        ep.start_session()

        ep.add(c)
        ep.commit()
예제 #16
0
    def setUp(self):
        class Knight(ep.Object):
            title = f.CharacterVarying(length=5, null=False, default="Sir")
            name = f.CharacterVarying(length=20, null=False)
            nickname = f.CharacterVarying(length=20, null=True)
            score = f.Integer()

        self.Knight = Knight
        ep.set_context(get_test_conn())
        ep.start_session()

        for ktup in [
            ("Sir", "Galahad", "The Pure", 10),
            ("King", "Arthur", None, 20),
            ("Sir", "Robin", "The Brave", 30),
            ("Sir", "Lancelot", None, 40),
        ]:
            title, name, nickname, score = ktup
            k = Knight(title=title, name=name, nickname=nickname, score=score)
            ep.add(k)

        ep.commit()
예제 #17
0
    def setUp(self):
        class Ingredient(ep.Object):
            name = ep.f.CharacterVarying(20)

        class Meal(ep.Object):
            name = ep.f.CharacterVarying(20)
            ingredients = ep.rel.ManyToMany(Ingredient)

        self.connection = get_test_conn()
        ep.set_context(self.connection)

        spam = Ingredient(name='spam')
        eggs = Ingredient(name='eggs')
        bacon = Ingredient(name='bacon')
        sausage = Ingredient(name='sausage')
        ep.start_session()
        ep.add(spam, eggs, bacon, sausage)
        meal1 = Meal(name='meal1', ingredients=[spam, bacon])
        meal2 = Meal(name='meal2', ingredients=[spam, eggs, bacon])
        meal3 = Meal(name='meal3', ingredients=[spam, bacon, sausage])
        ep.add(meal1, meal2, meal3)
        self.Meal = Meal
        self.Ingredient = Ingredient
        ep.commit()