Ejemplo n.º 1
0
def test_ingredient_refs(db_session):
    """ Test the backrefs"""

    global __recipe

    assert db_session.query(data.IngredientListEntry).count() == 0

    entry_1 = data.IngredientListEntry(recipe=__recipe, unit=data.IngredientUnit.unit_group, ingredient=__ingredient,
                                       name="Ingredient, green", position=1)
    entry_2 = data.IngredientListEntry(recipe=__recipe, unit=data.IngredientUnit.unit_group, ingredient=__ingredient,
                                       name="Ingredient, blue", position=2)

    db_session.add(entry_1)
    db_session.add(entry_2)
    db_session.commit()

    assert db_session.query(data.IngredientListEntry).count() == 2

    assert len(__recipe.ingredientlist) == 2
    assert len(__ingredient.recipes) == 1
    assert __ingredient.recipes[0] == __recipe
    assert entry_1.recipe == __recipe
    assert entry_2.recipe == __recipe

    # Delete the recipe -> auto delete should be in progress

    db_session.delete(__recipe)
    db_session.commit()

    assert db_session.query(data.IngredientListEntry).count() == 0
    assert len(__ingredient.recipes) == 0

    __recipe = data.Recipe("Test Recipe")
    cleanup(db_session, data.IngredientListEntry)
Ejemplo n.º 2
0
    def actionNew_triggered(self, checked=False):
        """
        New recipe
        Args:
            checked (): ignored

        Returns:

        """
        _translate = self._translate

        title = _translate("RecipeWindow", "New Recipe")

        new_recipe = data.Recipe(title=title)
        self._session.add(new_recipe)
        self._session.commit()
        self.modified = True

        new_recipe_id = new_recipe.id
        recipe_window = None

        # Is there already a window displaying this recipe? (shouldn't be!)
        if new_recipe_id in self._recipe_windows:
            recipe_window = self._recipe_windows[new_recipe_id]
        else:
            recipe_window = recipe_window_controller.RecipeWindow(
                session=self._session, recipe=new_recipe, new_recipe=True)
            self._recipe_windows[new_recipe_id] = recipe_window
            recipe_window.destroyed.connect(
                lambda: self._recipe_window_closed(new_recipe_id))
            recipe_window.recipeChanged.connect(self.recipe_commited)

        recipe_window.setEnabled(True)
        recipe_window.show()
        recipe_window.raise_()
Ejemplo n.º 3
0
def init_data(db_session):
    global __recipe, __group_one, __group_two
    """ Setup one recipe and two groups for the tests"""
    __recipe = data.Recipe(title="Test Recipe")
    db_session.add(__recipe)
    db_session.commit()

    position_one = data.IngredientListEntry.get_position_for_new_group(
        db_session, recipe=__recipe)
    ingredient_one = data.Ingredient("Group One", True)
    db_session.add(ingredient_one)
    db_session.commit()
    __group_one = __add_group(db_session,
                              recipe=__recipe,
                              group=ingredient_one,
                              position=position_one)

    position_two = data.IngredientListEntry.get_position_for_new_group(
        db_session, recipe=__recipe)
    ingredient_two = data.Ingredient("Group Two", True)
    db_session.add(ingredient_two)
    db_session.commit()
    __group_two = __add_group(db_session,
                              recipe=__recipe,
                              group=ingredient_two,
                              position=position_two)

    yield

    for table in (data.Recipe, data.Ingredient, data.IngredientListEntry):
        cleanup(db_session, table)
Ejemplo n.º 4
0
def test_time_constraints(db_session, preparation_time, cook_time, total_time, exception_expected):
    """ Test illegal times (i.e. negative times - doesn't make much sense) """

    assert db_session.query(data.Recipe).count() == 0
    test_object = data.Recipe("Some Recipe", preparation_time=preparation_time, cooking_time=cook_time,
                              total_time=total_time)

    error = add_integrity(db_session, test_object, exception_expected)
    if error:
        pytest.fail(error)
Ejemplo n.º 5
0
def test_rating_constraints(db_session, rating, exception_expected):
    """ Test valid/invalid ratings """

    assert db_session.query(data.Recipe).count() == 0

    test_object = data.Recipe("Some recipe", rating=rating)

    error = add_integrity(db_session, test_object, exception_expected)

    if error:
        pytest.fail(error)
Ejemplo n.º 6
0
def test_yields_constraints(db_session, yields, exception_expected):
    """ Test serving's db constraints
    """
    assert db_session.query(data.Recipe).count() == 0

    test_object = data.Recipe("Some recipe")
    test_object.yields = yields

    error = add_integrity(db_session, test_object, exception_expected)

    if error:
        pytest.fail(error)
Ejemplo n.º 7
0
#  (at your option) any later version.
#
#  Qisit is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#   along with qisit.  If not, see <https://www.gnu.org/licenses/>.

import pytest

from qisit.core.db import data
from . import cleanup, add_integrity

__recipe = data.Recipe("Test Recipe")
__ingredient = data.Ingredient("Iest Ingredient")


@pytest.fixture(autouse=True, scope="module")
def init_data(db_session):
    db_session.add(__recipe)
    db_session.add(__ingredient)
    db_session.commit()
    yield

    for table in (data.Recipe, data.Ingredient):
        cleanup(db_session, table)


@pytest.mark.parametrize("amount, range_amount, exception_expected",
def __setup_recipe(session, title: str = "Test Recipe") -> data.Recipe:
    recipe = data.Recipe(title=title)
    session.add(recipe)
    session.commit()
    return recipe
Ejemplo n.º 9
0
def __setup_recipe(session) -> data.Recipe:
    recipe = data.Recipe("Test recipe")
    session.add(recipe)
    session.merge(recipe)
    return recipe
Ejemplo n.º 10
0
    def __import_recipe(self, gourmet_recipe: gdata.Recipe) -> data.Recipe:
        """
        Convert / Import a Gourmet recipe into Qisit (basic data like title, categories, author..)

        Args:
            gourmet_recipe (): The recipe

        Returns:
            New Qisit's recipe
        """
        # 1.) Fill out all the recipes data

        # Gourmet uses 0 in rating to mark the recipes as unrated. Qisit uses None for this purpose, allowing
        # 0 to be a valid rating
        rating = gourmet_recipe.rating
        if rating == 0:
            rating = None

        # Empty links are stored as "" in Gourmet
        url = nullify(gourmet_recipe.link)

        last_modified = datetime.fromtimestamp(
            gourmet_recipe.last_modified).date()

        qisit_recipe = data.Recipe(title=gourmet_recipe.title,
                                   description=gourmet_recipe.description,
                                   instructions=nullify(
                                       gourmet_recipe.instructions),
                                   notes=nullify(gourmet_recipe.modifications),
                                   rating=rating,
                                   preparation_time=gourmet_recipe.preptime,
                                   cooking_time=gourmet_recipe.cooktime,
                                   yields=gourmet_recipe.yields,
                                   url=url,
                                   last_modified=last_modified)
        self._qisit.add(qisit_recipe)

        # 2.) Yield unit
        gourmet_yield_unit = nullify(gourmet_recipe.yield_unit)
        if gourmet_yield_unit is not None:
            qisit_recipe.yield_unit_name = data.YieldUnitName.get_or_add_yield_unit_name(
                session_=self._qisit, name=gourmet_yield_unit)

        # 3.) Author
        gourmet_source = nullify(gourmet_recipe.source)
        if gourmet_source:
            qisit_recipe.author = data.Author.get_or_add_author(
                self._qisit, gourmet_source)

        # 4.) Cuisine
        gourmet_cuisine = nullify(gourmet_recipe.cuisine)
        if gourmet_cuisine:
            qisit_recipe.cuisine = data.Cuisine.get_or_add_cusine(
                self._qisit, gourmet_cuisine)

        # 5.) Categories
        # Gourmet really *does* support multiple categories, although this is rather well hidden in the UI
        category_list = []
        gourmet_category_list = gourmet_recipe.categories

        if gourmet_category_list:
            for gourmet_category in gourmet_category_list:
                category_list.append(nullify(gourmet_category.category))

        for gourmet_item in category_list:
            if gourmet_item:
                qisit_category = data.Category.get_or_add_category(
                    self._qisit, gourmet_item)
                qisit_recipe.categories.append(qisit_category)

        self._qisit.merge(qisit_recipe)
        return qisit_recipe