hapi-schema 0.7.0__tar.gz → 0.7.1__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 (81) hide show
  1. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/.config/ruff.toml +4 -1
  2. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/PKG-INFO +1 -1
  3. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/changelog.md +6 -0
  4. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/contributing.md +4 -0
  5. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/requirements.txt +11 -9
  6. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/_version.py +2 -2
  7. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_food_security.py +0 -4
  8. hapi_schema-0.7.1/src/hapi_schema/db_patches.py +33 -0
  9. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/conftest.py +4 -0
  10. hapi_schema-0.7.1/tests/sample_data/data_patches.py +31 -0
  11. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_food_security.py +1 -39
  12. hapi_schema-0.7.1/tests/test_patches.py +28 -0
  13. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/.config/coveragerc +0 -0
  14. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/.config/pre-commit-config.yaml +0 -0
  15. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/.config/pytest.ini +0 -0
  16. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/.github/workflows/publish.yaml +0 -0
  17. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/.github/workflows/run-python-tests.yaml +0 -0
  18. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/.gitignore +0 -0
  19. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/LICENSE +0 -0
  20. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/README.md +0 -0
  21. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/pyproject.toml +0 -0
  22. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/__init__.py +0 -0
  23. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_admin1.py +0 -0
  24. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_admin2.py +0 -0
  25. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_age_range.py +0 -0
  26. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_dataset.py +0 -0
  27. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_gender.py +0 -0
  28. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_humanitarian_needs.py +0 -0
  29. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_ipc_phase.py +0 -0
  30. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_ipc_type.py +0 -0
  31. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_location.py +0 -0
  32. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_national_risk.py +0 -0
  33. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_operational_presence.py +0 -0
  34. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_org.py +0 -0
  35. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_org_type.py +0 -0
  36. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_population.py +0 -0
  37. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_population_group.py +0 -0
  38. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_population_status.py +0 -0
  39. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_resource.py +0 -0
  40. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/db_sector.py +0 -0
  41. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/utils/__init__.py +0 -0
  42. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/utils/base.py +0 -0
  43. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/src/hapi_schema/utils/view_params.py +0 -0
  44. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/__init__.py +0 -0
  45. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_admin1.py +0 -0
  46. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_admin2.py +0 -0
  47. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_age_range.py +0 -0
  48. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_dataset.py +0 -0
  49. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_food_security.py +0 -0
  50. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_gender.py +0 -0
  51. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_humanitarian_needs.py +0 -0
  52. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_ipc_phase.py +0 -0
  53. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_ipc_type.py +0 -0
  54. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_location.py +0 -0
  55. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_national_risk.py +0 -0
  56. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_operational_presence.py +0 -0
  57. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_org.py +0 -0
  58. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_org_type.py +0 -0
  59. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_population.py +0 -0
  60. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_population_group.py +0 -0
  61. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_population_status.py +0 -0
  62. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_resource.py +0 -0
  63. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/sample_data/data_sector.py +0 -0
  64. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_admin1.py +0 -0
  65. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_admin2.py +0 -0
  66. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_age_range.py +0 -0
  67. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_dataset.py +0 -0
  68. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_gender.py +0 -0
  69. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_humanitarian_needs.py +0 -0
  70. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_ipc_phase.py +0 -0
  71. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_ipc_type.py +0 -0
  72. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_location.py +0 -0
  73. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_national_risk.py +0 -0
  74. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_operational_presence.py +0 -0
  75. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_org.py +0 -0
  76. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_org_type.py +0 -0
  77. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_population.py +0 -0
  78. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_population_group.py +0 -0
  79. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_population_status.py +0 -0
  80. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_resource.py +0 -0
  81. {hapi_schema-0.7.0 → hapi_schema-0.7.1}/tests/test_sector.py +0 -0
@@ -9,7 +9,10 @@ select = [
9
9
  "I" # isort
10
10
  ]
11
11
  ignore = [
12
- "E501" # Line too long
12
+ "E501", # Line too long
13
+ "D100", # missing-module-docstring
14
+ "D101", # missing-class-docstring
15
+ "D103" # missing-function-docstring
13
16
  ]
14
17
 
15
18
  [lint.isort]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hapi-schema
3
- Version: 0.7.0
3
+ Version: 0.7.1
4
4
  Summary: HAPI database schema specified in SQLAlchemy
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hapi-schemas
6
6
  Author-email: Simon Johnson <simon.johnson@un.org>
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.7.1]
9
+
10
+ ### Changed
11
+
12
+ - Removed constraint from food security
13
+
8
14
  ## [0.7.0]
9
15
 
10
16
  ### Added
@@ -13,6 +13,10 @@ development by running:
13
13
 
14
14
  pip install -r requirements.txt
15
15
 
16
+ and then make an editable installation of the package:
17
+
18
+ pip install -e .
19
+
16
20
  ## Pre-Commit
17
21
 
18
22
  Also be sure to install `pre-commit`, which is run every time
@@ -6,13 +6,15 @@
6
6
  #
7
7
  cfgv==3.4.0
8
8
  # via pre-commit
9
- coverage[toml]==7.4.3
9
+ colorama==0.4.6
10
+ # via pytest
11
+ coverage[toml]==7.4.4
10
12
  # via
11
13
  # coverage
12
14
  # pytest-cov
13
15
  distlib==0.3.8
14
16
  # via virtualenv
15
- filelock==3.13.1
17
+ filelock==3.13.4
16
18
  # via virtualenv
17
19
  greenlet==3.0.3
18
20
  # via sqlalchemy
@@ -24,29 +26,29 @@ iniconfig==2.0.0
24
26
  # via pytest
25
27
  nodeenv==1.8.0
26
28
  # via pre-commit
27
- packaging==23.2
29
+ packaging==24.0
28
30
  # via pytest
29
31
  platformdirs==4.2.0
30
32
  # via virtualenv
31
33
  pluggy==1.4.0
32
34
  # via pytest
33
- pre-commit==3.6.2
35
+ pre-commit==3.7.0
34
36
  # via hapi-schema (pyproject.toml)
35
- pytest==8.0.2
37
+ pytest==8.1.1
36
38
  # via
37
39
  # hapi-schema (pyproject.toml)
38
40
  # pytest-cov
39
- pytest-cov==4.1.0
41
+ pytest-cov==5.0.0
40
42
  # via hapi-schema (pyproject.toml)
41
43
  pyyaml==6.0.1
42
44
  # via pre-commit
43
- sqlalchemy==2.0.27
45
+ sqlalchemy==2.0.29
44
46
  # via
45
47
  # hapi-schema (pyproject.toml)
46
48
  # hdx-python-database
47
- typing-extensions==4.9.0
49
+ typing-extensions==4.11.0
48
50
  # via sqlalchemy
49
- virtualenv==20.25.1
51
+ virtualenv==20.25.3
50
52
  # via pre-commit
51
53
 
52
54
  # The following packages are considered to be unsafe in a requirements file:
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.7.0'
16
- __version_tuple__ = version_tuple = (0, 7, 0)
15
+ __version__ = version = '0.7.1'
16
+ __version_tuple__ = version_tuple = (0, 7, 1)
@@ -28,10 +28,6 @@ from hapi_schema.utils.view_params import ViewParams
28
28
  class DBFoodSecurity(Base):
29
29
  __tablename__ = "food_security"
30
30
  __table_args__ = (
31
- CheckConstraint(
32
- "population_fraction_in_phase >= 0 AND population_fraction_in_phase <=1",
33
- name="population_fraction_in_phase",
34
- ),
35
31
  CheckConstraint(
36
32
  "(reference_period_end >= reference_period_start) OR (reference_period_start IS NULL)",
37
33
  name="reference_period",
@@ -0,0 +1,33 @@
1
+ """Patches table"""
2
+
3
+ from datetime import datetime
4
+
5
+ from sqlalchemy import (
6
+ DateTime,
7
+ Integer,
8
+ String,
9
+ )
10
+ from sqlalchemy.orm import Mapped, mapped_column
11
+
12
+ from hapi_schema.utils.base import Base
13
+
14
+
15
+ class DBPatches(Base):
16
+ __tablename__ = "patches"
17
+
18
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
19
+ patch_sequence_number: Mapped[int] = mapped_column(Integer, nullable=False)
20
+ commit_hash: Mapped[str] = mapped_column(
21
+ String(48), unique=True, nullable=False
22
+ )
23
+ commit_date: Mapped[datetime] = mapped_column(DateTime, nullable=False)
24
+ patch_path: Mapped[str] = mapped_column(String(128), nullable=False)
25
+ permanent_download_url: Mapped[str] = mapped_column(
26
+ String(1024), nullable=False, unique=True
27
+ )
28
+ state: Mapped[str] = mapped_column(String(16), nullable=False)
29
+ # discovered -> it was found in the patch repo
30
+ # executed -> the patch was executed successfully
31
+ # failed -> HWA tried to execute the patch but it failed (either pre-conditions
32
+ # were not met OR the transaction failed and was rolled back)
33
+ # canceled -> it was marked as canceled in the patch repo
@@ -22,6 +22,7 @@ from hapi_schema.db_operational_presence import (
22
22
  )
23
23
  from hapi_schema.db_org import DBOrg
24
24
  from hapi_schema.db_org_type import DBOrgType
25
+ from hapi_schema.db_patches import DBPatches
25
26
  from hapi_schema.db_population import DBPopulation
26
27
  from hapi_schema.db_population_group import DBPopulationGroup
27
28
  from hapi_schema.db_population_status import DBPopulationStatus
@@ -42,6 +43,7 @@ from sample_data.data_national_risk import data_national_risk
42
43
  from sample_data.data_operational_presence import data_operational_presence
43
44
  from sample_data.data_org import data_org
44
45
  from sample_data.data_org_type import data_org_type
46
+ from sample_data.data_patches import data_patches
45
47
  from sample_data.data_population import data_population
46
48
  from sample_data.data_population_group import data_population_group
47
49
  from sample_data.data_population_status import data_population_status
@@ -85,6 +87,8 @@ def engine():
85
87
  session.execute(insert(DBFoodSecurity), data_food_security)
86
88
  session.execute(insert(DBHumanitarianNeeds), data_humanitarian_needs)
87
89
 
90
+ session.execute(insert(DBPatches), data_patches)
91
+
88
92
  session.commit()
89
93
 
90
94
  return engine
@@ -0,0 +1,31 @@
1
+ from datetime import datetime
2
+
3
+ data_patches = [
4
+ dict(
5
+ id=1,
6
+ patch_sequence_number=1,
7
+ commit_hash="66e7e589a1224a1832ba7360817dda7a7d9313cf",
8
+ commit_date=datetime(2023, 1, 1),
9
+ patch_path="2024/01",
10
+ permanent_download_url="https://github.com/OCHA-DAP/hapi-patch-repo/blob/66e7e589a1224a1832ba7360817dda7a7d9313cf/2024/01/hapi_patch_10_hno.json",
11
+ state="executed",
12
+ ),
13
+ dict(
14
+ id=2,
15
+ patch_sequence_number=2,
16
+ commit_hash="554f18a92cf6a23a14e0f29356a6dec150f651ff",
17
+ commit_date=datetime(2023, 1, 2),
18
+ patch_path="2024/01",
19
+ permanent_download_url="https://github.com/OCHA-DAP/hapi-patch-repo/blob/554f18a92cf6a23a14e0f29356a6dec150f651ff/2024/01/hapi_patch_10_hno.json",
20
+ state="failed",
21
+ ),
22
+ dict(
23
+ id=3,
24
+ patch_sequence_number=3,
25
+ commit_hash="35ea27da009e5add8d8d227e02fd2c4bbcc84b76",
26
+ commit_date=datetime(2023, 1, 3),
27
+ patch_path="2024/01",
28
+ permanent_download_url="https://github.com/OCHA-DAP/hapi-patch-repo/blob/35ea27da009e5add8d8d227e02fd2c4bbcc84b76/2024/01/hapi_patch_10_hno.json",
29
+ state="discovered",
30
+ ),
31
+ ]
@@ -34,7 +34,7 @@ def test_reference_period_constraint(run_constraints_test):
34
34
  DBFoodSecurity(
35
35
  resource_ref=3,
36
36
  admin2_ref=4,
37
- ipc_phase_code="all",
37
+ ipc_phase_code="1",
38
38
  ipc_type_code="current",
39
39
  population_in_phase=1_000,
40
40
  population_fraction_in_phase=1,
@@ -45,41 +45,3 @@ def test_reference_period_constraint(run_constraints_test):
45
45
  ],
46
46
  expected_constraint="reference_period",
47
47
  )
48
-
49
-
50
- def test_population_fraction(run_constraints_test):
51
- """Check that pop fraction msut be between 0 and 1"""
52
- # Greater than 1
53
- run_constraints_test(
54
- new_rows=[
55
- DBFoodSecurity(
56
- resource_ref=3,
57
- admin2_ref=4,
58
- ipc_phase_code="all",
59
- ipc_type_code="current",
60
- population_in_phase=1_000,
61
- population_fraction_in_phase=10,
62
- reference_period_start=None,
63
- reference_period_end=None,
64
- source_data="DATA,DATA,DATA",
65
- )
66
- ],
67
- expected_constraint="population_fraction_in_phase",
68
- )
69
- # Less than 0
70
- run_constraints_test(
71
- new_rows=[
72
- DBFoodSecurity(
73
- resource_ref=3,
74
- admin2_ref=4,
75
- ipc_phase_code="all",
76
- ipc_type_code="current",
77
- population_in_phase=1_000,
78
- population_fraction_in_phase=-10,
79
- reference_period_start=None,
80
- reference_period_end=None,
81
- source_data="DATA,DATA,DATA",
82
- )
83
- ],
84
- expected_constraint="population_fraction_in_phase",
85
- )
@@ -0,0 +1,28 @@
1
+ import string
2
+
3
+ from sqlalchemy import create_engine
4
+
5
+ from hapi_schema.utils.base import Base
6
+
7
+
8
+ def test_db_patches(capfd):
9
+ engine = create_engine("sqlite://", echo=True)
10
+ Base.metadata.create_all(engine)
11
+
12
+ sql_table_creation_code = """CREATE TABLE patches (
13
+ id INTEGER NOT NULL,
14
+ patch_sequence_number INTEGER NOT NULL,
15
+ commit_hash VARCHAR(48) NOT NULL,
16
+ commit_date DATETIME NOT NULL,
17
+ patch_path VARCHAR(128) NOT NULL,
18
+ permanent_download_url VARCHAR(1024) NOT NULL,
19
+ state VARCHAR(16) NOT NULL,
20
+ PRIMARY KEY (id),
21
+ UNIQUE (commit_hash),
22
+ UNIQUE (permanent_download_url)
23
+ )
24
+ """
25
+ captured_sql, _ = capfd.readouterr()
26
+ assert sql_table_creation_code.translate(
27
+ str.maketrans("", "", string.whitespace)
28
+ ) in captured_sql.translate(str.maketrans("", "", string.whitespace))
File without changes
File without changes
File without changes
File without changes