Fix PMHS logs dir setup

  # Refactoring test|prod init

Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: Ib073cb762a7750fca7bdf415cf5080d04f7bda51
Issue-ID: DCAEGEN2-2078
diff --git a/components/pm-subscription-handler/Dockerfile b/components/pm-subscription-handler/Dockerfile
index bb3f63c..b1f3129 100644
--- a/components/pm-subscription-handler/Dockerfile
+++ b/components/pm-subscription-handler/Dockerfile
@@ -30,7 +30,10 @@
 WORKDIR $APPDIR
 
     # add non root user & group
-RUN addgroup --system $PMSHUSER && adduser --ingroup $PMSHUSER --system $PMSHUSER
+RUN addgroup --system $PMSHUSER && adduser --ingroup $PMSHUSER --system $PMSHUSER && \
+    # create and chown the LOGS_PATH
+    mkdir -p $LOGS_PATH && \
+    chown -R $PMSHUSER:$PMSHUSER $LOGS_PATH
 
 COPY setup.py ./
 COPY requirements.txt ./
diff --git a/components/pm-subscription-handler/pmsh_service/mod/__init__.py b/components/pm-subscription-handler/pmsh_service/mod/__init__.py
index f8b1c59..722188a 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/__init__.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/__init__.py
@@ -27,7 +27,7 @@
 basedir = os.path.abspath(os.path.dirname(__file__))
 
 
-def create_prod_app():
+def create_app():
     logger.create_loggers(os.getenv('LOGS_PATH'))
     connex_app = App(__name__, specification_dir=basedir)
     app = connex_app.app
@@ -38,18 +38,6 @@
     return app
 
 
-def create_test_app():
-    logger.create_loggers('./unit_test_logs')
-    connex_app = App(__name__, specification_dir=basedir)
-    app = connex_app.app
-    app.config['TESTING'] = True
-    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
-    app.config['SQLALCHEMY_RECORD_QUERIES'] = True
-    app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('TEST_DB_URL', 'sqlite://')
-    db.init_app(app)
-    return app
-
-
 def get_db_connection_url():
     pg_host = os.getenv('PMSH_PG_URL')
     pg_user = os.getenv('PMSH_PG_USERNAME')
diff --git a/components/pm-subscription-handler/pmsh_service/pmsh_service.py b/components/pm-subscription-handler/pmsh_service/pmsh_service.py
index 99689d0..c564a5e 100755
--- a/components/pm-subscription-handler/pmsh_service/pmsh_service.py
+++ b/components/pm-subscription-handler/pmsh_service/pmsh_service.py
@@ -20,7 +20,7 @@
 
 import mod.aai_client as aai_client
 import mod.pmsh_logging as logger
-from mod import db, create_prod_app
+from mod import db, create_app
 from mod.config_handler import ConfigHandler
 from mod.subscription import Subscription
 
@@ -28,7 +28,7 @@
 def main():
 
     try:
-        app = create_prod_app()
+        app = create_app()
         app.app_context().push()
         db.create_all(app=app)
 
diff --git a/components/pm-subscription-handler/tests/test_network_function.py b/components/pm-subscription-handler/tests/test_network_function.py
index 2af1489..267851d 100755
--- a/components/pm-subscription-handler/tests/test_network_function.py
+++ b/components/pm-subscription-handler/tests/test_network_function.py
@@ -16,17 +16,23 @@
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=====================================================
 import unittest
+from test.support import EnvironmentVarGuard
+from unittest import mock
 
-from mod import db, create_test_app
+from mod import db, create_app
 from mod.network_function import NetworkFunction
 
 
 class NetworkFunctionTests(unittest.TestCase):
 
-    def setUp(self):
+    @mock.patch('mod.get_db_connection_url')
+    def setUp(self, mock_get_db_url):
+        mock_get_db_url.return_value = 'sqlite://'
         self.nf_1 = NetworkFunction(nf_name='pnf_1', orchestration_status='Inventoried')
         self.nf_2 = NetworkFunction(nf_name='pnf_2', orchestration_status='Active')
-        self.app = create_test_app()
+        self.env = EnvironmentVarGuard()
+        self.env.set('LOGS_PATH', './unit_test_logs')
+        self.app = create_app()
         self.app_context = self.app.app_context()
         self.app_context.push()
         db.create_all()
diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py
index 3c7651d..97c1d6a 100755
--- a/components/pm-subscription-handler/tests/test_subscription.py
+++ b/components/pm-subscription-handler/tests/test_subscription.py
@@ -24,15 +24,17 @@
 from requests import Session
 
 import mod.aai_client as aai_client
-from mod import db, create_test_app
+from mod import db, create_app
 from mod.network_function import NetworkFunction
 from mod.subscription import Subscription, NetworkFunctionFilter
 
 
 class SubscriptionTest(unittest.TestCase):
 
+    @mock.patch('mod.get_db_connection_url')
     @mock.patch.object(Session, 'put')
-    def setUp(self, mock_session):
+    def setUp(self, mock_session, mock_get_db_url):
+        mock_get_db_url.return_value = 'sqlite://'
         with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
             self.aai_response_data = data.read()
         mock_session.return_value.status_code = 200
@@ -40,6 +42,8 @@
         self.env = EnvironmentVarGuard()
         self.env.set('AAI_SERVICE_HOST', '1.2.3.4')
         self.env.set('AAI_SERVICE_PORT_AAI_SSL', '8443')
+        self.env.set('TESTING', 'True')
+        self.env.set('LOGS_PATH', './unit_test_logs')
         with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
             self.cbs_data_1 = json.load(data)
         with open(os.path.join(os.path.dirname(__file__),
@@ -50,7 +54,7 @@
         self.nf_1 = NetworkFunction(nf_name='pnf_1', orchestration_status='Inventoried')
         self.nf_2 = NetworkFunction(nf_name='pnf_2', orchestration_status='Active')
         self.xnf_filter = NetworkFunctionFilter(**self.sub_1.nfFilter)
-        self.app = create_test_app()
+        self.app = create_app()
         self.app_context = self.app.app_context()
         self.app_context.push()
         db.create_all()