Skip to content

Commit 2d5cc29

Browse files
authored
Merge pull request #40 from python-microservices/feature/improvement_issue_34
Feature/improvement issue 34
2 parents 924f423 + 8054d8e commit 2d5cc29

File tree

5 files changed

+72
-38
lines changed

5 files changed

+72
-38
lines changed

Pipfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ anyconfig = ">=0.9.8"
1212
swagger-ui-bundle = ">=0.0.2"
1313
connexion = {extras = ["swagger-ui"],version = ">=2.2.0"}
1414
flask-opentracing = "==0.2.0"
15-
tornado = "==5.1.1"
15+
tornado = "==4.5.3"
1616

1717
[dev-packages]
1818
requests-mock = "*"
@@ -24,3 +24,6 @@ tox = "*"
2424

2525
[requires]
2626
python_version = "3.6"
27+
28+
[pipenv]
29+
allow_prereleases = true

Pipfile.lock

Lines changed: 38 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/mininum_microservice_docker/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import os
21
from flask import jsonify
2+
33
from pyms.flask.app import Microservice
44

55
ms = Microservice(service="my-minimal-microservice", path=__file__)

pyms/config/confile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def normalize_keys(self, key):
5050
key = key.replace("-", "_")
5151
return key
5252

53+
def __eq__(self, other):
54+
if not isinstance(other, ConfFile) and not isinstance(other, dict):
55+
return False
56+
return dict(self) == dict(other)
57+
5358
def __getattr__(self, name, *args, **kwargs):
5459
try:
5560
keys = self.normalize_keys(name).split(".")

tests/tests_config.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import unittest
44

55
from pyms.config.conf import Config
6-
76
from pyms.config.confile import ConfFile
87
from pyms.constants import CONFIGMAP_FILE_ENVIRONMENT, LOGGER_NAME
98
from pyms.exceptions import AttrDoesNotExistException, ConfigDoesNotFoundException, ServiceDoesNotExistException
@@ -48,6 +47,26 @@ def test_dictionary_recursive_dict_normal_key_dinamyc(self):
4847
config = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}, "test_2": "c"})
4948
self.assertEqual(getattr(config, "test_1.test_1_2"), "b")
5049

50+
def test_equal_instances_error(self):
51+
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}, "test_2": "c"})
52+
config2 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
53+
self.assertNotEqual(config1, config2)
54+
55+
def test_equal_instances_error2(self):
56+
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
57+
config2 = {"test-1": {"test-1-1": "a", "test-1-2": "b"}}
58+
self.assertNotEqual(config1, config2)
59+
60+
def test_equal_instances_ok(self):
61+
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
62+
config2 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
63+
self.assertEqual(config1, config2)
64+
65+
def test_equal_instances_ok2(self):
66+
config1 = ConfFile(config={"test-1": {"test-1-1": "a", "test_1-2": "b"}})
67+
config2 = {"test_1": {"test_1_1": "a", "test_1_2": "b"}}
68+
self.assertEqual(config1, config2)
69+
5170
def test_dictionary_attribute_not_exists(self):
5271
config = ConfFile(config={"test-1": "a"})
5372
with self.assertRaises(AttrDoesNotExistException):
@@ -98,3 +117,7 @@ def test_empty_conf_two_levels(self):
98117
def test_empty_conf_three_levels(self):
99118
config = ConfFile(empty_init=True)
100119
self.assertEqual(config.my_ms.level_two.level_three, {})
120+
121+
122+
if __name__ == '__main__':
123+
unittest.main()

0 commit comments

Comments
 (0)