Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Adds tests for email endpoints and dispatch service #1112

Merged
merged 4 commits into from
Aug 19, 2022
Merged

Conversation

eastandwestwind
Copy link
Contributor

@eastandwestwind eastandwestwind commented Aug 19, 2022

Purpose

Adds tests for email endpoints and dispatch service

Changes

  • Adds tests
  • updates 400 err to 404

Checklist

  • Update CHANGELOG.md file
    • Merge in main so the most recent CHANGELOG.md file is being appended to
    • Add description within the Unreleased section in an appropriate category. Add a new category from the list at the top of the file if the needed one isn't already there.
    • Add a link to this PR at the end of the description with the PR number as the text. example: #1
  • Applicable documentation updated (guides, quickstart, postman collections, tutorial, fidesdemo, database diagram.
  • If docs updated (select one):
    • documentation complete, or draft/outline provided (tag docs-team to complete/review on this branch)
    • documentation issue created (tag docs-team to complete issue separately)
  • Good unit test/integration test coverage
  • This PR contains a DB migration. If checked, the reviewer should confirm with the author that the down_revision correctly references the previous migration before merging
  • The Run Unsafe PR Checks label has been applied, and checks have passed, if this PR touches any external services

Ticket

Fixes #1086

Copy link
Contributor

@pattisdr pattisdr left a comment

Choose a reason for hiding this comment

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

nice attention to detail in these tests @eastandwestwind!

assert 422 == response.status_code
assert (
json.loads(response.text)["detail"][0]["msg"]
== "[\"field required ('domain',)\", \"extra fields not permitted ('invalid',)\"]"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you lean on Pydantic to take care of more of the validation for you and remove some of the redundant checks in EmailConfigRequest.validate_details? For example, if you remove your validate_details, you still get a 422 with the following response body:

{
   "detail":[
      {
         "loc":[
            "body",
            "details",
            "domain"
         ],
         "msg":"field required",
         "type":"value_error.missing"
      },
      {
         "loc":[
            "body",
            "details",
            "invalid"
         ],
         "msg":"extra fields not permitted",
         "type":"value_error.extra"
      }
   ]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice, taking a look at this now

assert response.status_code == 422
errors = response.json()["detail"]
assert "details" in errors[0]["loc"]
assert errors[0]["msg"] == "[\"field required ('domain',)\"]"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with this response, if you get rid of your custom validation in EmailConfigRequest.validate_details, you get the following response body, without the escaping issues:

{
   "loc":[
      "body",
      "details",
      "domain"
   ],
   "msg":"field required",
   "type":"value_error.missing"
}

@eastandwestwind
Copy link
Contributor Author

@pattisdr back over to you, thanks for the review!

Comment on lines -106 to +107
logger.error(e)
raise EmailDispatchException(format("Email failed to send: %s", str(e)))
logger.error("Email failed to send: %s", str(e))
raise EmailDispatchException(f"Email failed to send due to: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

I do think the %-style formatting you were using is better, there's a ticket to move to that at some point, but no need to change now since it's consistent with what we have now.

#837

Copy link
Contributor

@pattisdr pattisdr left a comment

Choose a reason for hiding this comment

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

@pattisdr pattisdr merged commit 4d9efb6 into main Aug 19, 2022
@pattisdr pattisdr deleted the 1086-email-tests branch August 19, 2022 20:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests for EmailConfig APIs
2 participants