Skip to content

Commit

Permalink
tweaks some database parameters and some url import logic to work bet…
Browse files Browse the repository at this point in the history
…ter on a remote server based on trial runs.
  • Loading branch information
trp07 committed Feb 16, 2021
1 parent ac8c91f commit 8e627b3
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pyrecipe/app/viewmodels/recipe/add_viewmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ def cook_time(self) -> int:
return int(cook_time)

@property
def servings(self) -> int:
def servings(self) -> str:
servings = self.request_dict.servings
if servings == "":
return 0
return "0"
else:
return int(servings)
return servings

@property
def name(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions pyrecipe/app/viewmodels/recipe/edit_viewmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def cook_time(self) -> int:
return int(self.recipe.cook_time)

@property
def servings(self) -> int:
def servings(self) -> str:
if self.method=="GET" and self.recipe:
return int(self.recipe.servings)
return self.recipe.servings

@property
def ingredients(self) -> List[str]:
Expand Down
7 changes: 4 additions & 3 deletions pyrecipe/services/importer/import_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def import_from_url(url: str) -> dict:
notes = ["Imported from: " + url]
nutrients = [k + ": " + v for k,v in scraper.nutrients().items()]

print("SCRAPER: ", scraper.yields())
return {
"name": scraper.title(),
"prep_time": 1,
"cook_time": scraper.total_time(),
"servings": scraper.yields().split(" ")[0],
"prep_time": 0,
"cook_time": scraper.total_time() or 999,
"servings": scraper.yields() or "",
"ingredients": scraper.ingredients(),
"directions": scraper.instructions().split("\n"),
"tags": ["imported", scraper.host().split(".")[0]],
Expand Down
6 changes: 3 additions & 3 deletions pyrecipe/storage/mongo/mongodriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def recipe_create(
name: str,
prep_time: int,
cook_time: int,
servings: int,
servings: str,
ingredients: List["ingredients"],
directions: List["directions"],
tags: List["tags"] = [],
Expand All @@ -77,7 +77,7 @@ def recipe_create(
r.name = name
r.prep_time = float(prep_time)
r.cook_time = float(cook_time)
r.servings = int(servings)
r.servings = servings
r.ingredients = ingredients
r.num_ingredients = len(ingredients)
r.directions = directions
Expand All @@ -93,7 +93,7 @@ def recipe_edit(
name: str,
prep_time: int,
cook_time: int,
servings: int,
servings: str,
ingredients: List["ingredients"],
directions: List["directions"],
tags: List["tags"] = [],
Expand Down
4 changes: 2 additions & 2 deletions pyrecipe/storage/mongo/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Recipe(BaseDocument):
NOT-REQUIRED params:
:param prep_time: (float) time to prep recipe in minutes.
:param cook_time: (float) time to cook recipe in minutes.
:param servings: (int) number of servings in the recipe.
:param servings: (str) number of servings in the recipe.
:param tags: (list) descriptive tags for a recipe.
i.e. ['bbq', 'vegetarian']
:param images: (list filepath for an uploaded image.
Expand All @@ -43,7 +43,7 @@ class Recipe(BaseDocument):

prep_time = mongoengine.FloatField(default=0, min_val=0.0)
cook_time = mongoengine.FloatField(default=0, min_val=0.0)
servings = mongoengine.IntField(default=0, min_val=1)
servings = mongoengine.StringField(required=False)
tags = mongoengine.ListField(required=False)
images = mongoengine.ListField(field=mongoengine.StringField(), required=False)
notes = mongoengine.ListField(field=mongoengine.StringField(), required=False)
Expand Down
2 changes: 1 addition & 1 deletion pyrecipe/storage/shared/recipe_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RecipeModel:
directions: list
prep_time: float
cook_time: float
servings: int
servings: str
tags: list
notes: list
rating: float
Expand Down
5 changes: 3 additions & 2 deletions pyrecipe/usecases/recipe_uc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_recipe(
name: str,
prep_time: int,
cook_time: int,
servings: int,
servings: str,
ingredients: List["ingredients"],
directions: List["directions"],
tags: List["tags"] = [],
Expand Down Expand Up @@ -83,7 +83,7 @@ def edit_recipe(
name: str,
prep_time: int,
cook_time: int,
servings: int,
servings: str,
ingredients: List["ingredients"],
directions: List["directions"],
tags: List["tags"] = [],
Expand Down Expand Up @@ -144,6 +144,7 @@ def import_recipe_from_url(self, url: str) -> "RecipeModel":
if imported["images"]:
imported["images"] = [self._save_image(imported["images"])]

print(imported)
return self.create_recipe(**imported)

def _save_image(self, url: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/app/viewmodels/test_vmrecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_addvm(mocker):
vm = AddViewModel()

assert vm.name == "oatmeal"
assert vm.servings == 4
assert vm.servings == "4"
assert vm.cook_time == 30
assert vm.prep_time == 2
assert vm.recipe_url == ""
Expand Down
4 changes: 2 additions & 2 deletions tests/services/importer/test_import_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_import_from_url(mocker):

result = imp.import_from_url("testurl")
assert result["name"] == "test_name"
assert result["prep_time"] == 1
assert result["prep_time"] == 0
assert result["cook_time"] == "10"
assert result["servings"] == "5"
assert result["ingredients"] == ["a", "b"]
Expand All @@ -48,7 +48,7 @@ def test_import_from_url_websiteError(mocker):

result = imp.import_from_url("testurl")
assert result["name"] == "test_name"
assert result["prep_time"] == 1
assert result["prep_time"] == 0
assert result["cook_time"] == "10"
assert result["servings"] == "5"
assert result["ingredients"] == ["a", "b"]
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/mongo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def recipes(mongodb):
recipe_1.directions = ["fry eggs", "add spam", "eat"]
recipe_1.prep_time = 10
recipe_1.cook_time = 5
recipe_1.servings = 1
recipe_1.servings = "1"
recipe_1.tags = ["breakfast", "fast"]
recipe_1.images = ["/path/to/image"]
recipe_1.save()
Expand Down
4 changes: 2 additions & 2 deletions tests/storage/mongo/test_mongodriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_recipe_to_dict(recipes):
assert r["directions"] == ["fry eggs", "add spam", "eat"]
assert r["prep_time"] == 10
assert r["cook_time"] == 5
assert r["servings"] == 1
assert r["servings"] == "1"
assert r["tags"] == ["breakfast", "fast"]
assert r["images"] == ["/path/to/image"]

Expand All @@ -78,7 +78,7 @@ def test_recipe_create(mongodb):
name="Tester",
prep_time=5,
cook_time=10,
servings=1,
servings="1",
ingredients=["garlic, 1 clove minced"],
directions=["cook", "eat"],
tags=["breakfast", "easy"],
Expand Down

0 comments on commit 8e627b3

Please sign in to comment.