hapi-schema 0.8.7__tar.gz → 0.8.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 (97) hide show
  1. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/PKG-INFO +1 -1
  2. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/changelog.md +9 -0
  3. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/_version.py +2 -2
  4. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_conflict_event.py +2 -3
  5. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_funding.py +3 -3
  6. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_national_risk.py +2 -1
  7. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_poverty_rate.py +1 -1
  8. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/constraints.py +13 -9
  9. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/enums.py +30 -17
  10. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_humanitarian_needs.py +7 -7
  11. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_population.py +4 -4
  12. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_sector.py +2 -2
  13. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_admin1.py +2 -2
  14. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_admin2.py +2 -2
  15. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_conflict_event.py +3 -3
  16. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_food_price.py +2 -2
  17. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_food_security.py +2 -2
  18. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_funding.py +4 -4
  19. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_humanitarian_needs.py +7 -7
  20. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_location.py +2 -2
  21. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_national_risk.py +13 -8
  22. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_operational_presence.py +1 -1
  23. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_population.py +15 -8
  24. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_poverty_rate.py +8 -8
  25. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_refugees.py +6 -6
  26. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_wfp_market.py +1 -1
  27. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/.config/coveragerc +0 -0
  28. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/.config/pre-commit-config.yaml +0 -0
  29. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/.config/pytest.ini +0 -0
  30. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/.config/ruff.toml +0 -0
  31. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/.github/workflows/publish.yaml +0 -0
  32. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/.github/workflows/run-python-tests.yaml +0 -0
  33. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/.gitignore +0 -0
  34. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/LICENSE +0 -0
  35. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/README.md +0 -0
  36. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/contributing.md +0 -0
  37. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/docker/docker-compose.yml +0 -0
  38. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/initialize_test_db.sh +0 -0
  39. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/pyproject.toml +0 -0
  40. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/requirements.txt +0 -0
  41. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/__init__.py +0 -0
  42. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_admin1.py +0 -0
  43. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_admin2.py +0 -0
  44. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_currency.py +0 -0
  45. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_dataset.py +0 -0
  46. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_food_price.py +0 -0
  47. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_food_security.py +0 -0
  48. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_humanitarian_needs.py +0 -0
  49. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_location.py +0 -0
  50. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_operational_presence.py +0 -0
  51. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_org.py +0 -0
  52. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_org_type.py +0 -0
  53. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_patch.py +0 -0
  54. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_population.py +0 -0
  55. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_refugees.py +0 -0
  56. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_resource.py +0 -0
  57. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_sector.py +0 -0
  58. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_views_as_tables.py +0 -0
  59. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_wfp_commodity.py +0 -0
  60. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/db_wfp_market.py +0 -0
  61. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/__init__.py +0 -0
  62. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/base.py +0 -0
  63. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
  64. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
  65. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
  66. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/utils/view_params.py +0 -0
  67. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/src/hapi_schema/views.py +0 -0
  68. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/conftest.py +0 -0
  69. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/__init__.py +0 -0
  70. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_admin1.py +0 -0
  71. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_admin2.py +0 -0
  72. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_conflict_event.py +0 -0
  73. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_currency.py +0 -0
  74. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_dataset.py +0 -0
  75. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_food_price.py +0 -0
  76. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_food_security.py +0 -0
  77. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_funding.py +0 -0
  78. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_location.py +0 -0
  79. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_national_risk.py +0 -0
  80. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_operational_presence.py +0 -0
  81. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_org.py +0 -0
  82. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_org_type.py +0 -0
  83. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_patch.py +0 -0
  84. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_poverty_rate.py +0 -0
  85. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_refugees.py +0 -0
  86. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_resource.py +0 -0
  87. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_wfp_commodity.py +0 -0
  88. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/sample_data/data_wfp_market.py +0 -0
  89. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_currency.py +0 -0
  90. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_dataset.py +0 -0
  91. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_org.py +0 -0
  92. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_org_type.py +0 -0
  93. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_patch.py +0 -0
  94. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_resource.py +0 -0
  95. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_sector.py +0 -0
  96. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_views_as_tables.py +0 -0
  97. {hapi_schema-0.8.7 → hapi_schema-0.8.8}/tests/test_wfp_commodity.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hapi-schema
3
- Version: 0.8.7
3
+ Version: 0.8.8
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,15 @@ 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.8.8
9
+
10
+ ### Changes
11
+
12
+ - Rewrite enums to use values rather than variable names
13
+ - Switch from "*" to "all" for rollup in enums
14
+ - Add "intersectoral" to sample sector data (distinct from "all")
15
+ - Ensure that constraint names end consistently with "\_constraint"
16
+
8
17
  ## 0.8.7
9
18
 
10
19
  ## Changes
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.8.7'
16
- __version_tuple__ = version_tuple = (0, 8, 7)
15
+ __version__ = version = '0.8.8'
16
+ __version_tuple__ = version_tuple = (0, 8, 8)
@@ -4,7 +4,6 @@ from datetime import datetime
4
4
 
5
5
  from sqlalchemy import (
6
6
  DateTime,
7
- Enum,
8
7
  ForeignKey,
9
8
  Integer,
10
9
  select,
@@ -18,7 +17,7 @@ from hapi_schema.utils.constraints import (
18
17
  population_constraint,
19
18
  reference_period_constraint,
20
19
  )
21
- from hapi_schema.utils.enums import EventType
20
+ from hapi_schema.utils.enums import EventType, build_enum_using_values
22
21
  from hapi_schema.utils.view_params import ViewParams
23
22
 
24
23
 
@@ -43,7 +42,7 @@ class DBConflictEvent(Base):
43
42
  primary_key=True,
44
43
  )
45
44
  event_type: Mapped[EventType] = mapped_column(
46
- Enum(EventType), nullable=False, primary_key=True
45
+ build_enum_using_values(EventType), nullable=False, primary_key=True
47
46
  )
48
47
  events: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
49
48
  fatalities: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
@@ -24,15 +24,15 @@ class DBFunding(Base):
24
24
  __table_args__ = (
25
25
  CheckConstraint(
26
26
  "requirements_usd >= 0.0",
27
- name="requirements_usd",
27
+ name="requirements_usd_constraint",
28
28
  ),
29
29
  CheckConstraint(
30
30
  "funding_usd >= 0.0",
31
- name="funding_usd",
31
+ name="funding_usd_constraint",
32
32
  ),
33
33
  CheckConstraint(
34
34
  "funding_pct >= 0.0",
35
- name="funding_pct",
35
+ name="funding_pct_constraint",
36
36
  ),
37
37
  reference_period_constraint(),
38
38
  )
@@ -32,7 +32,8 @@ class DBNationalRisk(Base):
32
32
  general_risk_constraint("vulnerability"),
33
33
  general_risk_constraint("coping_capacity"),
34
34
  CheckConstraint(
35
- "(global_rank >= 1) AND (global_rank <= 250)", name="global_rank"
35
+ "(global_rank >= 1) AND (global_rank <= 250)",
36
+ name="global_rank_constraint",
36
37
  ),
37
38
  CheckConstraint(
38
39
  "meta_avg_recentness_years >= 0.0",
@@ -34,7 +34,7 @@ class DBPovertyRate(Base):
34
34
  reference_period_constraint(),
35
35
  CheckConstraint(
36
36
  sqltext="ABS(headcount_ratio / 100 * intensity_of_deprivation / 100 - mpi) < 0.00001",
37
- name="mpi_product",
37
+ name="mpi_product_constraint",
38
38
  ),
39
39
  )
40
40
 
@@ -9,8 +9,8 @@ def min_age_constraint() -> CheckConstraint:
9
9
  Otherwise, it can be NULL for unknown, or should be an
10
10
  integer of 0 or greater."""
11
11
  sqltext = (
12
- "(age_range = '*' AND min_age IS NULL) OR "
13
- "(age_range != '*' AND (min_age >= 0 OR min_age is NULL))"
12
+ "(age_range = 'all' AND min_age IS NULL) OR "
13
+ "(age_range != 'all' AND min_age >= 0)"
14
14
  )
15
15
  return CheckConstraint(sqltext=sqltext, name="min_age_constraint")
16
16
 
@@ -32,7 +32,9 @@ def population_constraint(
32
32
  ) -> CheckConstraint:
33
33
  """Population must not be a negative number."""
34
34
  sqltext = f"{population_var_name} >= 0"
35
- return CheckConstraint(sqltext=sqltext, name=f"{population_var_name}")
35
+ return CheckConstraint(
36
+ sqltext=sqltext, name=f"{population_var_name}_constraint"
37
+ )
36
38
 
37
39
 
38
40
  def non_negative_constraint(
@@ -40,23 +42,25 @@ def non_negative_constraint(
40
42
  ) -> CheckConstraint:
41
43
  """Require a column to be non-negative."""
42
44
  sqltext = f"{var_name} >= 0"
43
- return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
45
+ return CheckConstraint(sqltext=sqltext, name=f"{var_name}_constraint")
44
46
 
45
47
 
46
48
  def percentage_constraint(var_name: str) -> CheckConstraint:
47
49
  sqltext = f"{var_name} >= 0. AND {var_name} <= 100."
48
- return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
50
+ return CheckConstraint(sqltext=sqltext, name=f"{var_name}_constraint")
49
51
 
50
52
 
51
53
  def reference_period_constraint() -> CheckConstraint:
52
54
  """reference_period_end should be greater than reference_period_start"""
53
55
  sqltext = "reference_period_end >= reference_period_start "
54
- return CheckConstraint(sqltext=sqltext, name="reference_period")
56
+ return CheckConstraint(sqltext=sqltext, name="reference_period_constraint")
55
57
 
56
58
 
57
59
  def general_risk_constraint(risk_name: str) -> CheckConstraint:
58
60
  sqltext = f"({risk_name}_risk >= 0) AND ({risk_name}_risk <= 10)"
59
- return CheckConstraint(sqltext=sqltext, name=f"{risk_name}_risk")
61
+ return CheckConstraint(
62
+ sqltext=sqltext, name=f"{risk_name}_risk_constraint"
63
+ )
60
64
 
61
65
 
62
66
  def code_and_reference_period_unique_constraint(
@@ -65,11 +69,11 @@ def code_and_reference_period_unique_constraint(
65
69
  return UniqueConstraint(
66
70
  "code",
67
71
  "reference_period_start",
68
- name=f"{admin_level}_code_and_reference_period_unique",
72
+ name=f"{admin_level}_code_and_reference_period_unique_constraint",
69
73
  )
70
74
 
71
75
 
72
76
  def latlon_constraint() -> CheckConstraint:
73
77
  """Latitude and longitude must be valid"""
74
78
  sqltext = "lat <= 90.0 AND lat >= -90.0 AND lon <= 180.0 AND lon >= -180.0"
75
- return CheckConstraint(sqltext=sqltext, name="latlon")
79
+ return CheckConstraint(sqltext=sqltext, name="latlon_constraint")
@@ -1,28 +1,41 @@
1
- import enum
1
+ from enum import Enum as PythonEnum
2
+ from typing import List
2
3
 
4
+ from sqlalchemy import Enum as SQLAlchemyEnum
3
5
 
4
- class Gender(str, enum.Enum):
6
+ """The two functions below create enums using the values rather than the keys"""
7
+
8
+
9
+ def _get_list_of_values(enum_class: PythonEnum) -> List[str]:
10
+ return [e.value for e in enum_class]
11
+
12
+
13
+ def build_enum_using_values(enum_class: PythonEnum) -> SQLAlchemyEnum:
14
+ return SQLAlchemyEnum(enum_class, values_callable=_get_list_of_values)
15
+
16
+
17
+ class Gender(str, PythonEnum):
5
18
  FEMALE = "f"
6
19
  MALE = "m"
7
20
  NONBINARY = "x"
8
21
  UNSPECIFIED = "u"
9
22
  OTHER = "o"
10
- ALL = "*"
23
+ ALL = "all"
11
24
 
12
25
 
13
- class DisabledMarker(str, enum.Enum):
26
+ class DisabledMarker(str, PythonEnum):
14
27
  YES = "y"
15
28
  NO = "n"
16
- ALL = "*"
29
+ ALL = "all"
17
30
 
18
31
 
19
- class EventType(str, enum.Enum):
32
+ class EventType(str, PythonEnum):
20
33
  CIVILIAN_TARGETING = "civilian_targeting"
21
34
  DEMONSTRATION = "demonstration"
22
35
  POLITICAL_VIOLENCE = "political_violence"
23
36
 
24
37
 
25
- class PopulationGroup(str, enum.Enum):
38
+ class PopulationGroup(str, PythonEnum):
26
39
  REFUGEES = "REF"
27
40
  ROC = "ROC"
28
41
  ASYLUM_SEEKERS = "ASY"
@@ -38,47 +51,47 @@ class PopulationGroup(str, enum.Enum):
38
51
  POC = "POC"
39
52
  RDP = "RDP"
40
53
  RRI = "RRI"
41
- ALL = "*"
54
+ ALL = "all"
42
55
 
43
56
 
44
- class PopulationStatus(str, enum.Enum):
57
+ class PopulationStatus(str, PythonEnum):
45
58
  POPULATION = "POP"
46
59
  AFFECTED = "AFF"
47
60
  INNEED = "INN"
48
61
  TARGETED = "TGT"
49
62
  REACHED = "REA"
50
- ALL = "*"
63
+ ALL = "all"
51
64
 
52
65
 
53
- class PriceFlag(str, enum.Enum):
66
+ class PriceFlag(str, PythonEnum):
54
67
  ACTUAL = "actual"
55
68
  AGGREGATE = "aggregate"
56
69
  ACTUAL_AGGREGATE = "actual,aggregate"
57
70
 
58
71
 
59
- class PriceType(str, enum.Enum):
72
+ class PriceType(str, PythonEnum):
60
73
  FARM_GATE = "Farm Gate"
61
74
  RETAIL = "Retail"
62
75
  WHOLESALE = "Wholesale"
63
76
 
64
77
 
65
- class IPCPhase(str, enum.Enum):
78
+ class IPCPhase(str, PythonEnum):
66
79
  PHASE_1 = "1"
67
80
  PHASE_2 = "2"
68
81
  PHASE_3 = "3"
69
82
  PHASE_4 = "4"
70
83
  PHASE_5 = "5"
71
84
  PHASE_3_PLUS = "3+"
72
- ALL = "*"
85
+ ALL = "all"
73
86
 
74
87
 
75
- class IPCType(str, enum.Enum):
88
+ class IPCType(str, PythonEnum):
76
89
  CURRENT = "current"
77
90
  FIRST_PROJECTION = "first projection"
78
91
  SECOND_PROJECTION = "second projection"
79
92
 
80
93
 
81
- class RiskClass(str, enum.Enum):
94
+ class RiskClass(str, PythonEnum):
82
95
  VERY_LOW = "1"
83
96
  LOW = "2"
84
97
  MEDIUM = "3"
@@ -86,7 +99,7 @@ class RiskClass(str, enum.Enum):
86
99
  VERY_HIGH = "5"
87
100
 
88
101
 
89
- class CommodityCategory(str, enum.Enum):
102
+ class CommodityCategory(str, PythonEnum):
90
103
  CEREALS_TUBERS = "cereals and tubers"
91
104
  MEAT_FISH_EGGS = "meat, fish and eggs"
92
105
  MILK_DAIRY = "milk and dairy"
@@ -5,11 +5,11 @@ data_humanitarian_needs = [
5
5
  dict(
6
6
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
7
7
  admin2_ref=1,
8
- gender="*",
9
- age_range="*",
10
- disabled_marker="*",
11
- sector_code="*",
12
- population_group="*",
8
+ gender="all",
9
+ age_range="all",
10
+ disabled_marker="all",
11
+ sector_code="intersectoral",
12
+ population_group="all",
13
13
  population_status="AFF",
14
14
  population=1_000_000,
15
15
  reference_period_start=datetime(2023, 1, 1),
@@ -20,7 +20,7 @@ data_humanitarian_needs = [
20
20
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
21
21
  admin2_ref=1,
22
22
  gender="f",
23
- age_range="*",
23
+ age_range="all",
24
24
  disabled_marker="n",
25
25
  sector_code="SHL",
26
26
  population_group="REF",
@@ -49,7 +49,7 @@ data_humanitarian_needs = [
49
49
  dict(
50
50
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
51
51
  admin2_ref=4,
52
- gender="*",
52
+ gender="all",
53
53
  age_range="80+",
54
54
  min_age=80,
55
55
  disabled_marker="y",
@@ -5,8 +5,8 @@ data_population = [
5
5
  dict(
6
6
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
7
7
  admin2_ref=1,
8
- gender="*",
9
- age_range="*",
8
+ gender="all",
9
+ age_range="all",
10
10
  population=1_000_000,
11
11
  reference_period_start=datetime(2023, 1, 1),
12
12
  reference_period_end=datetime(2023, 6, 30),
@@ -16,7 +16,7 @@ data_population = [
16
16
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
17
17
  admin2_ref=1,
18
18
  gender="f",
19
- age_range="*",
19
+ age_range="all",
20
20
  population=500_000,
21
21
  reference_period_start=datetime(2023, 1, 1),
22
22
  reference_period_end=datetime(2023, 6, 30),
@@ -37,7 +37,7 @@ data_population = [
37
37
  dict(
38
38
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
39
39
  admin2_ref=4,
40
- gender="*",
40
+ gender="all",
41
41
  age_range="80+",
42
42
  min_age=80,
43
43
  population=500,
@@ -16,7 +16,7 @@ data_sector = [
16
16
  name="Health",
17
17
  ),
18
18
  dict(
19
- code="*",
20
- name="All",
19
+ code="intersectoral",
20
+ name="Intersectoral",
21
21
  ),
22
22
  ]
@@ -42,7 +42,7 @@ def test_reference_period_constraint(run_constraints_test):
42
42
  reference_period_end=datetime(2023, 1, 1),
43
43
  )
44
44
  ],
45
- expected_constraint="reference_period",
45
+ expected_constraint="reference_period_constraint",
46
46
  )
47
47
 
48
48
 
@@ -65,5 +65,5 @@ def test_code_date_unique(run_constraints_test):
65
65
  reference_period_start=datetime(2023, 1, 1),
66
66
  ),
67
67
  ],
68
- expected_constraint="admin1_code_and_reference_period_unique",
68
+ expected_constraint="admin1_code_and_reference_period_unique_constraint",
69
69
  )
@@ -43,7 +43,7 @@ def test_reference_period_constraint(run_constraints_test):
43
43
  reference_period_end=datetime(2023, 1, 1),
44
44
  )
45
45
  ],
46
- expected_constraint="reference_period",
46
+ expected_constraint="reference_period_constraint",
47
47
  )
48
48
 
49
49
 
@@ -66,5 +66,5 @@ def test_code_date_unique(run_constraints_test):
66
66
  reference_period_start=datetime(2023, 1, 1),
67
67
  ),
68
68
  ],
69
- expected_constraint="admin2_code_and_reference_period_unique",
69
+ expected_constraint="admin2_code_and_reference_period_unique_constraint",
70
70
  )
@@ -46,7 +46,7 @@ def test_events_constraint(run_constraints_test):
46
46
  new_rows=[
47
47
  DBConflictEvent(**data),
48
48
  ],
49
- expected_constraint="events",
49
+ expected_constraint="events_constraint",
50
50
  )
51
51
 
52
52
 
@@ -58,7 +58,7 @@ def test_fatalities_constraint(run_constraints_test):
58
58
  new_rows=[
59
59
  DBConflictEvent(**data),
60
60
  ],
61
- expected_constraint="fatalities",
61
+ expected_constraint="fatalities_constraint",
62
62
  )
63
63
 
64
64
 
@@ -70,5 +70,5 @@ def test_reference_period_constraint(run_constraints_test):
70
70
  new_rows=[
71
71
  DBConflictEvent(**data),
72
72
  ],
73
- expected_constraint="reference_period",
73
+ expected_constraint="reference_period_constraint",
74
74
  )
@@ -43,7 +43,7 @@ def test_price_not_negative_constraint(run_constraints_test):
43
43
  new_rows=[
44
44
  DBFoodPrice(**data),
45
45
  ],
46
- expected_constraint="price",
46
+ expected_constraint="price_constraint",
47
47
  )
48
48
 
49
49
 
@@ -55,7 +55,7 @@ def test_reference_period_constraint(run_constraints_test):
55
55
  new_rows=[
56
56
  DBFoodPrice(**data),
57
57
  ],
58
- expected_constraint="reference_period",
58
+ expected_constraint="reference_period_constraint",
59
59
  )
60
60
 
61
61
 
@@ -40,7 +40,7 @@ def test_reference_period_constraint(run_constraints_test):
40
40
  reference_period_end=datetime(2023, 1, 1),
41
41
  )
42
42
  ],
43
- expected_constraint="reference_period",
43
+ expected_constraint="reference_period_constraint",
44
44
  )
45
45
 
46
46
 
@@ -59,5 +59,5 @@ def test_population_in_phase_positive(run_constraints_test):
59
59
  reference_period_end=datetime(2023, 1, 2),
60
60
  )
61
61
  ],
62
- expected_constraint="population_in_phase",
62
+ expected_constraint="population_in_phase_constraint",
63
63
  )
@@ -46,7 +46,7 @@ def test_reference_period_constraint(run_constraints_test):
46
46
  reference_period_end=datetime(2024, 12, 31),
47
47
  ),
48
48
  ],
49
- expected_constraint="reference_period",
49
+ expected_constraint="reference_period_constraint",
50
50
  )
51
51
 
52
52
 
@@ -67,7 +67,7 @@ def test_requirements_usd_constraint(run_constraints_test):
67
67
  reference_period_end=datetime(2024, 12, 31),
68
68
  ),
69
69
  ],
70
- expected_constraint="requirements_usd",
70
+ expected_constraint="requirements_usd_constraint",
71
71
  )
72
72
 
73
73
 
@@ -88,7 +88,7 @@ def test_funding_usd_constraint(run_constraints_test):
88
88
  reference_period_end=datetime(2024, 12, 31),
89
89
  ),
90
90
  ],
91
- expected_constraint="funding_usd",
91
+ expected_constraint="funding_usd_constraint",
92
92
  )
93
93
 
94
94
 
@@ -109,5 +109,5 @@ def test_funding_pct_constraint(run_constraints_test):
109
109
  reference_period_end=datetime(2024, 12, 31),
110
110
  ),
111
111
  ],
112
- expected_constraint="funding_pct",
112
+ expected_constraint="funding_pct_constraint",
113
113
  )
@@ -77,26 +77,26 @@ def test_population_positive(run_constraints_test, base_parameters):
77
77
  new_rows=[
78
78
  DBHumanitarianNeeds(**modified_params),
79
79
  ],
80
- expected_constraint="population",
80
+ expected_constraint="population_constraint",
81
81
  )
82
82
 
83
83
 
84
84
  def test_minage(run_constraints_test, base_parameters):
85
85
  """Check that the min_age value is positive, and NULL if
86
- age_range is *"""
86
+ age_range is all"""
87
87
  modified_params = {**base_parameters, **dict(age_range="5-10", min_age=-1)}
88
88
  run_constraints_test(
89
89
  new_rows=[
90
90
  DBHumanitarianNeeds(**modified_params),
91
91
  ],
92
- expected_constraint="min_age",
92
+ expected_constraint="min_age_constraint",
93
93
  )
94
- modified_params = {**base_parameters, **dict(age_range="*", min_age=10)}
94
+ modified_params = {**base_parameters, **dict(age_range="all", min_age=10)}
95
95
  run_constraints_test(
96
96
  new_rows=[
97
97
  DBHumanitarianNeeds(**modified_params),
98
98
  ],
99
- expected_constraint="min_age",
99
+ expected_constraint="min_age_constraint",
100
100
  )
101
101
 
102
102
 
@@ -110,7 +110,7 @@ def test_maxage(run_constraints_test, base_parameters):
110
110
  new_rows=[
111
111
  DBHumanitarianNeeds(**modified_params),
112
112
  ],
113
- expected_constraint="min_age",
113
+ expected_constraint="max_age_constraint",
114
114
  )
115
115
  modified_params = {
116
116
  **base_parameters,
@@ -120,5 +120,5 @@ def test_maxage(run_constraints_test, base_parameters):
120
120
  new_rows=[
121
121
  DBHumanitarianNeeds(**modified_params),
122
122
  ],
123
- expected_constraint="min_age",
123
+ expected_constraint="max_age_constraint",
124
124
  )
@@ -41,7 +41,7 @@ def test_reference_period_constraint(run_constraints_test):
41
41
  reference_period_end=datetime(2023, 1, 1),
42
42
  )
43
43
  ],
44
- expected_constraint="reference_period",
44
+ expected_constraint="reference_period_constraint",
45
45
  )
46
46
 
47
47
 
@@ -60,5 +60,5 @@ def test_code_date_unique(run_constraints_test):
60
60
  reference_period_start=datetime(2023, 1, 1),
61
61
  ),
62
62
  ],
63
- expected_constraint="location_code_and_reference_period_unique",
63
+ expected_constraint="location_code_and_reference_period_unique_constraint",
64
64
  )
@@ -37,22 +37,27 @@ def base_parameters():
37
37
  coping_capacity_risk=7.1,
38
38
  meta_missing_indicators_pct=8,
39
39
  meta_avg_recentness_years=0.26,
40
+ reference_period_start=datetime(2023, 1, 1),
41
+ reference_period_end=datetime(2023, 1, 2),
40
42
  )
41
43
 
42
44
 
43
45
  def test_reference_period_constraint(run_constraints_test, base_parameters):
44
46
  """Check that reference_period_end cannot be less than start"""
47
+ modified_params = {
48
+ **base_parameters,
49
+ **dict(
50
+ reference_period_start=datetime(2023, 1, 2),
51
+ reference_period_end=datetime(2023, 1, 1),
52
+ ),
53
+ }
45
54
  run_constraints_test(
46
55
  new_rows=[
47
56
  DBNationalRisk(
48
- **base_parameters,
49
- **dict(
50
- reference_period_start=datetime(2023, 1, 2),
51
- reference_period_end=datetime(2023, 1, 1),
52
- ),
57
+ **modified_params,
53
58
  )
54
59
  ],
55
- expected_constraint="reference_period",
60
+ expected_constraint="reference_period_constraint",
56
61
  )
57
62
 
58
63
 
@@ -61,12 +66,12 @@ def test_overall_risk_constraint(run_constraints_test, base_parameters):
61
66
  modified_params = {**base_parameters, "overall_risk": -1}
62
67
  run_constraints_test(
63
68
  new_rows=[DBNationalRisk(**modified_params)],
64
- expected_constraint="overall_risk",
69
+ expected_constraint="overall_risk_constraint",
65
70
  )
66
71
  modified_params = {**base_parameters, "overall_risk": 11}
67
72
  run_constraints_test(
68
73
  new_rows=[DBNationalRisk(**modified_params)],
69
- expected_constraint="overall_risk",
74
+ expected_constraint="overall_risk_constraint",
70
75
  )
71
76
 
72
77
 
@@ -45,5 +45,5 @@ def test_reference_period_constraint(run_constraints_test):
45
45
  reference_period_end=datetime(2023, 1, 1),
46
46
  )
47
47
  ],
48
- expected_constraint="reference_period",
48
+ expected_constraint="reference_period_constraint",
49
49
  )
@@ -29,7 +29,10 @@ def base_parameters():
29
29
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
30
30
  admin2_ref=1,
31
31
  gender=Gender.ALL,
32
+ age_range="all",
32
33
  population=1_000_000,
34
+ reference_period_start=datetime(2020, 1, 1),
35
+ reference_period_end=datetime(2020, 1, 2),
33
36
  )
34
37
 
35
38
 
@@ -44,7 +47,7 @@ def test_reference_period_constraint(run_constraints_test, base_parameters):
44
47
  }
45
48
  run_constraints_test(
46
49
  new_rows=[DBPopulation(**modified_params)],
47
- expected_constraint="reference_period",
50
+ expected_constraint="reference_period_constraint",
48
51
  )
49
52
 
50
53
 
@@ -55,26 +58,30 @@ def test_population_positive(run_constraints_test, base_parameters):
55
58
  new_rows=[
56
59
  DBPopulation(**modified_params),
57
60
  ],
58
- expected_constraint="population",
61
+ expected_constraint="population_constraint",
59
62
  )
60
63
 
61
64
 
62
65
  def test_minage(run_constraints_test, base_parameters):
63
66
  """Check that the min_age value is positive, and NULL if
64
- age_range is *"""
67
+ age_range is all"""
65
68
  modified_params = {**base_parameters, **dict(age_range="5-10", min_age=-1)}
66
69
  run_constraints_test(
67
70
  new_rows=[
68
71
  DBPopulation(**modified_params),
69
72
  ],
70
- expected_constraint="min_age",
73
+ expected_constraint="min_age_constraint",
71
74
  )
72
- modified_params = {**base_parameters, **dict(age_range="*", min_age=10)}
75
+ modified_params = {
76
+ **base_parameters,
77
+ **dict(age_range="all", min_age="10"),
78
+ }
79
+ print(modified_params)
73
80
  run_constraints_test(
74
81
  new_rows=[
75
82
  DBPopulation(**modified_params),
76
83
  ],
77
- expected_constraint="min_age",
84
+ expected_constraint="min_age_constraint",
78
85
  )
79
86
 
80
87
 
@@ -88,7 +95,7 @@ def test_maxage(run_constraints_test, base_parameters):
88
95
  new_rows=[
89
96
  DBPopulation(**modified_params),
90
97
  ],
91
- expected_constraint="min_age",
98
+ expected_constraint="max_age_constraint",
92
99
  )
93
100
  modified_params = {
94
101
  **base_parameters,
@@ -98,5 +105,5 @@ def test_maxage(run_constraints_test, base_parameters):
98
105
  new_rows=[
99
106
  DBPopulation(**modified_params),
100
107
  ],
101
- expected_constraint="min_age",
108
+ expected_constraint="max_age_constraint",
102
109
  )
@@ -32,7 +32,7 @@ def test_headcount_ratio_constraint(run_constraints_test):
32
32
  new_rows=[
33
33
  DBPovertyRate(**data),
34
34
  ],
35
- expected_constraint="headcount_ratio",
35
+ expected_constraint="headcount_ratio_constraint",
36
36
  )
37
37
 
38
38
 
@@ -44,7 +44,7 @@ def test_intensity_of_deprivation_constraint(run_constraints_test):
44
44
  new_rows=[
45
45
  DBPovertyRate(**data),
46
46
  ],
47
- expected_constraint="intensity_of_deprivation",
47
+ expected_constraint="intensity_of_deprivation_constraint",
48
48
  )
49
49
 
50
50
 
@@ -56,7 +56,7 @@ def test_vulnerable_to_poverty_constraint(run_constraints_test):
56
56
  new_rows=[
57
57
  DBPovertyRate(**data),
58
58
  ],
59
- expected_constraint="vulnerable_to_poverty",
59
+ expected_constraint="vulnerable_to_poverty_constraint",
60
60
  )
61
61
 
62
62
 
@@ -68,19 +68,19 @@ def test_in_severe_poverty_constraint(run_constraints_test):
68
68
  new_rows=[
69
69
  DBPovertyRate(**data),
70
70
  ],
71
- expected_constraint="in_severe_poverty",
71
+ expected_constraint="in_severe_poverty_constraint",
72
72
  )
73
73
 
74
74
 
75
75
  def test_mpi_product_constraint(run_constraints_test):
76
- """Check that MPI is between 0.0 and 1.0"""
76
+ """Check that MPI is the product of headcount and intensity"""
77
77
  data = _sample_data()
78
- data["mpi"] = 1.1
78
+ data["mpi"] = 0.5
79
79
  run_constraints_test(
80
80
  new_rows=[
81
81
  DBPovertyRate(**data),
82
82
  ],
83
- expected_constraint="mpi_product",
83
+ expected_constraint="mpi_product_constraint",
84
84
  )
85
85
 
86
86
 
@@ -92,7 +92,7 @@ def test_reference_period_constraint(run_constraints_test):
92
92
  new_rows=[
93
93
  DBPovertyRate(**data),
94
94
  ],
95
- expected_constraint="reference_period",
95
+ expected_constraint="reference_period_constraint",
96
96
  )
97
97
 
98
98
 
@@ -40,12 +40,12 @@ def test_min_age(run_constraints_test):
40
40
  reference_period_end=datetime(2023, 12, 31),
41
41
  )
42
42
  ],
43
- expected_constraint="min_age",
43
+ expected_constraint="min_age_constraint",
44
44
  )
45
45
 
46
46
 
47
47
  def test_max_age(run_constraints_test):
48
- """Check that the minimum age is greater than 0"""
48
+ """Check that the max age is greater than 0"""
49
49
  run_constraints_test(
50
50
  new_rows=[
51
51
  DBRefugees(
@@ -56,13 +56,13 @@ def test_max_age(run_constraints_test):
56
56
  gender="f",
57
57
  age_range="children",
58
58
  min_age=5,
59
- max_age=1200,
59
+ max_age=-1,
60
60
  population=2000,
61
61
  reference_period_start=datetime(2023, 1, 1),
62
62
  reference_period_end=datetime(2023, 12, 31),
63
63
  )
64
64
  ],
65
- expected_constraint="max_age",
65
+ expected_constraint="max_age_constraint",
66
66
  )
67
67
 
68
68
 
@@ -84,7 +84,7 @@ def test_population_positive(run_constraints_test):
84
84
  reference_period_end=datetime(2023, 12, 31),
85
85
  )
86
86
  ],
87
- expected_constraint="population",
87
+ expected_constraint="population_constraint",
88
88
  )
89
89
 
90
90
 
@@ -106,5 +106,5 @@ def test_reference_period_constraint(run_constraints_test):
106
106
  reference_period_end=datetime(2023, 1, 1),
107
107
  )
108
108
  ],
109
- expected_constraint="reference_period",
109
+ expected_constraint="reference_period_constraint",
110
110
  )
@@ -31,7 +31,7 @@ def test_lat_constraint(run_constraints_test):
31
31
  new_rows=[
32
32
  DBWFPMarket(**data),
33
33
  ],
34
- expected_constraint="latlon",
34
+ expected_constraint="latlon_constraint",
35
35
  )
36
36
 
37
37
 
File without changes
File without changes
File without changes
File without changes
File without changes