Example #1
0
 def get_meal(self, date, index):
     try:
         meal = (Session.query(Meal).filter(
             and_(Meal.date == date, Meal.index == index)).one())
     except NoResultFound:
         meal = Meal(date, index)
         Session.add(meal)
     return meal
Example #2
0
 def get_meal(self, date, index):
     try:
         meal = (Session.query(Meal).
                 filter(and_(Meal.date == date, Meal.index == index))
                 .one())
     except NoResultFound:
         meal = Meal(date, index)
         Session.add(meal)
     return meal
Example #3
0
    def _get_one(self):
        self.recipe = Recipe('carbo')
        self.m1 = Meal(datetime.date(2010, 01, 01), 0, [self.recipe])
        self.m2 = Meal(datetime.date(2010, 01, 05), 1, [self.recipe])
        Session.add_all([self.recipe, self.m1, self.m2])

        fro = datetime.date(2010, 01, 01)
        to = datetime.date(2010, 01, 10)
        pw = PlanningWidget(fro, to)
        return pw
Example #4
0
    def _get_one(self):
        self.recipe = Recipe('carbo')
        self.m1 = Meal(datetime.date(2010, 01, 01), 0, [self.recipe])
        self.m2 = Meal(datetime.date(2010, 01, 05), 1, [self.recipe])
        Session.add_all([self.recipe, self.m1, self.m2])

        fro = datetime.date(2010, 01, 01)
        to = datetime.date(2010, 01, 10)
        pw = PlanningWidget(fro, to)
        return pw
Example #5
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Delete:
         # Pas de confirmation, pas de sauvegarde : on est des oufs !
         ids = [item.data(Qt.UserRole) for item in self.selectedItems()]
         Session.query(Recipe).filter(Recipe.id.in_(ids)).delete('fetch')
         self.reload()
     elif event.key() == Qt.Key_N:
         self.editRecipe(None)
     else:
         super(RecipesWidget, self).keyPressEvent(event)
Example #6
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Delete:
         # Pas de confirmation, pas de sauvegarde : on est des oufs !
         ids = [item.data(Qt.UserRole) for item in self.selectedItems()]
         Session.query(Recipe).filter(Recipe.id.in_(ids)).delete('fetch')
         self.reload()
     elif event.key() == Qt.Key_N:
         self.editRecipe(None)
     else:
         super(RecipesWidget, self).keyPressEvent(event)
Example #7
0
    def test_remove_recipe(self):
        rw = RecipesWidget()
        self.assertEqual(len(rw.selectedItems()), 0)
        before = Session.query(Recipe).count()

        rw.item(0).setSelected(True)
        rw.item(3).setSelected(True)
        QTest.keyClick(rw, Qt.Key_Delete)

        self.assertEqual(Session.query(Recipe).count(), before - 2)
        self.assertEqual(rw.count(), before - 2)
Example #8
0
    def test_cant_add_twice_the_same_even_after_reload(self):
        tw = TagsWidget()
        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()
        Session.add(Tag(u'Another tag'))
        tw.reload()

        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()

        self.assertEqual(tw.listWidget.count(), 1)
Example #9
0
    def test_remove_recipe(self):
        rw = RecipesWidget()
        self.assertEqual(len(rw.selectedItems()), 0)
        before = Session.query(Recipe).count()

        rw.item(0).setSelected(True)
        rw.item(3).setSelected(True)
        QTest.keyClick(rw, Qt.Key_Delete)

        self.assertEqual(Session.query(Recipe).count(), before - 2)
        self.assertEqual(rw.count(), before - 2)
Example #10
0
    def test_cant_add_twice_the_same_even_after_reload(self):
        tw = TagsWidget()
        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()
        Session.add(Tag(u'Another tag'))
        tw.reload()

        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()

        self.assertEqual(tw.listWidget.count(), 1)
Example #11
0
    def test_we_got_the_right_meals(self):
        recipe = Recipe('carbo')
        m1 = Meal(datetime.date(2010, 01, 01), 0, [recipe])
        m2 = Meal(datetime.date(2010, 01, 05), 0, [recipe])
        m3 = Meal(datetime.date(2010, 01, 12), 1, [recipe])
        Session.add_all((recipe, m1, m2, m3))

        obj = mock.Mock(PlanningWidget)
        obj.fro = datetime.date(2010, 01, 01)
        obj.to = datetime.date(2010, 01, 10)

        self.assertEqual(PlanningWidget._meals_in_range(obj), [m1, m2])
Example #12
0
    def test_we_got_the_right_meals(self):
        recipe = Recipe('carbo')
        m1 = Meal(datetime.date(2010, 01, 01), 0, [recipe])
        m2 = Meal(datetime.date(2010, 01, 05), 0, [recipe])
        m3 = Meal(datetime.date(2010, 01, 12), 1, [recipe])
        Session.add_all((recipe, m1, m2, m3))

        obj = mock.Mock(PlanningWidget)
        obj.fro = datetime.date(2010, 01, 01)
        obj.to = datetime.date(2010, 01, 10)

        self.assertEqual(PlanningWidget._meals_in_range(obj),
                         [m1, m2])
Example #13
0
    def test_create_recipe(self):
        fut = RecipeEditionDialog()
        self.assertEqual(fut.name.text(), '')
        self.assertEqual(fut.description.toPlainText(), '')
        self.assertEqual(fut.tags.text(), '')

        fut.name.setText(u'Endive')
        fut.description.setPlainText(u'desc')
        fut.tags.setText(u'légume')
        tag = Tag(u'légume')
        Session.add(tag)

        fut.accept()

        r = fut.recipe
        self.assertEqual(r.name, u'Endive')
        self.assertEqual(r.description, u'desc')
        self.assertEqual(r.tags, [tag])
Example #14
0
 def reload(self):
     tags = Session.query(Tag.name, Tag.id).all()
     self.tagsdict = dict(tags)
     self.availableTags = self.tagsdict.keys()
     for i in xrange(self.listWidget.count()):
         tag = self.listWidget.item(i).text()
         if tag in self.availableTags:
             self.availableTags.remove(tag)
     self.lineEdit.completer().model().setStringList(self.availableTags)
Example #15
0
    def test_create_recipe(self):
        fut = RecipeEditionDialog()
        self.assertEqual(fut.name.text(), '')
        self.assertEqual(fut.description.toPlainText(), '')
        self.assertEqual(fut.tags.text(), '')

        fut.name.setText(u'Endive')
        fut.description.setPlainText(u'desc')
        fut.tags.setText(u'légume')
        tag = Tag(u'légume')
        Session.add(tag)

        fut.accept()

        r = fut.recipe
        self.assertEqual(r.name, u'Endive')
        self.assertEqual(r.description, u'desc')
        self.assertEqual(r.tags, [tag])
Example #16
0
 def reload(self):
     tags = Session.query(Tag.name, Tag.id).all()
     self.tagsdict = dict(tags)
     self.availableTags = self.tagsdict.keys()
     for i in xrange(self.listWidget.count()):
         tag = self.listWidget.item(i).text()
         if tag in self.availableTags:
             self.availableTags.remove(tag)
     self.lineEdit.completer().model().setStringList(self.availableTags)
Example #17
0
    def test_edit_recipe(self):
        r = self.recipes[1]
        fut = RecipeEditionDialog(r)
        self.assertEqual(fut.name.text(), r.name)
        self.assertEqual(fut.description.toPlainText(), r.description)
        self.assertIn(fut.tags.text(), [u'pâtes;tomate', u'tomate;pâtes'])

        fut.name.setText(u'Endive')
        fut.description.setPlainText(u'desc')
        fut.tags.setText(u'légume')
        tag = Tag(u'légume')
        Session.add(tag)

        fut.accept()

        r = fut.recipe
        self.assertEqual(r.name, u'Endive')
        self.assertEqual(r.description, u'desc')
        self.assertEqual(r.tags, [tag])
Example #18
0
    def test_getting_the_entered_tags(self):
        tw = TagsWidget()

        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()

        expected = [t.id for t in Session.query(Tag.id)
                                         .filter(Tag.name == u'lourd')
                                         .all()]
        self.assertEqual(tw.tags(), expected)
Example #19
0
    def test_edit_recipe(self):
        r = self.recipes[1]
        fut = RecipeEditionDialog(r)
        self.assertEqual(fut.name.text(), r.name)
        self.assertEqual(fut.description.toPlainText(), r.description)
        self.assertIn(fut.tags.text(), [u'pâtes;tomate',
                                        u'tomate;pâtes'])

        fut.name.setText(u'Endive')
        fut.description.setPlainText(u'desc')
        fut.tags.setText(u'légume')
        tag = Tag(u'légume')
        Session.add(tag)

        fut.accept()

        r = fut.recipe
        self.assertEqual(r.name, u'Endive')
        self.assertEqual(r.description, u'desc')
        self.assertEqual(r.tags, [tag])
Example #20
0
    def test_getting_the_entered_tags(self):
        tw = TagsWidget()

        QTest.keyClicks(tw.lineEdit, 'lourd')
        tw.addTag()

        expected = [
            t.id
            for t in Session.query(Tag.id).filter(Tag.name == u'lourd').all()
        ]
        self.assertEqual(tw.tags(), expected)
Example #21
0
def load_some_tags():
    t1 = Tag(u'pâtes')
    t2 = Tag(u'tomate')
    r1 = Recipe(u'carbonara')
    r1.tags = [t1]
    r2 = Recipe(u'bolognaise')
    r2.tags = [t1, t2]
    r3 = Recipe(u'tomates farcies')
    r3.tags = [t2]
    r4 = Recipe(u'saucisses-purée')

    tags = [t1, t2]
    recipes = [r1, r2, r3, r4]
    Session.add_all(tags)
    Session.add_all(recipes)
    Session.flush()
    return tags, recipes
Example #22
0
def load_some_tags():
    t1 = Tag(u'pâtes')
    t2 = Tag(u'tomate')
    r1 = Recipe(u'carbonara')
    r1.tags = [t1]
    r2 = Recipe(u'bolognaise')
    r2.tags = [t1, t2]
    r3 = Recipe(u'tomates farcies')
    r3.tags = [t2]
    r4 = Recipe(u'saucisses-purée')

    tags = [t1, t2]
    recipes = [r1, r2, r3, r4]
    Session.add_all(tags)
    Session.add_all(recipes)
    Session.flush()
    return tags, recipes
Example #23
0
 def add_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.append(recipe)
     self.widgets[(date, index)].addRecipe(recipe)
Example #24
0
 def setUp(self):
     super(TagsWidgetTestCase, self).setUp()
     Session.add_all(Tag(t) for t in [u'lourd', u'pâtes', u'hiver'])
     self.app = get_app()
Example #25
0
 def remove_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.remove(recipe)
     self.widgets[(date, index)].removeRecipe(recipe)
Example #26
0
 def doubleClick(self, item):
     recipe = Session.query(Recipe).get(item.data(Qt.UserRole))
     self.editRecipe(recipe)
Example #27
0
def get_recipes(tags=()):
    recipes = Session.query(Recipe)
    for t in tags:
        recipes = recipes.filter(Recipe.tags.any(Tag.id == t))
    return recipes.all()
Example #28
0
    def test_get_existing_tag(self):
        t = Tag('yay')
        Session.add(t)

        self.assertEqual(t, Tag.get('yay'))
Example #29
0
 def _meals_in_range(self):
     return (Session.query(Meal).options(joinedload('recipes'))
             .filter(and_(self.fro <= Meal.date, Meal.date < self.to))
             .all())
Example #30
0
    def test_get_existing_tag(self):
        t = Tag('yay')
        Session.add(t)

        self.assertEqual(t, Tag.get('yay'))
Example #31
0
 def doubleClick(self, item):
     recipe = Session.query(Recipe).get(item.data(Qt.UserRole))
     self.editRecipe(recipe)
Example #32
0
def get_recipes(tags=()):
    recipes = Session.query(Recipe)
    for t in tags:
        recipes = recipes.filter(Recipe.tags.any(Tag.id == t))
    return recipes.all()
Example #33
0
 def save_recipe(self):
     self.recipe.name = self.name.text()
     self.recipe.description = self.description.toPlainText()
     self.recipe.tags = [Tag.get(t) for t in self.tags.text().split(';')
                         ] if self.tags.text() else []
     Session.add(self.recipe)
Example #34
0
 def remove_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.remove(recipe)
     self.widgets[(date, index)].removeRecipe(recipe)
Example #35
0
 def add_recipe(self, id, date, index):
     meal = self.get_meal(date, index)
     recipe = Session.query(Recipe).get(id)
     meal.recipes.append(recipe)
     self.widgets[(date, index)].addRecipe(recipe)
Example #36
0
 def setUp(self):
     super(TagsWidgetTestCase, self).setUp()
     Session.add_all(Tag(t) for t in [u'lourd', u'pâtes', u'hiver'])
     self.app = get_app()
Example #37
0
 def save_recipe(self):
     self.recipe.name = self.name.text()
     self.recipe.description = self.description.toPlainText()
     self.recipe.tags = [Tag.get(t) for t in self.tags.text().split(';')] if self.tags.text() else []
     Session.add(self.recipe)
Example #38
0
 def _meals_in_range(self):
     return (Session.query(Meal).options(joinedload('recipes')).filter(
         and_(self.fro <= Meal.date, Meal.date < self.to)).all())
Example #39
0
 def tearDown(self):
     super(TestCase, self).tearDown()
     from re_eat.models import Session
     Session.remove()