Last active
January 16, 2019 22:11
-
-
Save d4vsanchez/ea5ba3b60e0c1138692583afb249620d to your computer and use it in GitHub Desktop.
Final version of the tests for the report model example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mock | |
from django.core import mail | |
from django.test import TestCase | |
from boto3.session import Session | |
from reports.models.report import Report | |
class FakeResource(): | |
def Bucket(self, bucket): | |
return self | |
def put_object(self, Key=None, Body=None, ACL='', Expires='', ContentType=''): | |
# We do nothing here, but return the same data type without data | |
return {} | |
class FakeSession(Session): | |
def resource(self, name): | |
return FakeResource() | |
@mock.patch('reports.models.report.Session', FakeSession) | |
class ReportTest(TestCase): | |
def tearDown(self): | |
Report.objects.all().delete() | |
mail.outbox = [] | |
def test_create_report_and_send_by_email(self): | |
info = {"name": "Fake report"} # This is a dict with the information of the fake Report | |
report = Report.objects.create(**info) | |
# There shouldn't be emails in the outbox | |
self.assertEqual(len(mail.outbox), 0) | |
report.create_report_and_send_by_email(self) | |
# There should be one email in the outbox | |
self.assertEqual(len(mail.outbox), 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment