From 6e06d4b27c4e062b3f6e5e36ebc6fc24b0785cbb Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 12 Apr 2024 19:34:54 -0400 Subject: [PATCH] fully cover, add test in recipes, aggregate_rows() --- ntclient/models/__init__.py | 12 ++++++++---- tests/services/test_recipe.py | 13 +++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ntclient/models/__init__.py b/ntclient/models/__init__.py index af6629d..df9dd9d 100644 --- a/ntclient/models/__init__.py +++ b/ntclient/models/__init__.py @@ -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} diff --git a/tests/services/test_recipe.py b/tests/services/test_recipe.py index 6813412..76a2f05 100644 --- a/tests/services/test_recipe.py +++ b/tests/services/test_recipe.py @@ -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""" -- 2.52.0