Skip to content

Commit

Permalink
Add actions test (#33)
Browse files Browse the repository at this point in the history
* Add pytest and fix import

* Add actions test
  • Loading branch information
gugsrs authored and ashwini0529 committed Oct 18, 2017
1 parent b715b6f commit 501605e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hackr/object_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import generator
from . import generator


def generate_json(count, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ qrcode
pillow
xmljson
sphinx_rtd_theme
matplotlib 2.0.2
matplotlib==2.0.2
pytest
Empty file added tests/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from io import StringIO
from unittest import mock

import smtplib
import pytest

from hackr.actions import email


@mock.patch('smtplib.SMTP')
def test_email(mock_smtp):
message = 'Mail message'
params = {
'email': '[email protected]',
'password': 'password',
'to': '[email protected]',
'subject': 'Test',
}
mock_smtp = mock.Mock()

response = email(message, **params)

assert response == 'Mail Sent Successfully'


@mock.patch('smtplib.SMTP')
def test_email_exception(mock_smtp):
message = 'Mail message'
params = {
'email': '[email protected]',
'password': 'password',
'to': '[email protected]',
'subject': 'Test',
}

instance = mock_smtp.return_value
instance.ehlo.side_effect = smtplib.SMTPRecipientsRefused('Failed to sent mail.')
response = email(message, **params)

assert not response

0 comments on commit 501605e

Please sign in to comment.