]> Nutra Git (v1) - nutratech/cli.git/commitdiff
fix tuple(csv_reader), list() first. Add test:
authorShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 23:01:39 +0000 (19:01 -0400)
committerShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 23:01:39 +0000 (19:01 -0400)
    test_recipes_overview_process_data_dupe_recipe_uuids_throws_key_error

ntclient/models/__init__.py
tests/services/test_recipe.py

index f61f79103401e6184e24bdbe82c19b4cb34be349..aac5015dedeffffc4a81cf28d2ebc6cb93b504b0 100644 (file)
@@ -38,7 +38,7 @@ class Recipe:
         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(self.csv_reader)
+            self.rows = tuple(list(self.csv_reader))
 
         # Validate data
         uuids = {x["recipe_id"] for x in self.rows}
index fbab1d86708ba57f1785e987b4311d569baf3f6d..7b0138f5e3aed06d441a469693c9e43df0507001 100644 (file)
@@ -6,6 +6,7 @@ Created on Wed Jul 20 21:36:43 2022
 """
 import os
 import unittest
+from unittest.mock import patch
 
 import pytest
 
@@ -31,6 +32,14 @@ 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):
+        """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 pytest.raises(KeyError):
+                r.recipes_overview()
+
     @unittest.expectedFailure
     @pytest.mark.xfail(reason="Due to a wip refactor")
     def test_recipe_overview_throws_exc_for_nonexistent_path(self):