def test_send_msg(): """ Test to send a message via SMTP """ name = "This is a salt states module" comt = "Need to send message to [email protected]: This is a salt states module" ret = {"name": name, "changes": {}, "result": None, "comment": comt} with patch.dict(smtp.__opts__, {"test": True}): assert ret == smtp.send_msg( name, "*****@*****.**", "Message from Salt", "*****@*****.**", "my-smtp-account", ) comt = "Sent message to [email protected]: This is a salt states module" with patch.dict(smtp.__opts__, {"test": False}): mock = MagicMock(return_value=True) with patch.dict(smtp.__salt__, {"smtp.send_msg": mock}): ret["comment"] = comt ret["result"] = True assert ret == smtp.send_msg( name, "*****@*****.**", "Message from Salt", "*****@*****.**", "my-smtp-account", )
def test_send_msg(self): ''' Test to send a message via SMTP ''' name = 'This is a salt states module' comt = ('Need to send message to [email protected]:' ' This is a salt states module') ret = {'name': name, 'changes': {}, 'result': None, 'comment': comt} with patch.dict(smtp.__opts__, {'test': True}): self.assertDictEqual(smtp.send_msg(name, '*****@*****.**', 'Message from Salt', '*****@*****.**', 'my-smtp-account'), ret) comt = ('Sent message to [email protected]: ' 'This is a salt states module') with patch.dict(smtp.__opts__, {'test': False}): mock = MagicMock(return_value=True) with patch.dict(smtp.__salt__, {'smtp.send_msg': mock}): ret['comment'] = comt ret['result'] = True self.assertDictEqual(smtp.send_msg(name, '*****@*****.**', 'Message from Salt', '*****@*****.**', 'my-smtp-account'), ret)