hdx-python-database 1.3.6__tar.gz → 1.3.8__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 (36) hide show
  1. hdx_python_database-1.3.6/.config/pre-commit-config.yaml → hdx_python_database-1.3.8/.pre-commit-config.yaml +5 -6
  2. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/PKG-INFO +4 -2
  3. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/documentation/mkdocs.yaml +3 -1
  4. hdx_python_database-1.3.8/hatch.toml +34 -0
  5. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/pyproject.toml +2 -48
  6. {hdx_python_database-1.3.6/.config → hdx_python_database-1.3.8}/pytest.ini +1 -1
  7. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/requirements.txt +46 -51
  8. {hdx_python_database-1.3.6/.config → hdx_python_database-1.3.8}/ruff.toml +0 -1
  9. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/_version.py +16 -3
  10. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/database.py +28 -12
  11. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/postgresql.py +13 -2
  12. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/utils.py +1 -3
  13. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/test_database.py +1 -3
  14. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/test_dburi.py +4 -12
  15. hdx_python_database-1.3.6/tests/hdx/database/test_recreate.py → hdx_python_database-1.3.8/tests/hdx/database/test_drop_recreate.py +7 -0
  16. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/test_ssh.py +1 -3
  17. /hdx_python_database-1.3.6/.config/coveragerc → /hdx_python_database-1.3.8/.coveragerc +0 -0
  18. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/.github/workflows/publish.yaml +0 -0
  19. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/.github/workflows/run-python-tests.yaml +0 -0
  20. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/.gitignore +0 -0
  21. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/CONTRIBUTING.md +0 -0
  22. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/LICENSE +0 -0
  23. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/README.md +0 -0
  24. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/documentation/.readthedocs.yaml +0 -0
  25. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/documentation/index.md +0 -0
  26. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/__init__.py +0 -0
  27. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/dburi.py +0 -0
  28. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/no_timezone.py +0 -0
  29. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/views.py +0 -0
  30. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/src/hdx/database/with_timezone.py +0 -0
  31. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/fixtures/test.db +0 -0
  32. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/__init__.py +0 -0
  33. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/conftest.py +0 -0
  34. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/dbtestdate.py +0 -0
  35. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/test_postgresql.py +0 -0
  36. {hdx_python_database-1.3.6 → hdx_python_database-1.3.8}/tests/hdx/database/test_reflect.py +0 -0
@@ -1,5 +1,5 @@
1
1
  default_language_version:
2
- python: python3.12
2
+ python: python3.13
3
3
  repos:
4
4
  - repo: https://github.com/pre-commit/pre-commit-hooks
5
5
  rev: v5.0.0
@@ -8,16 +8,15 @@ repos:
8
8
  - id: end-of-file-fixer
9
9
  - id: check-ast
10
10
  - repo: https://github.com/astral-sh/ruff-pre-commit
11
- rev: v0.9.10
11
+ rev: v0.12.0
12
12
  hooks:
13
13
  # Run the linter.
14
- - id: ruff
15
- args: [--config, .config/ruff.toml, --fix]
14
+ - id: ruff-check
15
+ args: [ --fix ]
16
16
  # Run the formatter.
17
17
  - id: ruff-format
18
- args: [--config, .config/ruff.toml]
19
18
  - repo: https://github.com/astral-sh/uv-pre-commit
20
- rev: 0.6.5
19
+ rev: 0.7.14
21
20
  hooks:
22
21
  # Run the pip compile
23
22
  - id: pip-compile
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hdx-python-database
3
- Version: 1.3.6
3
+ Version: 1.3.8
4
4
  Summary: HDX Python database utilities
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-database
6
6
  Author-email: Michael Rans <rans@email.com>
@@ -24,7 +24,7 @@ Classifier: Programming Language :: Python :: 3.10
24
24
  Classifier: Programming Language :: Python :: 3.11
25
25
  Classifier: Programming Language :: Python :: 3.12
26
26
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
- Requires-Python: >=3.8
27
+ Requires-Python: >=3.10
28
28
  Requires-Dist: sqlalchemy>=2
29
29
  Provides-Extra: dev
30
30
  Requires-Dist: pre-commit; extra == 'dev'
@@ -35,8 +35,10 @@ Requires-Dist: psycopg[binary]; extra == 'postgresql'
35
35
  Provides-Extra: sshtunnel
36
36
  Requires-Dist: sshtunnel; extra == 'sshtunnel'
37
37
  Provides-Extra: test
38
+ Requires-Dist: psycopg[binary]; extra == 'test'
38
39
  Requires-Dist: pytest; extra == 'test'
39
40
  Requires-Dist: pytest-cov; extra == 'test'
41
+ Requires-Dist: sshtunnel; extra == 'test'
40
42
  Description-Content-Type: text/markdown
41
43
 
42
44
  [![Build Status](https://github.com/OCHA-DAP/hdx-python-database/actions/workflows/run-python-tests.yaml/badge.svg)](https://github.com/OCHA-DAP/hdx-python-database/actions/workflows/run-python-tests.yaml)
@@ -12,5 +12,7 @@ plugins:
12
12
  nav:
13
13
  - Home: index.md
14
14
  - API Documentation:
15
- - Database: $src/hdx.database.*
15
+ - Database:
16
+ - $src/hdx.database.Database
17
+ - $src/hdx.database.DatabaseError
16
18
  - PostgreSQL specific: $src/hdx.database.postgresql.*
@@ -0,0 +1,34 @@
1
+ # Build
2
+
3
+ [build.targets.wheel]
4
+ packages = ["src/hdx"]
5
+
6
+ [build.hooks.vcs]
7
+ version-file = "src/hdx/database/_version.py"
8
+
9
+ # Versioning
10
+
11
+ [version]
12
+ source = "vcs"
13
+
14
+ [version.raw-options]
15
+ local_scheme = "no-local-version"
16
+ version_scheme = "python-simplified-semver"
17
+
18
+ # Tests
19
+
20
+ [envs.hatch-test]
21
+ features = ["test"]
22
+
23
+ [[envs.hatch-test.matrix]]
24
+ python = ["3.13"]
25
+
26
+ [envs.hatch-test.scripts]
27
+ run = """
28
+ pytest --rootdir=. --junitxml=test-results.xml --cov --no-cov-on-fail \
29
+ --cov-report=lcov --cov-report=term-missing
30
+ """
31
+
32
+ [envs.hatch-static-analysis]
33
+ config-path = "none"
34
+ dependencies = ["ruff==0.12.0"]
@@ -31,7 +31,7 @@ classifiers = [
31
31
  "Operating System :: MacOS",
32
32
  "Operating System :: Microsoft :: Windows",
33
33
  ]
34
- requires-python = ">=3.8"
34
+ requires-python = ">=3.10"
35
35
 
36
36
  dependencies = [
37
37
  "sqlalchemy>=2",
@@ -48,52 +48,6 @@ Homepage = "https://github.com/OCHA-DAP/hdx-python-database"
48
48
  [project.optional-dependencies]
49
49
  sshtunnel = ["sshtunnel"]
50
50
  postgresql = ["psycopg[binary]"]
51
- test = ["pytest", "pytest-cov"]
51
+ test = ["sshtunnel", "psycopg[binary]", "pytest", "pytest-cov"]
52
52
  dev = ["pre-commit"]
53
53
  docs = ["mkapi"]
54
-
55
-
56
- #########
57
- # Hatch #
58
- #########
59
-
60
- # Build
61
-
62
- [tool.hatch.build.targets.wheel]
63
- packages = ["src/hdx"]
64
-
65
- [tool.hatch.build.hooks.vcs]
66
- version-file = "src/hdx/database/_version.py"
67
-
68
- # Versioning
69
-
70
- [tool.hatch.version]
71
- source = "vcs"
72
-
73
- [tool.hatch.version.raw-options]
74
- local_scheme = "no-local-version"
75
- version_scheme = "python-simplified-semver"
76
-
77
- # Tests
78
-
79
- [tool.hatch.envs.hatch-test]
80
- features = ["sshtunnel", "postgresql", "test"]
81
-
82
- [[tool.hatch.envs.hatch-test.matrix]]
83
- python = ["3.12"]
84
-
85
- [tool.hatch.envs.hatch-test.scripts]
86
- run = """
87
- pytest -c .config/pytest.ini --rootdir=. --junitxml=test-results.xml \
88
- --cov --cov-config=.config/coveragerc --no-cov-on-fail \
89
- --cov-report=lcov --cov-report=term-missing
90
- """
91
-
92
- [tool.hatch.envs.hatch-static-analysis]
93
- dependencies = ["ruff==0.9.10"]
94
-
95
- [tool.hatch.envs.hatch-static-analysis.scripts]
96
- format-check = ["ruff format --config .config/ruff.toml --check --diff {args:.}",]
97
- format-fix = ["ruff format --config .config/ruff.toml {args:.}",]
98
- lint-check = ["ruff check --config .config/ruff.toml {args:.}",]
99
- lint-fix = ["ruff check --config .config/ruff.toml --fix {args:.}",]
@@ -1,4 +1,4 @@
1
1
  [pytest]
2
- pythonpath = ../src
2
+ pythonpath = src
3
3
  addopts = "--color=yes"
4
4
  log_cli = 1
@@ -1,69 +1,66 @@
1
1
  # This file was autogenerated by uv via the following command:
2
2
  # uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
3
- astdoc==1.1.5
3
+ astdoc==1.3.2
4
4
  # via mkapi
5
5
  babel==2.17.0
6
6
  # via mkdocs-material
7
- backrefs==5.8
7
+ backrefs==5.9
8
8
  # via mkdocs-material
9
- bcrypt==4.3.0
9
+ bcrypt==5.0.0
10
10
  # via paramiko
11
- certifi==2025.1.31
11
+ certifi==2025.10.5
12
12
  # via requests
13
- cffi==1.17.1
13
+ cffi==2.0.0
14
14
  # via
15
15
  # cryptography
16
16
  # pynacl
17
17
  cfgv==3.4.0
18
18
  # via pre-commit
19
- charset-normalizer==3.4.1
19
+ charset-normalizer==3.4.4
20
20
  # via requests
21
- click==8.1.8
21
+ click==8.3.0
22
22
  # via mkdocs
23
23
  colorama==0.4.6
24
24
  # via mkdocs-material
25
- coverage==7.7.0
25
+ coverage==7.11.0
26
26
  # via pytest-cov
27
- cryptography==44.0.2
27
+ cryptography==46.0.3
28
28
  # via paramiko
29
- distlib==0.3.9
29
+ distlib==0.4.0
30
30
  # via virtualenv
31
- filelock==3.18.0
31
+ filelock==3.20.0
32
32
  # via virtualenv
33
33
  ghp-import==2.1.0
34
34
  # via mkdocs
35
- greenlet==3.1.1
35
+ greenlet==3.2.4
36
36
  # via sqlalchemy
37
- identify==2.6.9
37
+ identify==2.6.15
38
38
  # via pre-commit
39
- idna==3.10
39
+ idna==3.11
40
40
  # via requests
41
- iniconfig==2.0.0
41
+ iniconfig==2.3.0
42
42
  # via pytest
43
+ invoke==2.2.1
44
+ # via paramiko
43
45
  jinja2==3.1.6
44
46
  # via
45
47
  # mkapi
46
48
  # mkdocs
47
49
  # mkdocs-material
48
- markdown==3.7
50
+ markdown==3.9
49
51
  # via
50
- # astdoc
51
52
  # mkdocs
52
53
  # mkdocs-material
53
54
  # pymdown-extensions
54
- markdown-it-py==3.0.0
55
- # via rich
56
- markupsafe==3.0.2
55
+ markupsafe==3.0.3
57
56
  # via
58
57
  # jinja2
59
58
  # mkdocs
60
- mdurl==0.1.2
61
- # via markdown-it-py
62
59
  mergedeep==1.3.4
63
60
  # via
64
61
  # mkdocs
65
62
  # mkdocs-get-deps
66
- mkapi==4.1.3
63
+ mkapi==4.5.0
67
64
  # via hdx-python-database (pyproject.toml)
68
65
  mkdocs==1.6.1
69
66
  # via
@@ -71,78 +68,76 @@ mkdocs==1.6.1
71
68
  # mkdocs-material
72
69
  mkdocs-get-deps==0.2.0
73
70
  # via mkdocs
74
- mkdocs-material==9.6.8
71
+ mkdocs-material==9.6.23
75
72
  # via mkapi
76
73
  mkdocs-material-extensions==1.3.1
77
74
  # via mkdocs-material
78
75
  nodeenv==1.9.1
79
76
  # via pre-commit
80
- packaging==24.2
77
+ packaging==25.0
81
78
  # via
82
79
  # mkdocs
83
80
  # pytest
84
81
  paginate==0.5.7
85
82
  # via mkdocs-material
86
- paramiko==3.5.1
83
+ paramiko==4.0.0
87
84
  # via sshtunnel
88
85
  pathspec==0.12.1
89
86
  # via mkdocs
90
- platformdirs==4.3.6
87
+ platformdirs==4.5.0
91
88
  # via
92
89
  # mkdocs-get-deps
93
90
  # virtualenv
94
- pluggy==1.5.0
95
- # via pytest
96
- pre-commit==4.1.0
91
+ pluggy==1.6.0
92
+ # via
93
+ # pytest
94
+ # pytest-cov
95
+ pre-commit==4.3.0
97
96
  # via hdx-python-database (pyproject.toml)
98
- psycopg==3.2.6
97
+ psycopg==3.2.12
99
98
  # via hdx-python-database (pyproject.toml)
100
- psycopg-binary==3.2.6
99
+ psycopg-binary==3.2.12
101
100
  # via psycopg
102
- pycparser==2.22
101
+ pycparser==2.23
103
102
  # via cffi
104
- pygments==2.19.1
103
+ pygments==2.19.2
105
104
  # via
106
105
  # mkdocs-material
107
- # rich
108
- pymdown-extensions==10.14.3
106
+ # pytest
107
+ pymdown-extensions==10.16.1
109
108
  # via mkdocs-material
110
- pynacl==1.5.0
109
+ pynacl==1.6.0
111
110
  # via paramiko
112
- pytest==8.3.5
111
+ pytest==8.4.2
113
112
  # via
114
113
  # hdx-python-database (pyproject.toml)
115
114
  # pytest-cov
116
- pytest-cov==6.0.0
115
+ pytest-cov==7.0.0
117
116
  # via hdx-python-database (pyproject.toml)
118
117
  python-dateutil==2.9.0.post0
119
118
  # via ghp-import
120
- pyyaml==6.0.2
119
+ pyyaml==6.0.3
121
120
  # via
122
121
  # mkdocs
123
122
  # mkdocs-get-deps
124
123
  # pre-commit
125
124
  # pymdown-extensions
126
125
  # pyyaml-env-tag
127
- pyyaml-env-tag==0.1
126
+ pyyaml-env-tag==1.1
128
127
  # via mkdocs
129
- requests==2.32.3
128
+ requests==2.32.5
130
129
  # via mkdocs-material
131
- rich==13.9.4
132
- # via mkapi
133
130
  six==1.17.0
134
131
  # via python-dateutil
135
- sqlalchemy==2.0.39
132
+ sqlalchemy==2.0.44
136
133
  # via hdx-python-database (pyproject.toml)
137
134
  sshtunnel==0.4.0
138
135
  # via hdx-python-database (pyproject.toml)
139
- typing-extensions==4.12.2
140
- # via
141
- # psycopg
142
- # sqlalchemy
143
- urllib3==2.3.0
136
+ typing-extensions==4.15.0
137
+ # via sqlalchemy
138
+ urllib3==2.5.0
144
139
  # via requests
145
- virtualenv==20.29.3
140
+ virtualenv==20.35.4
146
141
  # via pre-commit
147
142
  watchdog==6.0.0
148
143
  # via mkdocs
@@ -1,4 +1,3 @@
1
- line-length = 79
2
1
  exclude = ["_version.py"]
3
2
 
4
3
  [lint]
@@ -1,7 +1,14 @@
1
1
  # file generated by setuptools-scm
2
2
  # don't change, don't track in version control
3
3
 
4
- __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
5
12
 
6
13
  TYPE_CHECKING = False
7
14
  if TYPE_CHECKING:
@@ -9,13 +16,19 @@ if TYPE_CHECKING:
9
16
  from typing import Union
10
17
 
11
18
  VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
12
20
  else:
13
21
  VERSION_TUPLE = object
22
+ COMMIT_ID = object
14
23
 
15
24
  version: str
16
25
  __version__: str
17
26
  __version_tuple__: VERSION_TUPLE
18
27
  version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
19
30
 
20
- __version__ = version = '1.3.6'
21
- __version_tuple__ = version_tuple = (1, 3, 6)
31
+ __version__ = version = '1.3.8'
32
+ __version_tuple__ = version_tuple = (1, 3, 8)
33
+
34
+ __commit_id__ = commit_id = None
@@ -244,12 +244,10 @@ class Database:
244
244
  Returns:
245
245
  Tuple[Session, Any]: (SQLAlchemy session, base)
246
246
  """
247
- batches = range(len(rows) // batch_size + 1)
248
- for batch in batches:
249
- start_row = batch * batch_size
250
- end_row = start_row + batch_size
251
- batch_rows = rows[start_row:end_row]
252
- self._session.execute(insert(dbtable), batch_rows)
247
+
248
+ for i in range(0, len(rows), batch_size):
249
+ batch = rows[i : i + batch_size]
250
+ self._session.execute(insert(dbtable), batch)
253
251
  self._session.commit()
254
252
 
255
253
  @staticmethod
@@ -281,17 +279,15 @@ class Database:
281
279
  engine = create_engine(db_uri, poolclass=NullPool, echo=False)
282
280
  if reflect:
283
281
  Base = automap_base(declarative_base=table_base)
284
- Base.prepare(
285
- autoload_with=engine, reflection_options={"views": True}
286
- )
282
+ Base.prepare(autoload_with=engine, reflection_options={"views": True})
287
283
  table_base = Base
288
284
  else:
289
285
  table_base.metadata.create_all(engine)
290
286
  return Session(engine), table_base
291
287
 
292
288
  @staticmethod
293
- def recreate_schema(engine: Engine, schema_name: str = "public") -> bool:
294
- """Wipe and create empty schema in database using SQLAlchemy.
289
+ def drop_schema(engine: Engine, schema_name: str = "public") -> bool:
290
+ """Wipe schema in database using SQLAlchemy.
295
291
 
296
292
  Args:
297
293
  engine (Engine): SQLAlchemy engine to use.
@@ -307,10 +303,30 @@ class Database:
307
303
  DropSchema(schema_name, cascade=True, if_exists=True)
308
304
  )
309
305
  connection.commit()
306
+ return True
307
+ except SQLAlchemyError:
308
+ return False
309
+
310
+ @staticmethod
311
+ def recreate_schema(engine: Engine, schema_name: str = "public") -> bool:
312
+ """Wipe and create empty schema in database using SQLAlchemy.
313
+
314
+ Args:
315
+ engine (Engine): SQLAlchemy engine to use.
316
+ schema_name (str): Schema name. Defaults to "public".
317
+
318
+ Returns:
319
+ bool: True if all successful, False if not
320
+ """
321
+ # Wipe and create an empty schema
322
+ try:
323
+ with engine.connect() as connection:
310
324
  connection.execute(
311
- CreateSchema(schema_name, if_not_exists=True)
325
+ DropSchema(schema_name, cascade=True, if_exists=True)
312
326
  )
313
327
  connection.commit()
328
+ connection.execute(CreateSchema(schema_name, if_not_exists=True))
329
+ connection.commit()
314
330
  return True
315
331
  except SQLAlchemyError:
316
332
  return False
@@ -59,6 +59,12 @@ def restore_from_pgfile(db_uri: str, pg_restore_file: str) -> str:
59
59
  str: Output from the pg_restore command
60
60
  """
61
61
  db_params = get_params_from_connection_uri(db_uri)
62
+ if pg_restore_file[-3:] == ".xz":
63
+ decompress = subprocess.Popen(
64
+ ("unxz", "-c", "-d", pg_restore_file), stdout=subprocess.PIPE
65
+ ).stdout
66
+ else:
67
+ decompress = None
62
68
  subprocess_params = ["pg_restore", "-c"]
63
69
  for key, value in db_params.items():
64
70
  match key:
@@ -74,13 +80,18 @@ def restore_from_pgfile(db_uri: str, pg_restore_file: str) -> str:
74
80
  continue
75
81
  subprocess_params.append(f"{value}")
76
82
 
77
- subprocess_params.append(f"{pg_restore_file}")
83
+ if not decompress:
84
+ subprocess_params.append(pg_restore_file)
78
85
  env = environ.copy()
79
86
  password = db_params.get("password")
80
87
  if password:
81
88
  env["PGPASSWORD"] = password
82
89
  process = subprocess.run(
83
- subprocess_params, env=env, capture_output=True, encoding="utf-8"
90
+ subprocess_params,
91
+ env=env,
92
+ capture_output=True,
93
+ encoding="utf-8",
94
+ stdin=decompress,
84
95
  )
85
96
  try:
86
97
  process.check_returncode()
@@ -13,7 +13,5 @@ def camel_to_snake_case(string: str) -> str:
13
13
  Returns:
14
14
  str: String in snake case
15
15
  """
16
- string = re.sub(
17
- r"((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))", r"_\1", string
18
- )
16
+ string = re.sub(r"((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))", r"_\1", string)
19
17
  return string.lower().lstrip("_")
@@ -45,9 +45,7 @@ class TestDatabase:
45
45
  now = datetime(2023, 10, 20, 22, 35, 55, tzinfo=timezone.utc)
46
46
  rows = [{"test_date": now}]
47
47
  dbdatabase.batch_populate(rows, DBTestDate)
48
- dbtestdate = (
49
- dbsession.execute(select(DBTestDate)).all()[1][0].test_date
50
- )
48
+ dbtestdate = dbsession.execute(select(DBTestDate)).all()[1][0].test_date
51
49
  assert dbtestdate == now
52
50
 
53
51
  remove(dbpath)
@@ -17,9 +17,7 @@ class TestDBURI:
17
17
  "dialect": "postgresql",
18
18
  "driver": "psycopg",
19
19
  }
20
- connection_uri_pg = (
21
- "postgresql+psycopg://myuser:mypass@myserver:1234/mydatabase"
22
- )
20
+ connection_uri_pg = "postgresql+psycopg://myuser:mypass@myserver:1234/mydatabase"
23
21
  params_pg_no_driver = {
24
22
  "database": "mydatabase",
25
23
  "host": "myserver",
@@ -37,9 +35,7 @@ class TestDBURI:
37
35
  "dialect": "postgresql",
38
36
  "driver": None,
39
37
  }
40
- connection_uri_pg_no_driver = (
41
- "postgresql://myuser:mypass@myserver:1234/mydatabase"
42
- )
38
+ connection_uri_pg_no_driver = "postgresql://myuser:mypass@myserver:1234/mydatabase"
43
39
  params_sq_no_driver = {
44
40
  "database": "mydatabase",
45
41
  "host": "myserver",
@@ -67,9 +63,7 @@ class TestDBURI:
67
63
  include_driver=False,
68
64
  )
69
65
  assert result == TestDBURI.params_pg_no_driver
70
- result = get_params_from_connection_uri(
71
- TestDBURI.connection_uri_pg_no_driver
72
- )
66
+ result = get_params_from_connection_uri(TestDBURI.connection_uri_pg_no_driver)
73
67
  assert result == TestDBURI.params_pg_driver_none
74
68
  result = get_params_from_connection_uri(TestDBURI.connection_uri_sq)
75
69
  assert result == TestDBURI.params_sq_driver_none
@@ -77,9 +71,7 @@ class TestDBURI:
77
71
  def test_get_connection_uri(self):
78
72
  result = get_connection_uri(**TestDBURI.params_pg)
79
73
  assert result == TestDBURI.connection_uri_pg
80
- result = get_connection_uri(
81
- **TestDBURI.params_pg, include_driver=False
82
- )
74
+ result = get_connection_uri(**TestDBURI.params_pg, include_driver=False)
83
75
  assert result == TestDBURI.connection_uri_pg_no_driver
84
76
  result = get_connection_uri(**TestDBURI.params_pg_no_driver)
85
77
  assert result == TestDBURI.connection_uri_pg
@@ -1,6 +1,13 @@
1
1
  from hdx.database import Database
2
2
 
3
3
 
4
+ def test_drop_schema(mock_engine):
5
+ db_uri = "postgresql+psycopg://myuser:mypass@0.0.0.0:12345/mydatabase"
6
+ assert Database.drop_schema(mock_engine, db_uri) is True
7
+ db_uri = "Error"
8
+ assert Database.drop_schema(mock_engine, db_uri) is False
9
+
10
+
4
11
  def test_recreate_schema(mock_engine):
5
12
  db_uri = "postgresql+psycopg://myuser:mypass@0.0.0.0:12345/mydatabase"
6
13
  assert Database.recreate_schema(mock_engine, db_uri) is True
@@ -53,9 +53,7 @@ class TestSSH:
53
53
  )
54
54
  assert dbdatabase._base == NoTZBase
55
55
 
56
- with Database(
57
- ssh_host="mysshhost", ssh_port=25, **params
58
- ) as dbdatabase:
56
+ with Database(ssh_host="mysshhost", ssh_port=25, **params) as dbdatabase:
59
57
  dbsession = dbdatabase.get_session()
60
58
  assert (
61
59
  str(dbsession.bind.engine.url)