Skip to content
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

Remove magic number and add error handling #1538

Merged
merged 2 commits into from
Aug 7, 2023
Merged

Conversation

JimMadge
Copy link
Member

@JimMadge JimMadge commented Aug 4, 2023

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).
  • You have marked this pull request as a draft and added '[WIP]' to the title if needed (if you're not yet ready to merge).
  • You have formatted your code using appropriate automated tools (for example ./tests/AutoFormat_Powershell.ps1 -TargetPath <path to file or directory> for Powershell).

⤴️ Summary

  • Remove magic number
  • Add DataSafeHavenActiveDirectoryError exception
  • Add error handling for when number of fields is not what is expected

I'm a little ambivalent about the error handling. Checking that the number of columns returned is what we expect is sensible, we are interacting with an external process.

However, this

if (
user.username
and user.given_name
and user.surname
and user.phone_number
and user.email_address
and user.country
):

Is already checked here

for required_field in [
"GivenName",
"Surname",
"Phone",
"Email",
"CountryCode",
]:
if (not reader.fieldnames) or (
required_field not in reader.fieldnames
):
msg = f"Missing required CSV field '{required_field}'."
raise ValueError(msg)

🌂 Related issues

Closes #1513

🔬 Tests

@jemrobinson
Copy link
Member

As the flow is:

  • check we're providing the right arguments
  • run an external script with those arguments
  • get the output
  • check that the output has the right form

I think it's correct to have two checks.

@jemrobinson jemrobinson added this to the Python migration milestone Aug 4, 2023
Copy link
Member

@jemrobinson jemrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimMadge: happy with whichever option you choose to resolve the external Powershell script issue.

Copy link
Member

@jemrobinson jemrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JimMadge JimMadge merged commit 98afa4f into python-migration Aug 7, 2023
6 checks passed
@JimMadge JimMadge deleted the magic_number branch August 7, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants