]> Nutra Git (v2) - nutratech/cli.git/commitdiff
fully cover, add test in recipes, aggregate_rows()
authorShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 23:34:54 +0000 (19:34 -0400)
committerShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 23:34:54 +0000 (19:34 -0400)
ntclient/models/__init__.py
tests/services/test_recipe.py

index af6629d4a6c980df87e0e027692d2cf06f6d4d43..df9dd9de2ce57cb408f303fb2f5d1abc71016052 100644 (file)
@@ -27,6 +27,13 @@ class Recipe:
 
         self.food_data = {}  # type: ignore
 
+    def aggregate_rows(self) -> tuple:
+        """Aggregate rows into a tuple"""
+        print("Processing recipe file: %s" % self.file_path)
+        with open(self.file_path, "r", encoding="utf-8") as _file:
+            self.csv_reader = csv.DictReader(_file)
+            return tuple(list(self.csv_reader))
+
     def process_data(self) -> None:
         """
         Parses out the raw CSV input read in during self.__init__()
@@ -37,10 +44,7 @@ class Recipe:
         """
 
         # Read into memory
-        print("Processing recipe file: %s" % self.file_path)
-        with open(self.file_path, "r", encoding="utf-8") as _file:
-            self.csv_reader = csv.DictReader(_file)
-            self.rows = tuple(list(self.csv_reader))
+        self.rows = self.aggregate_rows()
 
         # Validate data
         uuids = {x["recipe_id"] for x in self.rows}
index 681341225d086a71d43cf5da9745767f16deab95..76a2f05a45115f12404fc17e057570576ac83582 100644 (file)
@@ -11,6 +11,7 @@ from unittest.mock import patch
 import pytest
 
 import ntclient.services.recipe.utils as r
+from ntclient.models import Recipe
 from ntclient.services.recipe import RECIPE_STOCK, csv_utils
 
 
@@ -32,13 +33,17 @@ class TestRecipe(unittest.TestCase):
         exit_code, _ = r.recipes_overview()
         assert exit_code == 0
 
-    @unittest.skip("Not implemented")
-    def test_recipes_overview_process_data_dupe_recipe_uuids_throws_key_error(self):
+    @unittest.skip("Not implemented")
+    def test_recipe_process_data_multiple_recipe_uuids_throws_key_error(self):
         """Raises key error if recipe uuids are not unique"""
         # TODO: return_value should be a list of recipe dicts, each with a 'uuid' key
-        with patch("ntclient.models.Recipe.rows", return_value={1, 2}):
+        with patch(
+            "ntclient.models.Recipe.aggregate_rows",
+            return_value=[{"recipe_id": "UUID_1"}, {"recipe_id": "UUID_2"}],
+        ):
             with pytest.raises(KeyError):
-                r.recipes_overview()
+                recipe = Recipe("FAKE-PATH")
+                recipe.process_data()
 
     def test_recipe_overview_returns_exit_code_1_for_nonexistent_path(self):
         """Returns (1, None) if recipe path is invalid"""