From 3a64e0eb96bf880906c179641b7257f000a5f3c0 Mon Sep 17 00:00:00 2001 From: Eyal Zekaria Date: Thu, 29 Sep 2022 12:06:22 +0300 Subject: [PATCH] Adapt tests for new structure - patch path for avoiding import errors (I hate this) - fix imports to new structure - update logging test --- tests/__init__.py | 7 +++++++ tests/test_gkeworkload.py | 4 +++- tests/test_gsaproject.py | 8 +++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..ccf3c9e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,7 @@ +import os +import sys +PROJECT_PATH = os.getcwd() +SOURCE_PATH = os.path.join( + PROJECT_PATH, 'src' +) +sys.path.append(SOURCE_PATH) diff --git a/tests/test_gkeworkload.py b/tests/test_gkeworkload.py index 91f06d1..113bab2 100644 --- a/tests/test_gkeworkload.py +++ b/tests/test_gkeworkload.py @@ -1,6 +1,8 @@ import unittest from unittest.mock import MagicMock, patch -from analyzer.analyzer import GkeWorkload, Reporter, parse_args, init_logger +from gke import GkeWorkload +from analyzer import parse_args, init_logger +from reporter import Reporter class GkeWorkloadTestCase(unittest.TestCase): diff --git a/tests/test_gsaproject.py b/tests/test_gsaproject.py index cd4b996..794bf82 100644 --- a/tests/test_gsaproject.py +++ b/tests/test_gsaproject.py @@ -1,6 +1,8 @@ import unittest from unittest.mock import MagicMock, patch -from analyzer.analyzer import GsaProject, Reporter, parse_args, init_logger +from gsa import GsaProject +from analyzer import parse_args, init_logger +from reporter import Reporter @patch('googleapiclient.discovery.build') @@ -106,10 +108,10 @@ def test_list_gsa_project_roles(self, mock_build): 'members': ['serviceAccount:testMember']} ] } - with self.assertLogs('analyzer') as cm: + with self.assertLogs() as cm: gsaProject.list_gsa_project_roles() self.assertEqual(cm.output, [ - 'INFO:analyzer:GSA: "testMember" has the following ' + 'INFO:root:GSA: "testMember" has the following ' 'roles in project "test-project":' '\nroles/viewer\nroles/editor'])