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

Tests #106

Merged
merged 3 commits into from
Nov 11, 2023
Merged

Tests #106

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Python Tests

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install pytest-mock
pip install -r requirements.txt

- name: Run tests
run: |
pytest tests/test_send.py
3 changes: 3 additions & 0 deletions send/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Initialize PyPI Package

__all__ = ["main"]
95 changes: 48 additions & 47 deletions send.py → send/send.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
"""
Auto Announcements - A bot framework that automatically sends announcements.
Copyright (C) 2017-2023 Dog Face Development Co.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from email.mime.text import *
import smtplib
import time
import datetime


def main():
sendaddress = input("YOUR email address:")
# replace above with your email address for direct delivery
receiveaddress = input("RECIPIENT's email address:")
# replace above with the recipients email address for direct delivery

DATE = str(datetime.datetime.today())
DATEtoday = str(datetime.date.today())
print(DATE)

msg = MIMEText("<h1>A Heading</h1><p>Hello There!</p>", "html")

msg["Subject"] = "Church Announcements for", DATEtoday
msg["From"] = sendaddress
msg["To"] = receiveaddress

s = smtplib.SMTP("localhost")
s.sendmail(sendaddress, [receiveaddress], msg.as_string())

print("Message sent successfully on", DATE, "!")


if __name__ == "__main__":
main()
"""
Auto Announcements - A bot framework that automatically sends announcements.
Copyright (C) 2017-2023 Dog Face Development Co.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

from email.mime.text import *
import smtplib
import time
import datetime


def main():
global msg
sendaddress = input("YOUR email address:")
# replace above with your email address for direct delivery
receiveaddress = input("RECIPIENT's email address:")
# replace above with the recipients email address for direct delivery

DATE = str(datetime.datetime.today())
DATEtoday = str(datetime.date.today())
print(DATE)

msg = MIMEText("<h1>A Heading</h1><p>Hello There!</p>", "html")

msg["Subject"] = "Church Announcements for", DATEtoday
msg["From"] = sendaddress
msg["To"] = receiveaddress

s = smtplib.SMTP("localhost")
s.sendmail(sendaddress, [receiveaddress], msg.as_string())

print("Message sent successfully on", DATE, "!")


if __name__ == "__main__":
main()
35 changes: 35 additions & 0 deletions tests/test_send.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
import datetime
from unittest.mock import MagicMock

# Get out of the test directory
import sys

sys.path.append("../send")

# Import file to test
import send


def test_main(mocker):
mock_input = mocker.patch(
"builtins.input", side_effect=["sender@example.com", "receiver@example.com"]
)
mock_smtp = mocker.patch("smtplib.SMTP")
mock_print = mocker.patch("builtins.print")

mock_smtp_instance = MagicMock()
mock_smtp.return_value = mock_smtp_instance

send.main()

mock_input.assert_any_call("YOUR email address:")
mock_input.assert_any_call("RECIPIENT's email address:")
mock_smtp.assert_called_once_with("localhost")
mock_smtp_instance.sendmail.assert_called_once_with(
"sender@example.com",
["receiver@example.com"],
send.msg.as_string(), # assuming msg is a global variable
)
date_today = str(datetime.datetime.today())
mock_print.assert_called_with("Message sent successfully on", date_today, "!")
Loading