forked from coddingtonbear/python-myfitnesspal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_integration.py
140 lines (115 loc) · 4.16 KB
/
test_integration.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import datetime
import os
import pytest
from myfitnesspal import Client
from .base import MFPTestCase
class TestIntegration(MFPTestCase):
client: Client
@classmethod
def setUpClass(cls):
try:
username = os.environ["MFP_INTEGRATION_TESTING_USERNAME"]
password = os.environ["MFP_INTEGRATION_TESTING_PASSWORD"]
except KeyError:
pytest.skip("Integration testing account not set in this environment.")
return
cls.client = Client(
username,
password,
)
day_with_known_entries = datetime.date(2020, 7, 4)
cls.day = cls.client.get_date(day_with_known_entries)
def test_get_exercises_dict(self):
expected_exercise_dicts = [
[
{
"name": "Rowing, stationary, very vigorous effort",
"nutrition_information": {
"minutes": 30.0,
"calories burned": 408.0,
},
}
],
[
{
"name": "Squat",
"nutrition_information": {
"sets": 5.0,
"reps/set": 5.0,
"weight/set": 225.0,
},
}
],
]
actual_exercises = [exercise.get_as_list() for exercise in self.day.exercises]
assert actual_exercises == expected_exercise_dicts
def test_get_day_meal_dict(self):
expected_meal_dict = {
"breakfast": [
{
"name": "Whole Foods - Juevos Rancheros, 2 cup",
"nutrition_information": {
"calories": 480,
"carbohydrates": 84,
"fat": 2,
"protein": 28,
"sodium": 2000,
"sugar": 4,
},
}
],
"lunch": [
{
"name": "Trillium - Impossible Burger, 1 Burger",
"nutrition_information": {
"calories": 410,
"carbohydrates": 61,
"fat": 13,
"protein": 15,
"sodium": 780,
"sugar": 4,
},
}
],
"dinner": [
{
"name": "Morrisons - Vegetarian Lasagne, 800 g",
"nutrition_information": {
"calories": 832,
"carbohydrates": 93,
"fat": 36,
"protein": 31,
"sodium": 3600,
"sugar": 30,
},
}
],
"snacks": [],
}
actual_meal_dict = self.day.get_as_dict()
assert actual_meal_dict == expected_meal_dict
def test_get_notes(self):
expected_note = "Epstein didn't kill himself"
actual_note = self.day.notes
assert expected_note == actual_note
def test_get_water(self):
expected_water = 480.0
actual_water = self.day.water
assert expected_water == actual_water
def test_search_results(self):
results = self.client.get_food_search_results("Tortilla Chips -- Juanita's")
# Don't assert that we get a particular match,
# just make sure that we receive items
# that happen to have an mfp_id; we can't
# really know how the search results might
# change in the future
assert len(results) > 0
for result in results:
assert isinstance(result.mfp_id, int)
# This is just to assert that we _do_ try
# to load extra nutrition information on-access
assert results[0].sodium > 0
def test_get_food_item_details(self):
juanitas_tortilla_chips_mfp_id = 63384601972733
result = self.client.get_food_item_details(juanitas_tortilla_chips_mfp_id)
assert result.mfp_id == juanitas_tortilla_chips_mfp_id