Ejemplo n.º 1
0
def test_recipe_deserialization():
    # Given
    json_string = """{"py/object": "recipe_organizer.recipe.recipe.Recipe", "title": "title", "labels": ["labelA", "labelB"], "ingredients": [{"py/object": "recipe_organizer.recipe.ingredient.ingredient.Ingredient", "name": "name", "quantity_type": "g", "quantity": 50}], "preparation": "preparation"}"""

    # When
    actual: Recipe = Recipe.from_json(json_string)

    # Then
    assert actual.title == "title"
    assert actual.labels == ["labelA", "labelB"]
    assert actual.preparation == "preparation"
Ejemplo n.º 2
0
    def __load_recipes(self, directory: Path):
        recipes: [Recipe] = []
        file_paths = directory.glob("**/*.json")
        for file_path in file_paths:
            with open(file_path, "r", encoding="utf-8") as file:
                json_data = file.read()
                try:
                    recipe = Recipe.from_json(json_data)
                except KeyError:
                    pass
                else:
                    recipes.append(recipe)

        self.__create_list(recipes)
Ejemplo n.º 3
0
    def __read_recipe_from_file(file_path: str) -> None:
        with open(file_path, "r", encoding="utf-8") as file:
            json_data = file.read()
            recipe = Recipe.from_json(json_data)

            EventPublisher.broadcast(Event(EventType.FILE_READ, payload=recipe))