コード例 #1
0
ファイル: test_isbg.py プロジェクト: xpunkt/isbg
 def test_do_isbg(self):
     """Test do_isbg."""
     sbg = isbg.ISBG()
     with pytest.raises(isbg.ISBGError, match="specify your imap password"):
         sbg.do_isbg()
         pytest.fail("It should rise a specify imap password " +
                     "ISBGError")
コード例 #2
0
ファイル: test_spamproc.py プロジェクト: l2dy/isbg
 def test_process_inbox(self):
     """Test process_inbox."""
     sbg = isbg.ISBG()
     sa = spamproc.SpamAssassin.create_from_isbg(sbg)
     with pytest.raises(AttributeError, match="has no attribute"):
         sa.process_inbox([])
         pytest.fail("Should rise error, IMAP not created.")
コード例 #3
0
ファイル: test_spamproc.py プロジェクト: l2dy/isbg
    def test_get_formated_uids(self):
        """Test get_formated_uids."""
        sbg = isbg.ISBG()
        sa = spamproc.SpamAssassin.create_from_isbg(sbg)

        # Test sorted and partialrun
        ret, oripast = sa.get_formated_uids(uids=[u'1 2 3'],
                                            origpastuids=[],
                                            partialrun=None)
        assert ret == [u'3', u'2', u'1']
        assert oripast == [], "List should be empty."

        ret, oripast = sa.get_formated_uids(uids=[u'1 2 3'],
                                            origpastuids=[],
                                            partialrun=3)
        assert ret == [u'3', u'2', u'1']
        assert oripast == [], "List should be empty."

        ret, oripast = sa.get_formated_uids(uids=[u'1 2 3'],
                                            origpastuids=[],
                                            partialrun=2)
        assert ret == [u'3', u'2']
        assert oripast == [], "List should be empty."

        # Test sorted and origpastuids. The uid '6' is not in the current uids,
        # and should be removed from the new origpastuids. And '3' should be
        # removed from the uids (it has been processed in the past).
        ret, oripast = sa.get_formated_uids(uids=[u'1 2 4 3'],
                                            origpastuids=[3, 1, 6],
                                            partialrun=2)
        print(oripast)
        print(ret)
        assert ret == [u'4', u'2']
        assert oripast == [3, 1], "Unexpected new orig past uids."
コード例 #4
0
ファイル: test_isbg.py プロジェクト: xpunkt/isbg
 def test_set_filename(self):
     """Test set_filename."""
     sbg = isbg.ISBG()
     filename = isbg.ISBG.set_filename(sbg.imapsets, "track")
     assert os.path.dirname(filename) != ""
     assert os.path.basename(filename) != ""
     assert os.path.basename(filename).startswith("track")
     filename = isbg.ISBG.set_filename(sbg.imapsets, "password")
     assert os.path.dirname(filename) != ""
     assert os.path.basename(filename) != ""
     assert os.path.basename(filename).startswith(".isbg-")
コード例 #5
0
ファイル: test_spamproc.py プロジェクト: l2dy/isbg
    def test_process_spam(self):
        """Test _process_spam."""
        sbg = isbg.ISBG()
        sa = spamproc.SpamAssassin.create_from_isbg(sbg)

        # OSError required when it's run without spamassassin (travis-cl)
        with pytest.raises((AttributeError, OSError, MessageError)):
            sa._process_spam(1, u"3/10\n", "", [], 0, "")
            pytest.fail("Should rise error, IMAP not created.")

        sa.noreport = True
        sa.deletehigherthan = 2
        sa._process_spam(1, u"3/10\n", "", [], 0, "")
コード例 #6
0
ファイル: test_isbg.py プロジェクト: xpunkt/isbg
 def test_removelock(self):
     """Test removelock."""
     sbg = isbg.ISBG()
     sbg.removelock()
     assert os.path.exists(sbg.lockfilename) is False, \
         "File should not exist."
     lockfile = open(sbg.lockfilename, 'w')
     lockfile.write(repr(os.getpid()))
     lockfile.close()
     assert os.path.exists(sbg.lockfilename), "File should exist."
     sbg.removelock()
     assert os.path.exists(sbg.lockfilename) is False, \
         "File should not exist."
コード例 #7
0
def main():
    """Run when this module is called from the command line.

    When the main function ends, it throw a sys.exit with 0 if it has end ok
    or one of the :py:data:`isbg.isbg.__exitcodes__`
    """
    sbg = isbg.ISBG()
    try:
        if parse_args(sbg) == 1:  # usage option
            sys.exit(0)
        return sbg.do_isbg()  # return the exit code.
    except isbg.ISBGError as err:
        sys.stderr.write(err.message)
        sys.stderr.write("\nUse --help to see valid options and arguments\n")
        if err.exitcode == -1:
            raise
        sys.exit(err.exitcode)
コード例 #8
0
ファイル: test_spamproc.py プロジェクト: l2dy/isbg
 def test_create_from_isbg(self):
     """Test create_from_isbg."""
     sbg = isbg.ISBG()
     sa = spamproc.SpamAssassin.create_from_isbg(sbg)
     assert sa.imap is None  # pylint: disable=no-member
     assert sa.logger is not None
コード例 #9
0
ファイル: test___main__.py プロジェクト: rsmuc/isbg
def test_parse_args():
    """Test parse_args."""
    # Remove pytest options:
    orig_args = sys.argv[:]

    # Parse command line (it should work):
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--flag", "--noninteractive"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    __main__.parse_args(sbg)
    assert sbg.imapsets.host == "localhost"
    assert sbg.imapsets.user == "anonymous"
    assert sbg.imapsets.passwd == "none"

    # Parse with unknown option
    del sys.argv[1:]
    for op in ["--foo"]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    with pytest.raises(isbg.ISBGError,
                       match="[options]",
                       message="It should rise a docopt SystemExit"):
        __main__.parse_args(sbg)

    # Parse with bogus deletehigherthan
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--deletehigherthan", "0"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    with pytest.raises(isbg.ISBGError,
                       match="too small",
                       message="It should rise a too small ISBGError"):
        __main__.parse_args(sbg)

    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--deletehigherthan", "foo"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    with pytest.raises(isbg.ISBGError,
                       match="Unrecognized score",
                       message=("It should rise a unrecognized score" +
                                "ISBGError")):
        __main__.parse_args(sbg)

    # Parse with ok deletehigherthan
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--deletehigherthan", "8"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    __main__.parse_args(sbg)
    assert sbg.deletehigherthan == 8.0

    # Parse with bogus maxsize
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--maxsize", "0"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    with pytest.raises(isbg.ISBGError,
                       match="too small",
                       message="It should rise a too small ISBGError"):
        __main__.parse_args(sbg)

    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--maxsize", "foo"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    with pytest.raises(isbg.ISBGError,
                       match="Unrecognised size",
                       message=("It should rise a Unrecognised size" +
                                "ISBGError")):
        __main__.parse_args(sbg)

    # Parse with ok maxsize
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--maxsize", "12000"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    __main__.parse_args(sbg)
    assert sbg.maxsize == 12000

    # Parse with bogus partialrun
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--partialrun", "-10"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    with pytest.raises(isbg.ISBGError,
                       match="equal to 0 or higher",
                       message=("It should rise a equal to 0 or higher " +
                                "ISBGError")):
        __main__.parse_args(sbg)

    # Parse with 0 partialrun
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--partialrun", "0"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    __main__.parse_args(sbg)
    assert sbg.partialrun is None

    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--dryrun", "--partialrun", "foo"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    with pytest.raises(isbg.ISBGError,
                       match="must be a integer",
                       message=("It should rise a invalid literal " +
                                "ValueError")):
        __main__.parse_args(sbg)

    # Parse with ok partialrun and verbose and nossl
    del sys.argv[1:]
    for op in [
            "--imaphost", "localhost", "--imapuser", "anonymous",
            "--imappasswd", "none", "--verbose", "--partialrun", "10",
            "--nossl"
    ]:
        sys.argv.append(op)
    sbg = isbg.ISBG()
    __main__.parse_args(sbg)
    assert sbg.partialrun == 10

    # Restore pytest options:
    del sys.argv[1:]
    sys.argv = orig_args[:]