dusking closed pull request #217: ARIA-426 support models prefix
URL: https://github.com/apache/incubator-ariatosca/pull/217
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/aria/__init__.py b/aria/__init__.py
index 980a2bb1..982c5d24 100644
--- a/aria/__init__.py
+++ b/aria/__init__.py
@@ -66,10 +66,18 @@ def install_aria_extensions(strict=True):
     extension.init()
 
 
-def application_model_storage(api, api_kwargs=None, initiator=None, 
initiator_kwargs=None):
+def application_model_storage(api, api_kwargs=None, initiator=None, 
initiator_kwargs=None,
+                              models_prefix=None):
     """
     Initiate model storage.
     """
+    if models_prefix:
+        # The metadata is the same for all models,
+        # so we're just extracting the metadata from the first model
+        metadata = modeling.models.models_to_register[0].metadata
+        for table in metadata.sorted_tables:
+            if not table.name.startswith(models_prefix):
+                table.name = models_prefix + table.name
     return storage.ModelStorage(api_cls=api,
                                 api_kwargs=api_kwargs,
                                 items=modeling.models.models_to_register,
diff --git a/tests/test_init.py b/tests/test_init.py
new file mode 100644
index 00000000..00e5c94d
--- /dev/null
+++ b/tests/test_init.py
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from aria import storage, modeling
+from aria import application_model_storage
+
+
+def test_models_prefix(mocker):
+    prefix = 'tosca_'
+    models_to_register = modeling.models.models_to_register
+    try:
+        mocker.patch.object(storage, 'ModelStorage')
+        application_model_storage(None, models_prefix=prefix)
+        assert all([model.__table__.name.startswith(prefix) for model in 
models_to_register])
+    finally:
+        for model in models_to_register:
+            model.__table__.name = model.__table__.name.replace(prefix, '')
diff --git a/tox.ini b/tox.ini
index d642f174..4adf9c06 100644
--- a/tox.ini
+++ b/tox.ini
@@ -11,7 +11,7 @@
 # limitations under the License.
 
 [tox]
-envlist=core,extensions,e2e,windows,ssh,pylint_core,pylint_tests,docs
+envlist=core,customdb,extensions,e2e,windows,ssh,pylint_core,pylint_tests,docs
 pytest_processes={env:CONCURRENCY:auto}
 pylint_jobs={env:CONCURRENCY:0}
 
@@ -30,6 +30,7 @@ deps=
     tests/requirements.txt
 basepython=
   core: python2.7
+  customdb: python2.7
   extensions: python2.7
   e2e: python2.7
   ssh: python2.7
@@ -48,6 +49,13 @@ commands=
     --cov-report term-missing \
     --cov aria
 
+[testenv:customdb]
+commands=
+  pytest tests/test_init.py \
+    --numprocesses={[tox]pytest_processes} \
+    --cov-report term-missing \
+    --cov aria
+
 [testenv:extensions]
 commands=
   pytest tests/extensions \


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to