Exemplo n.º 1
0
 def setUp(self):
     """Set up."""
     self.pi = ParseaImagenes(test=True)
     self.pi.test = False
Exemplo n.º 2
0
class SearcherTestCase(unittest.TestCase):
    """Tests for the Searcher."""

    def setUp(self):
        """Set up."""
        self.pi = ParseaImagenes(test=True)
        self.pi.test = False

    def _check(self, url, should_web, should_dsk):
        """Do proper checking."""
        m = FakeSearch(url)
        r = []
        self.pi._reemplaza(r, m)
        dsk, web = r[0]

        self.assertEqual(web, should_web)
        self.assertEqual(dsk, should_dsk)

    def test_reemplazar_wikipedia_commons_5parts(self):
        """Reemplazar wikipedia commons with 5 parts."""
        url = (
            "//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/"
            "Coat_of_arms_of_the_Netherlands_-_02.svg/"
            "250px-Coat_of_arms_of_the_Netherlands_-_02.svg.png"
        )
        should_web = (
            "http://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/"
            "Coat_of_arms_of_the_Netherlands_-_02.svg/"
            "250px-Coat_of_arms_of_the_Netherlands_-_02.svg.png"
        )
        should_dsk = (
            "commons/thumb/a/aa/"
            "250px-Coat_of_arms_of_the_Netherlands_-_02.svg.png"
        )
        self._check(url, should_web, should_dsk)

    def test_reemplazar_wikipedia_commons_1parts(self):
        """Reemplazar wikipedia commons with 1 parts."""
        url = (
            "//upload.wikimedia.org/wikipedia/commons/8/88/"
            "Marshall_Islands_coa.jpg"
        )
        should_web = (
            "http://upload.wikimedia.org/wikipedia/commons/8/88/"
            "Marshall_Islands_coa.jpg"
        )
        should_dsk = "commons/8/88/Marshall_Islands_coa.jpg"
        self._check(url, should_web, should_dsk)

    def test_reemplazar_bits(self):
        """Reemplazar bits."""
        url = "//bits.wikimedia.org/skins-1.18/common/images/magnify-clip.png"
        should_web = (
            "http://bits.wikimedia.org/"
            "skins-1.18/common/images/magnify-clip.png"
        )
        should_dsk = "magnify-clip.png"
        self._check(url, should_web, should_dsk)

    def test_reemplazar_timeline(self):
        """Reemplazar timeline."""
        url = (
            "//upload.wikimedia.org/wikipedia/es/"
            "timeline/cc707d3b957628b5e432d7242096abc5.png"
        )
        should_web = (
            "http://upload.wikimedia.org/wikipedia/es/"
            "timeline/cc707d3b957628b5e432d7242096abc5.png"
        )
        should_dsk = "timeline/cc707d3b957628b5e432d7242096abc5.png"
        self._check(url, should_web, should_dsk)

    def test_reemplazar_math(self):
        """Reemplazar math."""
        url = (
            "//upload.wikimedia.org/wikipedia/es/"
            "math/6/7/e/67ed4566dba0caae24ec4cf25133f200.png"
        )
        should_web = (
            "http://upload.wikimedia.org/wikipedia/es/"
            "math/6/7/e/67ed4566dba0caae24ec4cf25133f200.png"
        )
        should_dsk = "math/6/7/e/67ed4566dba0caae24ec4cf25133f200.png"
        self._check(url, should_web, should_dsk)