-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare_nutrients_test.py
79 lines (60 loc) · 2.27 KB
/
prepare_nutrients_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from prepare_nutrients import prepare_nutrients
def test_prepare_nutrients():
product = {
'ingredients': [{
'id':'en:tomato',
'nutrients': {
'carbohydrates': {'percent_min': 2.5,'percent_max': 2.5},
'energy': {'percent_min': 80,'percent_max': 80},
'water': {'percent_min': 90,'percent_max': 90},
}
}],
'nutriments': {
'carbohydrates_100g': 5,
'proteins_100g': 4,
'energy_100g': 160,
}}
prepare_nutrients(product)
metrics = product.get('recipe_estimator')
assert metrics is not None
# Ingredient count is calculated
assert metrics['ingredient_count'] == 1
nutrients = metrics.get('nutrients')
assert nutrients is not None
nutrient = nutrients.get('carbohydrates')
assert nutrient is not None
# Nutrient information is calculated
assert nutrient.get('ingredient_count') == 1
assert nutrient.get('unweighted_total') == 2.5
# Weighting assigned based on proportion in product
# TODO: This seems to have been disabled
# assert nutrient.get('weighting') == 0.2
# Nutrients not on any ingredient are not included
assert nutrients.get('proteins') is None
# Water is included
assert nutrients.get('water') is not None
# Enery is not weighted
energy = nutrients.get('energy')
assert energy.get('weighting') is None
def test_prepare_nutrients_copes_with_no_product_nutrients():
product = {
'ingredients': [{
'id':'en:tomato',
'nutrients': {
'carbohydrates': {'percent_min': 2.5,'percent_max': 2.5},
'energy': {'percent_min': 80,'percent_max': 80},
'water': {'percent_min': 90,'percent_max': 90},
}
}]}
prepare_nutrients(product)
metrics = product.get('recipe_estimator')
assert metrics is not None
# Ingredient count is calculated
assert metrics['ingredient_count'] == 1
nutrients = metrics.get('nutrients')
assert nutrients is not None
nutrient = nutrients.get('carbohydrates')
assert nutrient is not None
# Nutrient information flagged
assert nutrient.get('notes') is not None
assert nutrient.get('weighting') is None