python-ubercode-utils 2.0.4__tar.gz → 2.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/PKG-INFO +1 -1
  2. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/python_ubercode_utils.egg-info/PKG-INFO +1 -1
  3. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/setup.py +1 -1
  4. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/test/test_urls.py +15 -2
  5. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/urls.py +26 -2
  6. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/LICENSE +0 -0
  7. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/MANIFEST.in +0 -0
  8. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/README.md +0 -0
  9. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/python_ubercode_utils.egg-info/SOURCES.txt +0 -0
  10. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/python_ubercode_utils.egg-info/dependency_links.txt +0 -0
  11. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/python_ubercode_utils.egg-info/not-zip-safe +0 -0
  12. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/python_ubercode_utils.egg-info/top_level.txt +0 -0
  13. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/setup.cfg +0 -0
  14. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/test/test_convert.py +0 -0
  15. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/test/test_cursor.py +0 -0
  16. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/test/test_data.py +0 -0
  17. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/test/test_dataframe.py +0 -0
  18. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/test/test_environment.py +0 -0
  19. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/test/test_logging.py +0 -0
  20. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/__init__.py +0 -0
  21. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/__init__.py +0 -0
  22. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/convert.py +0 -0
  23. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/cursor.py +0 -0
  24. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/data.py +0 -0
  25. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/dataframe.py +0 -0
  26. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/environment.py +0 -0
  27. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.5}/ubercode/utils/logging.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python_ubercode_utils
3
- Version: 2.0.4
3
+ Version: 2.0.5
4
4
  Summary: Core python utilities for all apps
5
5
  Home-page: https://github.com/sstacha/python-ubercode-utils
6
6
  Author: Steve Stacha
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-ubercode-utils
3
- Version: 2.0.4
3
+ Version: 2.0.5
4
4
  Summary: Core python utilities for all apps
5
5
  Home-page: https://github.com/sstacha/python-ubercode-utils
6
6
  Author: Steve Stacha
@@ -4,7 +4,7 @@ with open("README.md", "r") as fh:
4
4
  long_description = fh.read()
5
5
 
6
6
  setuptools.setup(name='python_ubercode_utils',
7
- version='2.0.4',
7
+ version='2.0.5',
8
8
  description='Core python utilities for all apps',
9
9
  long_description=long_description,
10
10
  long_description_content_type="text/markdown",
@@ -1,6 +1,4 @@
1
1
  import unittest
2
- from contextlib import redirect_stdout
3
- from io import StringIO
4
2
 
5
3
  from ubercode.utils.urls import ParsedUrl
6
4
  from ubercode.utils.urls import ParsedQueryString
@@ -90,6 +88,21 @@ class TestUrls(unittest.TestCase):
90
88
  # test encoded @ for password since that could be needed
91
89
  dj_db_url = DjUrl(':asfcasdf23%401:/!?--atencoded')
92
90
  self.assertEqual(dj_db_url.password, 'asfcasdf23@1:/!')
91
+ # test that we can pass a dict of database properties and have it fill in
92
+ default = {
93
+ 'ENGINE': 'django.db.backends.mysql',
94
+ 'HOST': 'localhost',
95
+ 'USER': 'scott',
96
+ 'PASSWORD': 'tiger',
97
+ 'PORT': '3306',
98
+ 'NAME': 'test'
99
+ }
100
+ dj_db_url = DjUrl().from_dict(default)
101
+ self.assertEqual(str(dj_db_url), 'django.db.backends.mysql://scott:t***r@localhost:3306/test')
102
+ # test that to_dict ignores None values so we only have overrides
103
+ dj_db_url = DjUrl(':testoverridepasswordonly')
104
+ override_dict = dj_db_url.to_dict()
105
+ self.assertEqual(str(override_dict), "{'PASSWORD': 'testoverridepasswordonly'}")
93
106
 
94
107
  # --- basic retrieval
95
108
  # -------------------
@@ -290,10 +290,34 @@ class DjUrl:
290
290
  elif len(hoststr) > 0:
291
291
  self.host = hoststr
292
292
 
293
+ #
294
+ def from_dict(self, properties_dict: dict):
295
+ """
296
+ overrides instance properties with dictionary values
297
+ NOTE: rule is that we expect the instance propery to be attribute uppercased
298
+ EX: self.name = properties_dict[self.name.upper()]
299
+
300
+ :param properties_dict: dictionary values
301
+ :return: this instance for chaining. ex: x = DjUrl().from_dict({"ENGINE": "test"})
302
+ """
303
+ if isinstance(properties_dict, dict):
304
+ for attr, value in vars(DjUrl).items():
305
+ if not attr.startswith('__') and not callable(value) and not attr.startswith('_'):
306
+ setattr(self, attr, properties_dict.get(attr.upper(), value))
307
+ return self
308
+
293
309
  def to_dict(self) -> dict:
310
+ """
311
+ converts instance properties to dictionary values
312
+ NOTE: does not convert None values
313
+
314
+ :return: dict of values in upper case for replacement in django databases settings
315
+ """
294
316
  dct = {}
295
- for attr, value in vars(self).items():
296
- dct[attr.upper()] = value
317
+ for attr, value in vars(DjUrl).items():
318
+ if not attr.startswith('__') and not callable(value) and not attr.startswith('_'):
319
+ if getattr(self, attr) is not None:
320
+ dct[attr.upper()] = getattr(self, attr)
297
321
  return dct
298
322
 
299
323
  def __str__(self) -> str: