def test_test_mail(): """Tests for learn_mail, with a running SA instance.""" fmail = open('tests/examples/spam.eml', 'rb') ftext = fmail.read() mail = new_message(ftext) fmail.close() # We test the mail with spamc: score1, code1, spamassassin_result = spamproc.test_mail(mail, True) score2, code2, spamassassin_result = spamproc.test_mail( mail, cmd=["spamc", "-E", "--max-size=268435450"]) assert score1 == score2, "The score should be the same." assert code1 == code2, "The return code should be the same." score, code, spamassassin_result = spamproc.test_mail("", True) assert score == u'-9999', 'It should return a error' assert code is None, 'It should return a error' # We test the mail with spamassassin: score3, code3, spamassassin_result = spamproc.test_mail(mail, False) score4, code4, spamassassin_result = spamproc.test_mail( mail, cmd=["spamassassin", "--exit-code"]) assert score3 == score4, "The score should be the same." assert code3 == code4, "The return code should be the same." score, code, spamassassin_result = spamproc.test_mail("", False) assert score == u'-9999', 'It should return a error' assert code is None, 'It should return a error' # We try a random cmds (existant and unexistant): score, code, spamassassin_result = spamproc.test_mail("", cmd=["echo"]) assert score == u'-9999', 'It should return a error' assert code is None, 'It should return a error' with pytest.raises(OSError, match="No such file"): spamproc.test_mail(mail, cmd=["_____fooo___x_x"]) pytest.fail("Should rise OSError.")
def test_feed_mail(): """Test feed_mail.""" fmail = open('examples/spam.eml', 'rb') ftext = fmail.read() mail = new_message(ftext) fmail.close() if cmd_exists('spamc'): # We test the mail with spamc: new_mail1, code1 = spamproc.feed_mail(mail, True) new_mail2, code2 = spamproc.feed_mail(mail, cmd=["spamc"]) assert code1 == code2, "The return code should be the same." new_mail, code = spamproc.feed_mail("", True) assert new_mail == '-9999', 'It should return a error' assert code is None, 'It should return a error' else: with pytest.raises(OSError, match="No such file", message="Should rise OSError."): spamproc.feed_mail(mail, True) with pytest.raises(OSError, match="No such file", message="Should rise OSError."): spamproc.feed_mail(mail, cmd=["spamc"]) if cmd_exists('spamassassin'): # We test the mail with spamassassin: new_mail3, code3 = spamproc.feed_mail(mail, False) new_mail4, code4 = spamproc.test_mail(mail, cmd=["spamassassin"]) assert code3 == code4, "The return code should be the same." new_mail, code = spamproc.test_mail("", False) assert new_mail == u'-9999', 'It should return a error' assert code is None, 'It should return a error' else: with pytest.raises(OSError, match="No such file", message="Should rise OSError."): spamproc.feed_mail(mail, False) with pytest.raises(OSError, match="No such file", message="Should rise OSError."): spamproc.feed_mail(mail, cmd=["spamassassin"]) # We try a random cmds (existant and unexistant new_mail, code = spamproc.feed_mail("", cmd=["echo"]) assert new_mail == u'-9999', 'It should return a error' assert code is None, 'It should return a error' with pytest.raises(OSError, match="No such file", message="Should rise OSError."): spamproc.feed_mail(mail, cmd=["_____fooo___x_x"])
def test_test_mail(): """Tests for learn_mail.""" fmail = open('examples/spam.eml', 'rb') ftext = fmail.read() mail = new_message(ftext) fmail.close() if cmd_exists('spamc'): # We test the mail with spamc: score1, code1, spamassassin_result = spamproc.test_mail(mail, True) score2, code2, spamassassin_result = spamproc.test_mail(mail, cmd=["spamc", "-E", "--max-size=268435450"]) assert score1 == score2, "The score should be the same." assert code1 == code2, "The return code should be the same." score, code, spamassassin_result = spamproc.test_mail("", True) assert score == u'-9999', 'It should return a error' assert code is None, 'It should return a error' else: with pytest.raises(OSError, match="No such file"): spamproc.test_mail(mail, True) pytest.fail("Should rise OSError.") with pytest.raises(OSError, match="No such file"): spamproc.test_mail(mail, cmd=["spamc", "-E", "--max-size=268435450"]) pytest.fail("Should rise OSError.") if cmd_exists('spamassassin'): # We test the mail with spamassassin: score3, code3, spamassassin_result = spamproc.test_mail(mail, False) score4, code4, spamassassin_result = spamproc.test_mail(mail, cmd=["spamassassin", "--exit-code"]) assert score3 == score4, "The score should be the same." assert code3 == code4, "The return code should be the same." score, code, spamassassin_result = spamproc.test_mail("", False) assert score == u'-9999', 'It should return a error' assert code is None, 'It should return a error' else: with pytest.raises(OSError, match="No such file"): spamproc.test_mail(mail, False) pytest.fail("Should rise OSError.") with pytest.raises(OSError, match="No such file"): spamproc.test_mail(mail, cmd=["spamassassin", "--exit-code"]) pytest.fail("Should rise OSError.") # We try a random cmds (existant and unexistant): score, code, spamassassin_result = spamproc.test_mail("", cmd=["echo"]) assert score == u'-9999', 'It should return a error' assert code is None, 'It should return a error' with pytest.raises(OSError, match="No such file"): spamproc.test_mail(mail, cmd=["_____fooo___x_x"]) pytest.fail("Should rise OSError.")