python-ubercode-utils 2.0.4__tar.gz → 2.0.6__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.6}/PKG-INFO +1 -1
  2. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/python_ubercode_utils.egg-info/PKG-INFO +1 -1
  3. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/setup.py +1 -1
  4. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/test/test_environment.py +7 -0
  5. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/test/test_urls.py +15 -2
  6. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/utils/environment.py +1 -1
  7. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/utils/urls.py +26 -2
  8. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/LICENSE +0 -0
  9. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/MANIFEST.in +0 -0
  10. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/README.md +0 -0
  11. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/python_ubercode_utils.egg-info/SOURCES.txt +0 -0
  12. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/python_ubercode_utils.egg-info/dependency_links.txt +0 -0
  13. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/python_ubercode_utils.egg-info/not-zip-safe +0 -0
  14. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/python_ubercode_utils.egg-info/top_level.txt +0 -0
  15. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/setup.cfg +0 -0
  16. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/test/test_convert.py +0 -0
  17. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/test/test_cursor.py +0 -0
  18. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/test/test_data.py +0 -0
  19. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/test/test_dataframe.py +0 -0
  20. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/test/test_logging.py +0 -0
  21. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/__init__.py +0 -0
  22. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/utils/__init__.py +0 -0
  23. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/utils/convert.py +0 -0
  24. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/utils/cursor.py +0 -0
  25. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/utils/data.py +0 -0
  26. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/ubercode/utils/dataframe.py +0 -0
  27. {python_ubercode_utils-2.0.4 → python_ubercode_utils-2.0.6}/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.6
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.6
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.6',
8
8
  description='Core python utilities for all apps',
9
9
  long_description=long_description,
10
10
  long_description_content_type="text/markdown",
@@ -109,6 +109,13 @@ class TestEnvironment(unittest.TestCase):
109
109
  self.assertTrue("Test_************sword" in sout.getvalue())
110
110
  # test a None still works for initialization
111
111
  self.assertIsNotNone(Environment())
112
+ # bug: test that a missing db gets created instead of failing (threw key error before)
113
+ os_vars = {
114
+ 'DATABASES__booger__ENGINE': 'django.db.backends.mysql'
115
+ }
116
+ env2 = Environment(environment_variable_map=os_vars)
117
+ self.assertIsNotNone(env2.override_database_variables(DATABASES))
118
+
112
119
 
113
120
  def test_override_database_urls(self):
114
121
  # we will start with the default dict for a new django install
@@ -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
  # -------------------
@@ -199,7 +199,7 @@ class Environment:
199
199
  _log_from_value = 'None'
200
200
  _log_to_value = str(v)
201
201
  # we may be setting up a completely new database from scratch so create if it doesn't exist
202
- if not db_dict[db_parts[1]]:
202
+ if not db_dict.get(db_parts[1]):
203
203
  self._logger.debug(f'database {db_parts[0]}[{db_parts[1]}] was not found; creating...')
204
204
  db_dict[db_parts[1]] = {}
205
205
  # we now have db dict; we may not have a property already defined; if not we want to add it
@@ -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: