-
Notifications
You must be signed in to change notification settings - Fork 4
feat(tests): add validation error handling for various invalid CSV field values #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32b4c54
4519fc5
2c3cde4
bc89558
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,7 +50,7 @@ def step_step_step(context: Context): | |||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @given( | ||||||||||||||
| "my CSV file contains a row that has an invalid postal code format in contact_1_address_1_postal_code" | ||||||||||||||
| "my CSV file contains a row that has an invalid postal code format in contact_1_address_1_postal_code" | ||||||||||||||
| ) | ||||||||||||||
| def step_step_step_2(context: Context): | ||||||||||||||
| _set_file_content(context, "well-inventory-invalid-postal-code.csv") | ||||||||||||||
|
|
@@ -362,4 +362,76 @@ def step_step_step_21(context): | |||||||||||||
| _set_file_content(context, "well-inventory-missing-wl-fields.csv") | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @given( | ||||||||||||||
| "my CSV file contains a row with an address_type value that is not one of: Work, Personal, Mailing, Physical" | ||||||||||||||
| ) | ||||||||||||||
| def step_given_row_contains_invalid_address_type_value(context: Context): | ||||||||||||||
| df = _get_valid_df(context) | ||||||||||||||
| df.loc[0, "contact_1_address_1_type"] = "InvalidAddressType" | ||||||||||||||
| _set_content_from_df(context, df) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @given( | ||||||||||||||
| "my CSV file contains a row with a state value that is not a valid 2-letter US state abbreviation" | ||||||||||||||
| ) | ||||||||||||||
| def step_given_row_contains_invalid_state_value(context: Context): | ||||||||||||||
| df = _get_valid_df(context) | ||||||||||||||
| df.loc[0, "contact_1_address_1_state"] = "New Mexico" | ||||||||||||||
| _set_content_from_df(context, df) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @given( | ||||||||||||||
| 'my CSV file contains a row with a well_hole_status value that is not one of: "Abandoned", "Active, pumping well", "Destroyed, exists but not usable", "Inactive, exists but not used"' | ||||||||||||||
| ) | ||||||||||||||
| def step_given_row_contains_invalid_well_hole_status_value(context: Context): | ||||||||||||||
| df = _get_valid_df(context) | ||||||||||||||
| if "well_status" in df.columns: | ||||||||||||||
| df.loc[0, "well_status"] = "NotARealWellHoleStatus" | ||||||||||||||
jirhiker marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| _set_content_from_df(context, df) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @given( | ||||||||||||||
| 'my CSV file contains a row with a monitoring_status value that is not one of: "Open", "Open (unequipped)", "Closed", "Datalogger can be installed", "Datalogger cannot be installed", "Abandoned", "Active, pumping well", "Destroyed, exists but not usable", "Inactive, exists but not used", "Currently monitored", "Not currently monitored"' | ||||||||||||||
| ) | ||||||||||||||
| def step_given_row_contains_invalid_monitoring_status_value(context: Context): | ||||||||||||||
| df = _get_valid_df(context) | ||||||||||||||
| if "monitoring_frequency" in df.columns: | ||||||||||||||
|
||||||||||||||
| if "monitoring_frequency" in df.columns: | |
| # Prefer the monitoring_status column if present; fall back to monitoring_frequency | |
| # for schemas that still use that name. | |
| if "monitoring_status" in df.columns: | |
| df.loc[0, "monitoring_status"] = "NotARealMonitoringStatus" | |
| elif "monitoring_frequency" in df.columns: |
jirhiker marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| @production | ||
| @backend | ||
| @cli | ||
| @BDMS-TBD | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_extract_field_from_value_error()relies on parsingstr(e)to infer a field name. This is brittle because exception string formatting can change between Pydantic versions and for different error shapes. Sincepydantic.ValidationErroris already imported, consider catchingValidationErrorexplicitly in_import_well_inventory_csv(before theValueErrorhandler) and deriving the field frome.errors()[0]['loc'](with a safe fallback) instead of string parsing.