{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "34f766aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "class AlertSys:\n",
    "    def __init__(self, phone_number, email_address):\n",
    "        self.phone_number = phone_number\n",
    "        self.email_address = email_address\n",
    "    \n",
    "    def sendText(self, message):\n",
    "        # Use a third-party service to send a text message to the specified phone number\n",
    "        print(f\"Sending text message to {self.phone_number}: {message}\")\n",
    "    \n",
    "    def sendEmail(self, subject, message):\n",
    "        # Use a third-party email service to send an email to the specified email address\n",
    "        print(f\"Sending email to {self.email_address} with subject '{subject}': {message}\")\n",
    "    \n",
    "    def check_blood_glucose(self, glucose_level):\n",
    "        if glucose_level < 70 or glucose_level > 180:\n",
    "            message = f\"Blood glucose level is abnormal: {glucose_level}\"\n",
    "            self.sendText(message)\n",
    "            self.sendEmail(\"Alert: Abnormal Blood Glucose Level\", message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6582589f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sending text message to +15551234567: Blood glucose level is abnormal: 200\n",
      "Sending email to johndoe@example.com with subject 'Alert: Abnormal Blood Glucose Level': Blood glucose level is abnormal: 200\n"
     ]
    }
   ],
   "source": [
    "# Create an AlertSys object with a phone number and email address\n",
    "alert_system = AlertSys(\"+15551234567\", \"johndoe@example.com\")\n",
    "\n",
    "# Check a blood glucose level\n",
    "glucose_level = 200\n",
    "alert_system.check_blood_glucose(glucose_level)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1a59a372",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "...\n",
      "----------------------------------------------------------------------\n",
      "Ran 3 tests in 0.010s\n",
      "\n",
      "OK\n"
     ]
    }
   ],
   "source": [
    "import unittest\n",
    "from unittest.mock import patch\n",
    "\n",
    "\n",
    "class TestAlertSys(unittest.TestCase):\n",
    "    def setUp(self):\n",
    "        # Create an AlertSys object with a mock phone number and email address\n",
    "        self.alert_system = AlertSys(\"+15551234567\", \"johndoe@example.com\")\n",
    "    \n",
    "    @patch.object(AlertSys, 'sendText')\n",
    "    @patch.object(AlertSys, 'sendEmail')\n",
    "    def test_check_blood_glucose_normal(self, mock_send_email, mock_send_text_message):\n",
    "        # Check a normal blood glucose level\n",
    "        glucose_level = 100\n",
    "        self.alert_system.check_blood_glucose(glucose_level)\n",
    "        \n",
    "        # Ensure that no alerts were sent\n",
    "        mock_send_text_message.assert_not_called()\n",
    "        mock_send_email.assert_not_called()\n",
    "    \n",
    "    @patch.object(AlertSys, 'sendText')\n",
    "    @patch.object(AlertSys, 'sendEmail')\n",
    "    def test_check_blood_glucose_low(self, mock_send_email, mock_send_text_message):\n",
    "        # Check a low blood glucose level\n",
    "        glucose_level = 50\n",
    "        self.alert_system.check_blood_glucose(glucose_level)\n",
    "        \n",
    "        # Ensure that a text message and email alert were sent\n",
    "        mock_send_text_message.assert_called_once_with('Blood glucose level is abnormal: 50')\n",
    "        mock_send_email.assert_called_once_with('Alert: Abnormal Blood Glucose Level', 'Blood glucose level is abnormal: 50')\n",
    "    \n",
    "    @patch.object(AlertSys, 'sendText')\n",
    "    @patch.object(AlertSys, 'sendEmail')\n",
    "    def test_check_blood_glucose_high(self, mock_send_email, mock_send_text_message):\n",
    "        # Check a high blood glucose level\n",
    "        glucose_level = 200\n",
    "        self.alert_system.check_blood_glucose(glucose_level)\n",
    "        \n",
    "        # Ensure that a text message and email alert were sent\n",
    "        mock_send_text_message.assert_called_once_with('Blood glucose level is abnormal: 200')\n",
    "        mock_send_email.assert_called_once_with('Alert: Abnormal Blood Glucose Level', 'Blood glucose level is abnormal: 200')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    unittest.main(argv=['first-arg-is-ignored'],exit=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69820de1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
