From 784cb8acfd892630a4cb9acfa35143b7d6fcad17 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 12 Apr 2024 19:01:39 -0400 Subject: [PATCH] fix tuple(csv_reader), list() first. Add test: test_recipes_overview_process_data_dupe_recipe_uuids_throws_key_error --- ntclient/models/__init__.py | 2 +- tests/services/test_recipe.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ntclient/models/__init__.py b/ntclient/models/__init__.py index f61f791..aac5015 100644 --- a/ntclient/models/__init__.py +++ b/ntclient/models/__init__.py @@ -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} diff --git a/tests/services/test_recipe.py b/tests/services/test_recipe.py index fbab1d8..7b0138f 100644 --- a/tests/services/test_recipe.py +++ b/tests/services/test_recipe.py @@ -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): -- 2.52.0