Skip to content

Commit

Permalink
tests edited
Browse files Browse the repository at this point in the history
  • Loading branch information
yassiommi committed May 29, 2020
1 parent db1ef8f commit 537b28d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
8 changes: 4 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def temp_main_function():
if app.debug:
app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True)

#enabling whitenoise
app.wsgi_app = WhiteNoise(app.wsgi_app)
for static_folder in app.config.STATIC_FOLDERS:
app.wsgi_app.add_files(static_folder)
# #enabling whitenoise
# app.wsgi_app = WhiteNoise(app.wsgi_app)
# for static_folder in app.config.STATIC_FOLDERS:
# app.wsgi_app.add_files(static_folder)

return app

Expand Down
58 changes: 33 additions & 25 deletions foods/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,58 @@

@foods.route('/yevade/<int:calorie>', methods=['GET'])
def get_yevade(calorie):
cat = ['breakfast, ''mostly_meat', 'pasta', 'main_dish', 'sandwich', 'appetizers', 'drink']
dog = get_foods_with_categories(cat)
if calorie > 0:
cat = ['breakfast, ''mostly_meat', 'pasta', 'main_dish', 'sandwich', 'appetizers', 'drink']
dog = get_foods_with_categories(cat)

catdog = yevade(dog, calorie)
catdog = yevade(dog, calorie)

if catdog is None:
return jsonify({'error': 'Not Found'}), 404
if catdog is None:
return jsonify({'error': 'Not Found'}), 404
else:
return jsonify({'diet': [str(catdog[0]), catdog[1]]}), 200
else:
return jsonify({'diet': [str(catdog[0]), catdog[1]]}), 200
return jsonify({'error': 'I\'m a teapot'}), 418


@foods.route('/dovade/<int:calorie>', methods=['GET'])
def get_dovade(calorie):
cats1 = ['breakfast', 'sandwich', 'pasta', 'appetizers', 'drink']
cats2 = ['mostly_meat', 'pasta', 'main_dish', 'sandwich', 'appetizers']
if calorie > 0:
cats1 = ['breakfast', 'sandwich', 'pasta', 'appetizers', 'drink']
cats2 = ['mostly_meat', 'pasta', 'main_dish', 'sandwich', 'appetizers']

dogs1 = get_foods_with_categories(cats1)
dogs2 = get_foods_with_categories(cats2)
dogs1 = get_foods_with_categories(cats1)
dogs2 = get_foods_with_categories(cats2)

catdog = dovade(dogs1, dogs2, calorie)
catdog = dovade(dogs1, dogs2, calorie)

if catdog is None:
return jsonify({'error': 'Not Found'}), 404
if catdog is None:
return jsonify({'error': 'Not Found'}), 404
else:
return jsonify({'diet': [str(catdog[0]), str(catdog[1]), str(catdog[2])]}), 200
else:
return jsonify({'diet': [str(catdog[0]), str(catdog[1]), str(catdog[2])]}), 200
return jsonify({'error': 'I\'m a teapot'}), 418


@foods.route('/sevade/<int:calorie>', methods=['GET'])
def get_sevade(calorie):
cats1 = ['breakfast', 'pasta', 'salad', 'sandwich', 'appetizers']
cats2 = ['mostly_meat', 'pasta', 'main_dish', 'sandwich']
cats3 = ['dessert', 'other', 'salad', 'side_dish', 'drink', 'main_dish', 'pasta']
if calorie > 0:
cats1 = ['breakfast', 'pasta', 'salad', 'sandwich', 'appetizers']
cats2 = ['mostly_meat', 'pasta', 'main_dish', 'sandwich']
cats3 = ['dessert', 'other', 'salad', 'side_dish', 'drink', 'main_dish', 'pasta']

dogs1 = get_foods_with_categories(cats1)
dogs2 = get_foods_with_categories(cats2)
dogs3 = get_foods_with_categories(cats3)
dogs1 = get_foods_with_categories(cats1)
dogs2 = get_foods_with_categories(cats2)
dogs3 = get_foods_with_categories(cats3)

catdog = sevade(dogs1, dogs2, dogs3, calorie)
catdog = sevade(dogs1, dogs2, dogs3, calorie)

if catdog is None:
return jsonify({'error': 'Not Found'}), 404
if catdog is None:
return jsonify({'error': 'Not Found'}), 404
else:
return jsonify({'diet': [str(catdog[0]), str(catdog[1]), str(catdog[2]), catdog[3]]}), 200
else:
return jsonify({'diet': [str(catdog[0]), str(catdog[1]), str(catdog[2]), catdog[3]]}), 200

return jsonify({'error': 'I\'m a teapot'}), 418

@foods.route('/recipe/<int:id>', methods=['GET'])
def get_recipe(id):
Expand Down
29 changes: 16 additions & 13 deletions tests/diet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@
import json

# ip = 'https://dailydiet-api.herokuapp.com/'
ip = 'localhost:5000'
ip = 'http://127.0.0.1:5000'
class TestDiet(unittest.TestCase):

def test_sevade(self):
r = requests.get(ip + '/food/sevade/2300')
result = r.result()
r = requests.post(ip + '/food/sevade/2300')
result = r.json()
assert result['diet'][3] in range(2990, 2310, 1), 'Test Failed :('

def test_zero_sevade(self):
r = requests.get(ip + '/food/sevade/0')
assert r.status_code == 404, 'Khak bar saret :('
r = requests.post(ip + '/food/sevade/0')
assert r.status_code == 418, 'Khak bar saret :('

def test_dovade(self):
r = requests.get(ip + '/food/dovade/4300')
result = r.result()
r = requests.post(ip + '/food/dovade/4300')
result = r.json()
assert result['diet'][2] in range(2990, 2310, 1), 'Test Failed :('

def test_zero_dovade(self):
r = requests.get(ip + '/food/dovade/0')
assert r.status_code == 404, 'Khak bar saret :('
r = requests.post(ip + '/food/dovade/0')
assert r.status_code == 418, 'Khak bar saret :('

def test_yevade(self):
r = requests.get(ip + '/food/yevade/400')
result = r.result()
r = requests.post(ip + '/food/yevade/400')
result = r.json()
assert result['diet'][1] in range(390, 410, 1), 'Test Failed :('

def test_zero_yevade(self):
r = requests.get(ip + '/food/yevade/0')
assert r.status_code == 404, 'Khak bar saret :('
r = requests.post(ip + '/food/yevade/0')
assert r.status_code == 418, 'Khak bar saret :('

if __name__ == '__main__':
unittest.main()

0 comments on commit 537b28d

Please sign in to comment.