示例#1
0
 def testInstructionsContainsNone(self):
     with self.assertRaises(Exception):
         Recipe("Lasagna", ['pasta', 'italian'], 1.0, 2.0,
                ['meat', 'noodles', 'sauce', 'cheese'],
                [None, 'combine ingredients', 'cook ingredients'], 2)
示例#2
0
 def testServingsIsNegative(self):
     with self.assertRaises(Exception):
         Recipe("Lasagna", ['pasta', 'italian'], 1.0, 2.0,
                ['meat', 'noodles', 'sauce', 'cheese'],
                ['combine ingredients', 'cook ingredients'], -1)
示例#3
0
 def testIngredientsIsNone(self):
     with self.assertRaises(Exception):
         Recipe("Lasagna", ['pasta', 'italian'], 1.0, 2.0, None,
                ['combine ingredients', 'cook ingredients'], 2)
示例#4
0
 def testInstructionsIsNone(self):
     with self.assertRaises(Exception):
         Recipe("Lasagna", ['pasta', 'italian'], 1.0, 2.0,
                ['meat', 'noodles', 'sauce', 'cheese'], None, 2)
示例#5
0
 def testCategoriesIsNone(self):
     with self.assertRaises(Exception):
         Recipe("Lasagna", None, 1.0, 2.0,
                ['meat', 'noodles', 'sauce', 'cheese'],
                ['combine ingredients', 'cook ingredients'], 2)
示例#6
0
 def testNameIsNone(self):
     with self.assertRaises(Exception):
         Recipe(None, ['pasta', 'italian'], 1.0, 2.0,
                ['meat', 'noodles', 'sauce', 'cheese'],
                ['combine ingredients', 'cook ingredients'], 2)
示例#7
0
def importBeerXMLRecipe(data):
    logger.debug("Start parsing recipe")
    try:
        tree = ElementTree.parse(data)
    except TypeError:
        tree = data
    except FileNotFoundError:
        tree = ElementTree.fromstring(data)
    except:
        raise

    recipe = Recipe()
    recipe.path = data

    presentation = tree.find('.//RECIPE')
    fermentables = tree.findall('.//FERMENTABLE')
    hops = tree.findall('.//HOP')
    levures = tree.findall('.//YEAST')
    misc = tree.findall('.//MISC')
    style = tree.find('.//STYLE')
    mash = tree.find('.//MASH')

    for element in presentation:
        if 'NAME' == element.tag:
            recipe.name = element.text
            logger.debug(" Recipe name: %s", recipe.name)
        if 'BREWER' == element.tag:
            recipe.brewer = element.text
            logger.debug(" Recipe brewer: %s", recipe.brewer)
        if 'TYPE' == element.tag:
            if "All Grain" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_ALL_GRAIN
            elif "Partial Mash" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_PARTIAL_MASH
            elif "Extract" == element.text:
                recipe.type = model.constants.RECIPE_TYPE_EXTRACT
            logger.debug(" Recipe type: %s", recipe.type)
        if "BATCH_SIZE" == element.tag:
            recipe.volume = float(element.text)
            logger.debug(" Recipe volume: %s", recipe.volume)
        if "EFFICIENCY" == element.tag:
            recipe.efficiency = float(element.text)
            logger.debug(" Recipe efficiency: %s", recipe.efficiency)
        if "BOIL_TIME" == element.tag:
            recipe.boil = float(element.text)
            logger.debug(" Recipe boil time: %s", recipe.boil)
        if "NOTES" == element.tag:
            recipe.recipeNotes = element.text
            logger.debug(" Recipe notes: %s", recipe.recipeNotes)
    try:
        for element in style:
            if "NAME" == element.tag:
                recipe.style = element.text
    except TypeError:
        recipe.style = ""

    try:
        recipe.mash = importBeerXMLMash(mash)
    except:
        pass

    for element in fermentables:
        recipe.listeFermentables.append(importBeerXMLFermentable(element))
    for element in hops:
        recipe.listeHops.append(importBeerXMLHop(element))
    for element in levures:
        recipe.listeYeasts.append(importBeerXMLYeast(element))
    for element in misc:
        recipe.listeMiscs.append(importBeerXMLMisc(element))

    logger.debug("End parsing recipe")
    return recipe
示例#8
0
def importDictRecipe(dic):
    logger.debug("Start parsing dict")

    recipe = Recipe()
    recipe.path = dic['path']
    recipe.name = dic['name']
    recipe.brewer = dic['brewer']
    recipe.style = dic['style']
    if dic['type'] == "All Grain":
        recipe.type = RECIPE_TYPE_ALL_GRAIN
    elif dic['type'] == "Extract":
        recipe.type = RECIPE_TYPE_EXTRACT
    elif recipe.type == "Partial Mash":
        recipe.type = RECIPE_TYPE_PARTIAL_MASH

    recipe.volume = dic['volume']
    recipe.boil = dic['boilTime']
    recipe.efficiency = dic['efficiency']

    for hop_dic in dic['hops']:
        hop = Hop()
        hop.name = hop_dic['name']

        if hop_dic['form'] == "Pellet":
            hop.form = HOP_FORM_PELLET
        elif hop_dic['form'] == "Leaf":
            hop.form = HOP_FORM_LEAF
        elif hop_dic['form'] == "Plug":
            hop.form = HOP_FORM_PLUG
        hop.alpha = hop_dic['alpha']
        hop.use = hop_dic['use']
        hop.time = hop_dic['time']
        hop.amount = hop_dic['amount']
        recipe.listeHops.append(hop)

    for f_dic in dic['fermentables']:
        f = Fermentable()
        f.name = f_dic['name']
        f.type = f_dic['type']
        f.fyield = f_dic['fyield']
        f.color = f_dic['color']
        f.amount = f_dic['amount']
        if f_dic['afterBoil'] == 'TRUE':
            f.useAfterBoil = True
        else:
            f.useAfterBoil = False
        f.recommendMash = f_dic['recoMash']
        recipe.listeFermentables.append(f)

    for y_dic in dic['yeasts']:
        y = Yeast()
        y.name = y_dic['name']
        y.productId = y_dic['product_id']
        y.labo = y_dic['labo']
        y.form = y_dic['form']
        y.attenuation = y_dic['attenuation']
        recipe.listeYeasts.append(y)

    for m_dic in dic['miscs']:
        m = Misc()
        m.name = m_dic['name']
        m.amount = m_dic['amount']
        m.type = m_dic['type']
        m.use = m_dic['use']
        m.time = m_dic['time']
        recipe.listeMiscs.append(m)

    mash_dic = dic['mashProfile']
    recipe.mash.name = mash_dic['name']
    recipe.mash.ph = mash_dic['ph']
    recipe.mash.spargeTemp = mash_dic['sparge']
    recipe.mash.tunTemp = mash_dic['tunTemp']

    for s_dic in mash_dic['steps']:
        s = MashStep()
        s.name = s_dic['name']
        s.time = s_dic['time']
        s.temp = s_dic['temp']
        s.type = s_dic['type']
        recipe.listeMashSteps.append(s)
    recipe.recipeNotes = dic['notes']

    return recipe
示例#9
0
recipe1 = Recipe(
    recipeID='135',
    authorID='sarah',
    name='Sweet Potato Soup',
    duration='45 minutes',
    picture='picture',
    difficulty='easy',
    style='boiling',
    country='chinese',
    course='dessert',
    ingredient={
        "ingredient": [{
            "name": "sweet potato",
            "amount": "400g"
        }, {
            "name": "slab sugar",
            "amount": "1 block"
        }, {
            "name": "ginger",
            "amount": "2 slices"
        }]
    },
    procedure={
        "procedure": [{
            "procedure": 1,
            "description": "Washed and peel sweet the potato"
        }, {
            "procedure":
            2,
            "description":
            "When you slice the sweet potatoes, cut it halfway then split the piece off (It brings out a better flavor)"
        }, {
            "procedure":
            3,
            "description":
            "Add ginger and sweet potatoes into boiled water. Turn the water to med heat. "
        }, {
            "procedure":
            4,
            "description":
            "Cook for 25 minutes until the sweet potatoes are softened. "
        }, {
            "procedure": 5,
            "description": "Add slab sugar. "
        }]
    })