Skip to content

Commit

Permalink
sendEmail mock test
Browse files Browse the repository at this point in the history
Kjører en simpel mock test
  • Loading branch information
victbakk committed Feb 22, 2024
1 parent a7bb137 commit 1cea81f
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 3 deletions.
Binary file modified WMS/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified WMS/__pycache__/ortofoto.cpython-311.pyc
Binary file not shown.
Binary file modified WMS/__pycache__/sanderscript.cpython-311.pyc
Binary file not shown.
Binary file modified WMS/__pycache__/util.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion WMS/resources/config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Config": {"data_parameters": ["90", "10", "100"], "layers": ["Bygning", "Veg", "Bru"], "colors": ["#000000", "#ffff00", "#00ff00"]}}
{"Config": {"data_parameters": [0.4, 0.4, 0.4], "layers": ["Bygning"], "colors": ["#000000"]}}
2 changes: 1 addition & 1 deletion WMS/resources/coordinates.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Coordinates": [[593258.009753139, 6644808.377803862], [593255.0498549859, 6644925.788442824], [593641.2676597863, 6644935.545142756], [593644.2398199342, 6644818.134709595], [593258.009753139, 6644808.377803862]]}
{"Coordinates": [592779.1140089021, 6647491.588284892, 592763.7375065162, 6648104.070222126, 593262.1290835012, 6648116.616443546, 593277.5882226683, 6647504.13588983, 592779.1140089021, 6647491.588284892]}
Binary file added __pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/deleteFolder.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 30 additions & 1 deletion test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient
from main import app
from unittest.mock import patch
from unittest.mock import patch, MagicMock


#Import test client
Expand Down Expand Up @@ -47,3 +47,32 @@ def test_generatePhotos():

def cleanup_test_data():
pass

@patch('main.send_email_with_attachment')
@patch('main.zip_files')
@patch('os.remove')
@patch('main.util.teardown_WMS_folders')
def test_send_zipped_files_email(mock_teardown, mock_remove, mock_zip, mock_send_email):
# Mock the behavior of external dependencies
mock_zip.return_value = None
mock_send_email.return_value = None
mock_remove.return_value = None
mock_teardown.return_value = None

# Simulate a request with a JSON payload containing the email
response = client.post("/sendEmail", json={"email": "[email protected]"})

# Assertions to verify the endpoint behavior
assert response.status_code == 200
assert response.json() == {"message": "Email sent successfully with zipped files."}

# Verify that the mocked functions were called as expected
mock_zip.assert_called_once_with() # Add any arguments if your function requires them
mock_send_email.assert_called_once_with(
to_emails="[email protected]",
subject="Here are your zipped files",
content="<strong>Zip file holding the requested data.</strong>",
attachment_path="attachments.zip"
)
mock_remove.assert_called_once_with("attachments.zip")
mock_teardown.assert_called_once()

0 comments on commit 1cea81f

Please sign in to comment.