diff --git a/tests/lib/check/models_test.py b/tests/lib/check/models_test.py index 671dad79ee..c30024b9a3 100644 --- a/tests/lib/check/models_test.py +++ b/tests/lib/check/models_test.py @@ -361,32 +361,31 @@ class TestCheckReport: class TestCheckReportAWS: def test_check_report_aws(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "arn", "region"]) resource.id = "test_id" resource.arn = "test_arn" resource.region = "test_region" check_report_aws = Check_Report_AWS( metadata=mock_metadata.json(), resource=resource ) + assert check_report_aws.resource_id == "test_id" assert check_report_aws.resource_arn == "test_arn" assert check_report_aws.region == "test_region" def test_check_report_aws_no_id_but_name(self): - resource = mock.Mock - + resource = mock.Mock(spec=["name", "arn", "region"]) resource.name = "test_id" resource.arn = "test_arn" resource.region = "test_region" - report = Check_Report_AWS(metadata=mock_metadata.json(), resource=resource) + assert report.resource_id == "test_id" assert report.resource_arn == "test_arn" assert report.region == "test_region" def test_check_report_aws_no_id_or_name(self): - resource = mock.Mock - + resource = mock.Mock(spec=["arn", "region"]) resource.arn = "test_arn" resource.region = "test_region" @@ -394,8 +393,7 @@ class TestCheckReportAWS: Check_Report_AWS(metadata=mock_metadata.json(), resource=resource) def test_check_report_aws_no_arn(self): - resource = mock.Mock - + resource = mock.Mock(spec=["id", "region"]) resource.id = "test_id" resource.region = "test_region" @@ -403,10 +401,9 @@ class TestCheckReportAWS: Check_Report_AWS(metadata=mock_metadata.json(), resource=resource) def test_check_report_aws_no_region(self): - resource = mock.Mock - + resource = mock.Mock(spec=["id", "arn"]) resource.id = "test_id" - resource.region = "test_region" + resource.arn = "test_arn" with pytest.raises(AttributeError): Check_Report_AWS(metadata=mock_metadata.json(), resource=resource) @@ -418,59 +415,63 @@ class TestCheckReportAWS: class TestCheckReportAzure: def test_check_report_azure(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name", "location"]) resource.id = "test_id" resource.name = "test_name" resource.location = "test_location" report = Check_Report_Azure(metadata=mock_metadata.json(), resource=resource) + assert report.resource_id == "test_id" assert report.resource_name == "test_name" assert report.location == "test_location" assert report.subscription is None def test_check_report_azure_no_id(self): - resource = mock.Mock - + resource = mock.Mock(spec=["name", "location"]) resource.name = "test_name" resource.location = "global" + with pytest.raises(AttributeError): Check_Report_Azure(metadata=mock_metadata.json(), resource=resource) def test_check_report_azure_resource_id(self): - resource = mock.Mock + resource = mock.Mock(spec=["resource_id", "name", "location"]) resource.resource_id = "resource_id" resource.name = "test_name" resource.location = "global" report = Check_Report_Azure(metadata=mock_metadata.json(), resource=resource) - assert report.resource_id == "test_id" + + assert report.resource_id == "resource_id" assert report.resource_name == "test_name" assert report.location == "global" assert report.subscription is None def test_check_report_azure_no_name(self): - resource = mock.Mock - + resource = mock.Mock(spec=["id", "location"]) resource.id = "test_id" resource.location = "global" + with pytest.raises(AttributeError): Check_Report_Azure(metadata=mock_metadata.json(), resource=resource) def test_check_report_azure_resource_name(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "resource_name", "location"]) resource.id = "test_id" resource.resource_name = "test_name" resource.location = "global" report = Check_Report_Azure(metadata=mock_metadata.json(), resource=resource) + assert report.resource_id == "test_id" assert report.resource_name == "test_name" assert report.location == "global" assert report.subscription is None def test_check_report_azure_no_location(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name"]) resource.id = "test_id" resource.name = "test_name" report = Check_Report_Azure(metadata=mock_metadata.json(), resource=resource) + assert report.resource_id == "test_id" assert report.resource_name == "test_name" assert report.location == "global" @@ -479,19 +480,20 @@ class TestCheckReportAzure: class TestCheckReportGCP: def test_check_report_gcp(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name", "project_id", "location"]) resource.id = "test_id" resource.name = "test_name" resource.project_id = "test_project" resource.location = "test_location" report = Check_Report_GCP(metadata=mock_metadata.json(), resource=resource) + assert report.resource_id == "test_id" assert report.resource_name == "test_name" assert report.location == "test_location" assert report.project_id == "test_project" def test_check_report_gcp_resource_id(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name", "project_id", "location"]) resource.id = "test_id" resource.name = "test_name" resource.project_id = "test_project" @@ -499,13 +501,14 @@ class TestCheckReportGCP: report = Check_Report_GCP( metadata=mock_metadata.json(), resource=resource, resource_id="resource_1" ) + assert report.resource_id == "resource_1" assert report.resource_name == "test_name" assert report.location == "test_location" assert report.project_id == "test_project" def test_check_report_gcp_no_resource_id(self): - resource = mock.Mock + resource = mock.Mock(spec=["name", "project_id", "location"]) resource.name = "test_name" resource.project_id = "test_project" resource.location = "test_location" @@ -513,13 +516,14 @@ class TestCheckReportGCP: metadata=mock_metadata.json(), resource=resource, ) + assert report.resource_id == "test_name" assert report.resource_name == "test_name" assert report.location == "test_location" assert report.project_id == "test_project" def test_check_report_gcp_resource_name(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name", "project_id", "location"]) resource.id = "test_id" resource.name = "test_name" resource.project_id = "test_project" @@ -527,29 +531,32 @@ class TestCheckReportGCP: report = Check_Report_GCP( metadata=mock_metadata.json(), resource=resource, resource_name="resource_1" ) + assert report.resource_id == "test_id" assert report.resource_name == "resource_1" assert report.location == "test_location" assert report.project_id == "test_project" def test_check_report_gcp_no_project_id(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name", "location"]) resource.id = "test_id" resource.name = "test_name" resource.location = "test_location" + with pytest.raises(AttributeError): Check_Report_GCP(metadata=mock_metadata.json(), resource=resource) def test_check_report_gcp_no_location(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name", "project_id"]) resource.id = "test_id" resource.name = "test_name" resource.project_id = "test_project" + with pytest.raises(AttributeError): Check_Report_GCP(metadata=mock_metadata.json(), resource=resource) def test_check_report_gcp_region(self): - resource = mock.Mock + resource = mock.Mock(spec=["id", "name", "region", "project_id"]) resource.id = "test_id" resource.name = "test_name" resource.region = "test_region" @@ -558,6 +565,7 @@ class TestCheckReportGCP: metadata=mock_metadata.json(), resource=resource, ) + assert report.resource_id == "test_id" assert report.resource_name == "test_name" assert report.location == "test_region" @@ -566,41 +574,45 @@ class TestCheckReportGCP: class TestCheckReportKubernetes: def test_check_report_kubernetes(self): - resource = mock.Mock + resource = mock.Mock(spec=["uid", "name", "namespace"]) resource.uid = "test_uid" resource.name = "test_name" resource.namespace = "test_namespace" report = Check_Report_Kubernetes( metadata=mock_metadata.json(), resource=resource ) + assert report.resource_id == "test_uid" assert report.resource_name == "test_name" assert report.namespace == "test_namespace" def test_check_report_kubernetes_no_name(self): - resource = mock.Mock + resource = mock.Mock(spec=["uid", "namespace"]) resource.uid = "test_uid" resource.namespace = "test_namespace" + with pytest.raises(AttributeError): Check_Report_Kubernetes(metadata=mock_metadata.json(), resource=resource) def test_check_report_kubernetes_no_uid(self): - resource = mock.Mock + resource = mock.Mock(spec=["name", "namespace"]) resource.name = "test_name" resource.namespace = "test_namespace" report = Check_Report_Kubernetes( metadata=mock_metadata.json(), resource=resource ) + assert report.resource_id == "test_name" assert report.resource_name == "test_name" assert report.namespace == "test_namespace" def test_check_report_kubernetes_no_namespace(self): - resource = mock.Mock + resource = mock.Mock(spec=["name"]) resource.name = "test_name" report = Check_Report_Kubernetes( metadata=mock_metadata.json(), resource=resource ) + assert report.resource_id == "test_name" assert report.resource_name == "test_name" assert report.namespace == "cluster-wide"