Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyconfig = ">=0.9.8"
swagger-ui-bundle = ">=0.0.2"
connexion = {extras = ["swagger-ui"],version = ">=2.2.0"}
flask-opentracing = "==0.2.0"
tornado = "==5.1.1"
tornado = "==4.5.3"

[dev-packages]
requests-mock = "*"
Expand All @@ -24,3 +24,6 @@ tox = "*"

[requires]
python_version = "3.6"

[pipenv]
allow_prereleases = true
73 changes: 38 additions & 35 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/mininum_microservice_docker/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from flask import jsonify

from pyms.flask.app import Microservice

ms = Microservice(service="my-minimal-microservice", path=__file__)
Expand Down
5 changes: 5 additions & 0 deletions pyms/config/confile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def normalize_keys(self, key):
key = key.replace("-", "_")
return key

def __eq__(self, other):
if not isinstance(other, ConfFile) and not isinstance(other, dict):
return False
return dict(self) == dict(other)

def __getattr__(self, name, *args, **kwargs):
try:
keys = self.normalize_keys(name).split(".")
Expand Down
25 changes: 24 additions & 1 deletion tests/tests_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import unittest

from pyms.config.conf import Config

from pyms.config.confile import ConfFile
from pyms.constants import CONFIGMAP_FILE_ENVIRONMENT, LOGGER_NAME
from pyms.exceptions import AttrDoesNotExistException, ConfigDoesNotFoundException, ServiceDoesNotExistException
Expand Down Expand Up @@ -48,6 +47,26 @@ def test_dictionary_recursive_dict_normal_key_dinamyc(self):
config = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}, "test_2": "c"})
self.assertEqual(getattr(config, "test_1.test_1_2"), "b")

def test_equal_instances_error(self):
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}, "test_2": "c"})
config2 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
self.assertNotEqual(config1, config2)

def test_equal_instances_error2(self):
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
config2 = {"test-1": {"test-1-1": "a", "test-1-2": "b"}}
self.assertNotEqual(config1, config2)

def test_equal_instances_ok(self):
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
config2 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
self.assertEqual(config1, config2)

def test_equal_instances_ok2(self):
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
config2 = {"test_1": {"test_1_1": "a", "test_1_2": "b"}}
self.assertEqual(config1, config2)

def test_dictionary_attribute_not_exists(self):
config = ConfFile(config={"test-1": "a"})
with self.assertRaises(AttrDoesNotExistException):
Expand Down Expand Up @@ -98,3 +117,7 @@ def test_empty_conf_two_levels(self):
def test_empty_conf_three_levels(self):
config = ConfFile(empty_init=True)
self.assertEqual(config.my_ms.level_two.level_three, {})


if __name__ == '__main__':
unittest.main()