-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
|
||
|
||
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" Monkey-patch smtplib so we don't send actual emails. | ||
Thanks to http://www.psychicorigami.com/2007/09/20/monkey-patching-pythons-smtp-lib-for-unit-testing/ | ||
Importing this module and smtplib.SMTP will refer to the DummySMTP bellow. | ||
It provides access to any sent messages via emailutils.inbox and the last | ||
SMTP class created via emailutils.smtp. | ||
Example : | ||
import emailutils | ||
def test_some_email(): | ||
emailutils.inbox = [] # clear the inbox | ||
# code that does some emailing here | ||
assert len(emailutils.inbox) == 1 # check one email was sent | ||
assert emailutils.inbox[0].to_address == '[email protected]' | ||
""" | ||
|
||
smtp = None | ||
inbox = [] | ||
|
||
class Message(object): | ||
|
||
def __init__(self, from_address, to_address, fullmessage): | ||
self.from_address = from_address | ||
self.to_address = to_address | ||
self.fullmessage = fullmessage | ||
|
||
class DummySMTP(object): | ||
|
||
def __init__(self, address): | ||
self.address = address | ||
global smtp | ||
smtp = self | ||
|
||
def login(self, username, password): | ||
self.username = username | ||
self.password = password | ||
|
||
def sendmail(self, from_address, to_address, fullmessage): | ||
global inbox | ||
inbox.append(Message(from_address, to_address, fullmessage)) | ||
return [] | ||
|
||
def quit(self): | ||
self.has_quit = True | ||
|
||
# this is the actual monkey patch (simply replacing one class with another) | ||
import smtplib | ||
smtplib.SMTP = DummySMTP |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# http://docs.python.org/2/library/unittest.html | ||
|
||
import unittest | ||
|
||
import emailutils | ||
from supervision.website import config | ||
|
||
# TODO | ||
# monkey patching pythons smtp lib | ||
# http://www.psychicorigami.com/2007/09/20/monkey-patching-pythons-smtp-lib-for-unit-testing/ | ||
|
||
class TestSetupConfig(unittest.TestCase): | ||
|
||
def setUp(self): | ||
# Adapt the module configuration for our tests | ||
config.TIMEOUT = 1000 | ||
# etc...... | ||
|
||
class TestGenerateCheckHostShScript(TestSetupConfig): | ||
# sh script generation | ||
# check all is ok | ||
pass | ||
|
||
class TestCheckHostShScript(TestSetupConfig): | ||
# extend setup to delete the reports folder and his content | ||
# sh script generation | ||
# launch sh script to initialize folder structure | ||
# check : the folder exists | ||
# check : sitemonitor.current.status exists and is not empty | ||
# check : sitemonitor.previous.status exists and is empty | ||
# launch sh script | ||
# check : sitemonitor.current.status exists and is not empty | ||
# check : sitemonitor.previous.status exists and is not empty | ||
# check : sitemonitor.previous.status = initial sitemonitor.current.status | ||
pass | ||
|
||
class TestReadStatus(TestSetupConfig): | ||
# extend setup to delete the reports folder and his content | ||
# sh script generation | ||
# launch sh script to initialize folder structure | ||
|
||
# set custom sitemonitor.current.status & sitemonitor.previous.status | ||
# with all possible configurations : SLOW_THRESHOLD, OK_STATUSES_PER_HOST, ... | ||
# verifier read_status(status_type='current') | ||
# verifier read_status(status_type='previous') | ||
|
||
pass | ||
|
||
class TestGenerateReports(TestSetupConfig): | ||
# ! test only complete report lines | ||
|
||
# extend setup to delete the reports folder and his content | ||
# sh script generation | ||
# launch sh script to initialize folder structure | ||
|
||
# set custom sitemonitor.current.status | ||
# generate reports | ||
# check reports txt/html | ||
|
||
# set custom sitemonitor.current.status & sitemonitor.previous.status | ||
# generate reports | ||
# check reports txt/html | ||
|
||
pass | ||
|
||
class TestSendMail(TestSetupConfig): | ||
# extend setup to delete the reports folder and his content | ||
# sh script generation | ||
# launch sh script to initialize folder structure | ||
|
||
# set same custom sitemonitor.current.status & sitemonitor.previous.status | ||
# MAIL_SEND = False, MAIL_SEND_ONLY_ON_CHANGE=False | ||
# generate reports | ||
# no mail | ||
# MAIL_SEND = False, MAIL_SEND_ONLY_ON_CHANGE=True | ||
# generate reports | ||
# no mail | ||
# MAIL_SEND = True, MAIL_SEND_ONLY_ON_CHANGE=False | ||
# generate reports | ||
# MAIL_SEND = True, MAIL_SEND_ONLY_ON_CHANGE=True | ||
# generate reports | ||
# no mail | ||
|
||
# set different sitemonitor.current.status & sitemonitor.previous.status | ||
# MAIL_SEND = False, MAIL_SEND_ONLY_ON_CHANGE=False | ||
# generate reports | ||
# no mail | ||
# MAIL_SEND = False, MAIL_SEND_ONLY_ON_CHANGE=True | ||
# generate reports | ||
# no mail | ||
# MAIL_SEND = True, MAIL_SEND_ONLY_ON_CHANGE=False | ||
# generate reports | ||
# MAIL_SEND = True, MAIL_SEND_ONLY_ON_CHANGE=True | ||
# generate reports | ||
|
||
# test from/to... on the last message | ||
|
||
pass | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# needed to allow coverage for the python script | ||
import generate_reports | ||
import generate_check_host_sh_script |