Test cases for FG controller 00/14300/5
authorSwaraj Kumar <swaraj.kumar@samsung.com>
Fri, 4 Apr 2025 09:54:10 +0000 (15:24 +0530)
committerSwaraj Kumar <swaraj.kumar@samsung.com>
Tue, 15 Apr 2025 11:16:58 +0000 (11:16 +0000)
Implement Error Handling in Responses in all the components of AIMLFW

Issue Id- AIMLFW-181
Change-Id: I716daf379322e1039a7cd301f64b263dad2f6493
Signed-off-by: Swaraj Kumar <swaraj.kumar@samsung.com>
tests/test_featuregroupcontroller.py [new file with mode: 0644]

diff --git a/tests/test_featuregroupcontroller.py b/tests/test_featuregroupcontroller.py
new file mode 100644 (file)
index 0000000..d0b2890
--- /dev/null
@@ -0,0 +1,41 @@
+import pytest
+from flask import Flask
+from unittest.mock import patch
+from requests.models import Response
+from threading import Lock
+import os
+import sys
+import datetime
+from io import BytesIO
+from flask_api import status
+from dotenv import load_dotenv
+load_dotenv('tests/test.env')
+from trainingmgr.constants.states import States
+from threading import Lock
+from trainingmgr.controller.featuregroup_controller import featuregroup_controller
+from trainingmgr.common.exceptions_utls import DBException, TMException
+from trainingmgr.common.trainingmgr_config import TrainingMgrConfig
+from marshmallow import ValidationError
+from trainingmgr.schemas.problemdetail_schema import ProblemDetails
+from types import SimpleNamespace
+from trainingmgr import trainingmgr_main
+from trainingmgr.common.tmgr_logger import TMLogger
+
+trainingmgr_main.LOGGER = pytest.logger
+
+@pytest.fixture
+def client():
+    app = Flask(__name__)
+    app.register_blueprint(featuregroup_controller)
+    app.config['TESTING'] = True
+    return app.test_client()
+
+class TestCreateFeatureGroup:
+
+    @patch('trainingmgr.schemas.featuregroup_schema.FeatureGroupSchema.load')
+    def test_invalid_featuregroup_name(self, mock_load, client):
+        mock_load.return_value = type("FeatureGroup", (), {"featuregroup_name": "xy", "enable_dme": False})
+        response = client.post("/featureGroup", json={})
+        assert response.status_code == 400
+        expected = ProblemDetails(400, "Bad Request", "Failed to create the feature group since feature group not valid").to_dict()
+        assert response.get_json() == expected