1. Blue
  2. django-spotnet

Source

django-spotnet / spotnet / tests / selection.py

try:
    from django.utils import unittest
except ImportError:
    try:
        import unittest2 as unittest
    except ImportError:
        import unittest

from spotnet.connection import TITLE_SELECTION_REGEXP, Connection


class TitleSelectionTest(unittest.TestCase):
    def match(self, title):
        return TITLE_SELECTION_REGEXP.match(title) is not None

    def test_title_selection_regexp(self):
        # not spotnet posts, positive matches for the regexp
        positives = [
            # extensive
            '(4954/5369) "VA-CD_Club_Promo_Only_May_Part_10-2011-BFHMP3.rar" - 371,87 MB - yEnc (1/1)',

            # without title
            '"VA-CD_Club_Promo_Only_May_Part_10-2011-BFHMP3.rar" - 371,87 MB - yEnc (1/1)',

            # no space after title
            '(4954/5369)"VA-CD_Club_Promo_Only_May_Part_10-2011-BFHMP3.rar" - 371,87 MB - yEnc (1/1)',

            # no filesize or index, not both w/o hyphen
            '(4954/5369) "VA-CD_Club_Promo_Only_May_Part_10-2011-BFHMP3.rar" yEnc (1/1)',
            '(4954/5369) "VA-CD_Club_Promo_Only_May_Part_10-2011-BFHMP3.rar" - 371,87 MB - yEnc',
            '(4954/5369) "VA-CD_Club_Promo_Only_May_Part_10-2011-BFHMP3.rar" yEnc',

            # simpler versions
            'blaat blaat "blaat blaat" - 23.2 MB - yEnc (2/45)',
            'blaat blaat "blaat blaat" yEnc (2/45)',
            'blaat blaat "blaat blaat" yEnc (233/425)',
            'blaat blaat "blaat blaat" yEnc',
            '"blaat blaat" yEnc (233/425)',
            'blaat blaat"blaat blaat" yEnc (2/45)',
        ]

        # spotnet posts, negative matches for the regexp
        negatives = [
            'other title "with quotation"',
            'something with yEnc to test',
            'something with (2/4)',
            'Paul (2011) | masterew',
        ]

	conn = Connection(connect=False)
	messageid = '<blaat@free.pt>'  # a typical spotnet post messageid

        for m in positives:
            self.assertTrue(self.match(m), "title selection matches positive %r" % m)
            self.assertFalse(conn.is_spotnet_post(messageid, m), "title %r is no spotnet post" % m)
        for m in negatives:
            self.assertFalse(self.match(m), "title selection does not match negative %r" % m)
            self.assertTrue(conn.is_spotnet_post(messageid, m), "title %r is spotnet post" % m)