-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import random | ||
|
||
def sevade(list1, list2, list3, calorie): | ||
i = 0 | ||
j = 0 | ||
k = len(list3)-1 | ||
rand = random.randint(1,10) | ||
while i < len(list1): | ||
while j < len(list2) and k >= 0: | ||
if list1[i].get_calorie() + list2[j].get_calorie() + list3[k].get_calorie() in range(n-rand, n+rand, 1): | ||
return list1[i], list2[j], list3[k], list1[i].get_calorie() + list2[j].get_calorie() + list3[k].get_calorie() | ||
elif list1[i].get_calorie() + list2[j].get_calorie() + list3[k].get_calorie() < n-10: | ||
j += 1 | ||
else: | ||
k -=1 | ||
i +=1 | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from extentions import db | ||
from foods.models import Food | ||
|
||
def get_foods_with_categories(categories): | ||
foods = [] | ||
for cat in categories: | ||
foods += Food.query.filter_by(Category=cat).all() | ||
return foods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from foods import foods | ||
from foods.utils import get_foods_with_categories | ||
from foods.diet import sevade | ||
|
||
@foods.route('/sevade', methods=['GET']) | ||
def get_sevade(calorie): | ||
cats1 = ['breakfast'] | ||
cats2 = ['mostly_meat', 'pasta', 'main_dish', 'sandwich'] | ||
cats3 = ['dessert', 'other', 'salad'] | ||
|
||
dogs1 = get_foods_with_categories(cats1) | ||
dogs2 = get_foods_with_categories(cats2) | ||
dogs3 = get_foods_with_categories(cats3) | ||
|
||
catdog = sevade(dogs1, dogs2, dogs3, calorie) | ||
|
||
if catdog is None: | ||
return {'error': 'Not Found'}, 404 | ||
else: | ||
return {'diet': [str(catdog[0]), str(catdog[1]), str(catdog[2]), catdog[3]]}, 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest | ||
import requests | ||
import json | ||
|
||
class TestDiet(unittest.TestCase): | ||
|
||
def test_sevade(self): | ||
r = requests.get(ip + '/food/sevade', json={'calorie': 2300}) | ||
result = r.result() | ||
assert result['diet'][3] in range(2990, 2310, 1), 'Test Failed :(' | ||
|
||
def test_zero_sevade(self): | ||
r = requests.get(ip + '/food/sevade', json={'calorie': 0}) | ||
assert r.status_code == 404, 'Khak bar saret :(' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import unittest | ||
import requests | ||
from os import getenv | ||
|
||
# ip = getenv('TEST_URL') | ||
# ip = 'http://127.0.0.1:5000' | ||
|
||
class TestUser(unittest.TestCase): | ||
|
||
def test_create1(self): | ||
# correct things :D | ||
r = requests.post(ip + '/users/signup', | ||
json={'full_name':'Ken Adams', 'email':'[email protected]', | ||
'password':'Audio123', 'confirm_password':'Audio123'}) | ||
assert r.status_code == 201, 'Test Failed :(' | ||
|
||
def test_create2(self): | ||
# mismatching passwords | ||
r = requests.post(ip + '/users/signup', | ||
json={'full_name': 'Ken Adams', 'email': '[email protected]', | ||
'password': 'Audio123', 'confirm_password': 'Audio456'}) | ||
assert r.status_code == 400, 'Test Failed :(' | ||
|
||
def test_create3(self): | ||
# invalid email | ||
r = requests.post(ip + '/users/signup', | ||
json={'full_name': 'Ken Adams', 'email': '[email protected]', | ||
'password': 'Audio123', 'confirm_password': 'Audio123'}) | ||
assert r.status_code == 400, 'Test Failed :(' | ||
|
||
def test_signin1(self): | ||
# correct | ||
r = requests.post(ip + '/users/signin', | ||
json={'email':'[email protected]', 'password':'p@$$word123'}) | ||
assert r.status_code == 200, 'Test Failed :(' | ||
|
||
def test_signin2(self): | ||
# mismatching email and passwords | ||
r = requests.post(ip + '/users/signin', | ||
json={'email':'[email protected]', 'password':'probablywrong'}) | ||
assert r.status_code == 403, 'Test Failed :(' | ||
|
||
def test_signin3(self): | ||
# invalid email | ||
r = requests.post(ip + '/users/signin', | ||
json={'email':'[email protected]', 'password':'p@$$word123'}) | ||
assert r.status_code == 400, 'Test Failed :(' | ||
|
||
def test_modify1(self): | ||
# change password | ||
r = requests.post(ip + '/users/signup/modify', | ||
json={'old_password':'p@$$word123', 'new_password':'123456', 'confirm_password':'123456'}) | ||
assert r.status_code == 204, 'Test Failed :(' | ||
|
||
def test_modify2(self): | ||
# mismtach passwords | ||
r = requests.post(ip + '/users/signup/modify', | ||
json={'old_password': 'p@$$word123', 'new_password': '123456', 'confirm_password': '7891011'}) | ||
assert r.status_code == 400, 'Test Failed :(' | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters