Skip to content

Commit 3495104

Browse files
authored
Removed required param "path" in Microservice Class (#97)
* Removed required param "path" in Microservice Class * Updated tests and docstrings
1 parent 8870d24 commit 3495104

File tree

9 files changed

+20
-10
lines changed

9 files changed

+20
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ from flask import jsonify
6666

6767
from pyms.flask.app import Microservice
6868

69-
ms = Microservice(path=__file__) # 1.1
69+
ms = Microservice() # 1.1
7070
app = ms.create_app() # 2.1
7171

7272

docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from flask import jsonify
1010

1111
from pyms.flask.app import Microservice
1212

13-
ms = Microservice(path=__file__) # 1.1
13+
ms = Microservice() # 1.1
1414
app = ms.create_app() # 2.1
1515

1616

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from pyms.flask.app import Microservice
22

3-
ms = Microservice(path=__file__)
3+
ms = Microservice()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from pyms.flask.app import Microservice
22

3-
ms = Microservice(path=__file__)
3+
ms = Microservice()

examples/microservice_swagger/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pyms.flask.app import Microservice
22

3-
ms = Microservice(path=__file__)
3+
ms = Microservice()
44
app = ms.create_app()
55

66
if __name__ == '__main__':

pyms/flask/app/create_app.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ def example():
9797
_singleton = True
9898

9999
def __init__(self, *args, **kwargs):
100-
self.path = os.path.dirname(kwargs.get("path", __file__))
100+
"""
101+
You can get the relative path from the current directory with `__file__` in path param. The path must be
102+
the folder where PyMS search for default config file, default swagger definition and encrypt key.
103+
:param args:
104+
:param kwargs: "path", optional, the current directory where `Microservice` class is instanciated
105+
"""
106+
path = kwargs.get("path", None)
107+
self.path = os.path.abspath("")
108+
if path:
109+
self.path = os.path.dirname(os.path.abspath(path))
110+
101111
validate_conf()
102112
self.config = get_conf(path=self.path, service=CONFIG_BASE)
103113
self.init_services()

tests/config-tests-flask-swagger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pyms:
66
config:
77
DEBUG: true
88
TESTING: true
9-
APP_NAME: "Python Microservice With Flask"
9+
APP_NAME: "Python Microservice With Flask in tests"
1010
APPLICATION_ROOT: /
1111
test_var: general
1212
subservice1:

tests/test_flask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class HomeWithFlaskTests(unittest.TestCase):
2323
def setUp(self):
2424
os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
2525
"config-tests-flask.yml")
26-
ms = MyMicroservice(path=__file__)
26+
ms = MyMicroservice()
2727
ms.reload_conf()
2828
self.app = ms.create_app()
2929
self.client = self.app.test_client()
@@ -54,7 +54,7 @@ def setUp(self):
5454
ms = MyMicroservice(path=__file__)
5555
self.app = ms.create_app()
5656
self.client = self.app.test_client()
57-
self.assertEqual("Python Microservice With Flask", self.app.config["APP_NAME"])
57+
self.assertEqual("Python Microservice With Flask in tests", self.app.config["APP_NAME"])
5858

5959
def test_healthcheck(self):
6060
response = self.client.get('/healthcheck')

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ envlist=py36,py37,pylint,flake8,safety,bandit,docs
44
[travis]
55
python =
66
3.6: py36
7-
3.7: py37,pylint,flake8,safety,bandit,docs
7+
3.7: py37,pylint,flake8,bandit,docs
88
3.8: py38
99

1010
[testenv]

0 commit comments

Comments
 (0)