Skip to content

Commit

Permalink
Merge pull request #9328 from OpenMined/bschell/add-user-emails-recei…
Browse files Browse the repository at this point in the history
…ved-check-bq-notebooks

Check that users receive approved / reject emails in bigquery L2 notebook
  • Loading branch information
IonesioJunior authored Sep 27, 2024
2 parents 53bb398 + e3600b6 commit 4226ac2
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions notebooks/scenarios/bigquery/040-do-review-requests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"outputs": [],
"source": [
"# stdlib\n",
"from collections import Counter\n",
"import random\n",
"\n",
"# syft absolute\n",
Expand Down Expand Up @@ -220,9 +221,46 @@
"metadata": {},
"outputs": [],
"source": [
"# for user_email, new_count in new_n_emails_per_job_user.items():\n",
"# old_count = n_emails_per_job_user[user_email]\n",
"# assert new_count > old_count"
"job_emails = get_job_emails(submitted_jobs_data, high_client, email_server)\n",
"rejected_email_counts = {\n",
" k: sum(\"rejected\" in email[\"email_content\"].lower() for email in v)\n",
" for k, v in job_emails.items()\n",
"}\n",
"approved_email_counts = {\n",
" k: sum(\"approved\" in email[\"email_content\"].lower() for email in v)\n",
" for k, v in job_emails.items()\n",
"}\n",
"expected_rejected_email_counts = Counter(\n",
" job.user_email for job in submitted_jobs_data_should_fail\n",
")\n",
"\n",
"expected_approved_email_counts = Counter(\n",
" job.user_email for job in submitted_jobs_data_should_succeed\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# if user's email notifications are enabled,\n",
"# should have received either approved or rejected email\n",
"for user_email, new_count in new_n_emails_per_job_user.items():\n",
" user = [u for u in users if u.email == user_email][0]\n",
" old_count = n_emails_per_job_user[user_email]\n",
" if not user.email_disabled:\n",
" # greater than or equal to since duplicates can happen\n",
" assert new_count > old_count\n",
" assert rejected_email_counts.get(\n",
" user_email, 0\n",
" ) >= expected_rejected_email_counts.get(user_email, 0)\n",
" assert approved_email_counts.get(\n",
" user_email, 0\n",
" ) >= expected_approved_email_counts.get(user_email, 0)\n",
" else:\n",
" assert new_count == old_count"
]
},
{
Expand Down Expand Up @@ -293,6 +331,11 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "syft",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -303,7 +346,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 4226ac2

Please sign in to comment.