Esempio n. 1
0
    def testNotFound(self):
        """Tests when a URL in the crawl is not found."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', (
                    'Hello world! <a href="/missing">x</a>')
            elif path == '/missing':
                return 404, 'text/plain', 'Nope'

        site_diff.real_main(
            start_url='http://%s:%d/' % test.server_address,
            ignore_prefixes=['/ignore'],
            output_dir=self.output_dir,
            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))

        self.assertEquals(
            ['/'],
            self.output_readlines('url_paths.txt'))

        self.fail()
Esempio n. 2
0
    def testCrawler(self):
        """Tests that the crawler behaves well.

        Specifically:
            - Finds new links in HTML data
            - Avoids non-HTML pages
            - Respects ignore patterns specified on flags
        """
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', (
                    'Hello world! <a href="/stuff">x</a> '
                    '<a href="/ignore">y</a>')
            elif path == '/stuff':
                return 200, 'text/html', 'Stuff page <a href="/avoid">x</a>'
            elif path == '/avoid':
                return 200, 'text/plain', 'Ignore me!'

        site_diff.real_main(start_url='http://%s:%d/' % test.server_address,
                            ignore_prefixes=['/ignore'],
                            output_dir=self.output_dir,
                            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))
        self.assertFalse(exists(join(self.output_dir, '_ignore_run.log')))
        self.assertFalse(exists(join(self.output_dir, '_ignore_run.png')))
        self.assertFalse(exists(join(self.output_dir, '_ignore_config.js')))

        self.assertEquals(['/', '/stuff'],
                          self.output_readlines('url_paths.txt'))
Esempio n. 3
0
    def testNoDifferences(self):
        """Tests crawling the site end-to-end."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world!'

        site_diff.real_main(start_url='http://%s:%d/' % test.server_address,
                            output_dir=self.reference_dir,
                            coordinator=self.coordinator)

        self.coordinator = workers.get_coordinator()
        site_diff.real_main(start_url='http://%s:%d/' % test.server_address,
                            output_dir=self.output_dir,
                            reference_dir=self.reference_dir,
                            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.reference_dir, '__run.log')))
        self.assertTrue(exists(join(self.reference_dir, '__run.png')))
        self.assertTrue(exists(join(self.reference_dir, '__config.js')))
        self.assertTrue(exists(join(self.reference_dir, 'url_paths.txt')))

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__ref.log')))
        self.assertTrue(exists(join(self.output_dir, '__ref.png')))
        self.assertFalse(exists(join(self.output_dir,
                                     '__diff.png')))  # No diff
        self.assertTrue(exists(join(self.output_dir, '__diff.log')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))
Esempio n. 4
0
    def testNoDifferences(self):
        """Tests crawling the site end-to-end."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world!'

        site_diff.real_main(
            start_url='http://%s:%d/' % test.server_address,
            output_dir=self.reference_dir,
            coordinator=self.coordinator)

        self.coordinator = workers.get_coordinator()
        site_diff.real_main(
            start_url='http://%s:%d/' % test.server_address,
            output_dir=self.output_dir,
            reference_dir=self.reference_dir,
            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.reference_dir, '__run.log')))
        self.assertTrue(exists(join(self.reference_dir, '__run.png')))
        self.assertTrue(exists(join(self.reference_dir, '__config.js')))
        self.assertTrue(exists(join(self.reference_dir, 'url_paths.txt')))

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__ref.log')))
        self.assertTrue(exists(join(self.output_dir, '__ref.png')))
        self.assertFalse(exists(join(self.output_dir, '__diff.png'))) # No diff
        self.assertTrue(exists(join(self.output_dir, '__diff.log')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))
Esempio n. 5
0
    def testFirstSnapshot(self):
        """Tests taking the very first snapshot."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world!'

        site_diff.real_main(start_url='http://%s:%d/' % test.server_address,
                            output_dir=self.output_dir,
                            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))

        self.assertEquals(['/'], self.output_readlines('url_paths.txt'))
Esempio n. 6
0
    def testCrawler(self):
        """Tests that the crawler behaves well.

        Specifically:
            - Finds new links in HTML data
            - Avoids non-HTML pages
            - Respects ignore patterns specified on flags
            - Properly handles 404s
        """

        @webserver
        def test(path):
            if path == "/":
                return (
                    200,
                    "text/html",
                    (
                        'Hello world! <a href="/stuff">x</a> '
                        '<a href="/ignore">y</a> and also '
                        '<a href="/missing">z</a>'
                    ),
                )
            elif path == "/stuff":
                return 200, "text/html", 'Stuff page <a href="/avoid">x</a>'
            elif path == "/missing":
                return 404, "text/plain", "Nope"
            elif path == "/avoid":
                return 200, "text/plain", "Ignore me!"

        site_diff.real_main(
            start_url=test.server_prefix + "/",
            upload_build_id=self.build_id,
            upload_release_name=self.release_name,
            ignore_prefixes=["/ignore"],
        )

        release = wait_for_release(self.build_id, self.release_name)
        run_list = models.Run.query.all()
        found = set(run.name for run in run_list)

        expected = set(["/", "/stuff"])
        self.assertEquals(expected, found)

        test.shutdown()
Esempio n. 7
0
    def testFirstSnapshot(self):
        """Tests taking the very first snapshot."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world!'

        site_diff.real_main(
            start_url='http://%s:%d/' % test.server_address,
            output_dir=self.output_dir,
            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))

        self.assertEquals(
            ['/'],
            self.output_readlines('url_paths.txt'))
Esempio n. 8
0
    def testOneDifference(self):
        """Tests when there is one found difference."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world!'

        site_diff.real_main(
            start_url='http://%s:%d/' % test.server_address,
            output_dir=self.reference_dir,
            coordinator=self.coordinator)
        test.shutdown()

        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world a little different!'

        self.coordinator = workers.get_coordinator()
        site_diff.real_main(
            start_url='http://%s:%d/' % test.server_address,
            output_dir=self.output_dir,
            reference_dir=self.reference_dir,
            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.reference_dir, '__run.log')))
        self.assertTrue(exists(join(self.reference_dir, '__run.png')))
        self.assertTrue(exists(join(self.reference_dir, '__config.js')))
        self.assertTrue(exists(join(self.reference_dir, 'url_paths.txt')))

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__ref.log')))
        self.assertTrue(exists(join(self.output_dir, '__ref.png')))
        self.assertTrue(exists(join(self.output_dir, '__diff.png'))) # Diff!!
        self.assertTrue(exists(join(self.output_dir, '__diff.log')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))
Esempio n. 9
0
    def testOneDifference(self):
        """Tests when there is one found difference."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world!'

        site_diff.real_main(start_url='http://%s:%d/' % test.server_address,
                            output_dir=self.reference_dir,
                            coordinator=self.coordinator)
        test.shutdown()

        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', 'Hello world a little different!'

        self.coordinator = workers.get_coordinator()
        site_diff.real_main(start_url='http://%s:%d/' % test.server_address,
                            output_dir=self.output_dir,
                            reference_dir=self.reference_dir,
                            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.reference_dir, '__run.log')))
        self.assertTrue(exists(join(self.reference_dir, '__run.png')))
        self.assertTrue(exists(join(self.reference_dir, '__config.js')))
        self.assertTrue(exists(join(self.reference_dir, 'url_paths.txt')))

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__ref.log')))
        self.assertTrue(exists(join(self.output_dir, '__ref.png')))
        self.assertTrue(exists(join(self.output_dir, '__diff.png')))  # Diff!!
        self.assertTrue(exists(join(self.output_dir, '__diff.log')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))
Esempio n. 10
0
    def testCrawler(self):
        """Tests that the crawler behaves well.

        Specifically:
            - Finds new links in HTML data
            - Avoids non-HTML pages
            - Respects ignore patterns specified on flags
            - Properly handles 404s
        """
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', (
                    'Hello world! <a href="/stuff">x</a> '
                    '<a href="/ignore">y</a> and also '
                    '<a href="/missing">z</a>')
            elif path == '/stuff':
                return 200, 'text/html', 'Stuff page <a href="/avoid">x</a>'
            elif path == '/missing':
                return 404, 'text/plain', 'Nope'
            elif path == '/avoid':
                return 200, 'text/plain', 'Ignore me!'

        site_diff.real_main(
            start_url=test.server_prefix + '/',
            upload_build_id=self.build_id,
            upload_release_name=self.release_name,
            ignore_prefixes=['/ignore'])

        release = wait_for_release(self.build_id, self.release_name)
        run_list = models.Run.query.all()
        found = set(run.name for run in run_list)

        expected = set(['/', '/stuff'])
        self.assertEquals(expected, found)

        test.shutdown()
Esempio n. 11
0
    def testCrawler(self):
        """Tests that the crawler behaves well.

        Specifically:
            - Finds new links in HTML data
            - Avoids non-HTML pages
            - Respects ignore patterns specified on flags
        """
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', (
                    'Hello world! <a href="/stuff">x</a> '
                    '<a href="/ignore">y</a>')
            elif path == '/stuff':
                return 200, 'text/html', 'Stuff page <a href="/avoid">x</a>'
            elif path == '/avoid':
                return 200, 'text/plain', 'Ignore me!'

        site_diff.real_main(
            start_url='http://%s:%d/' % test.server_address,
            ignore_prefixes=['/ignore'],
            output_dir=self.output_dir,
            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))
        self.assertFalse(exists(join(self.output_dir, '_ignore_run.log')))
        self.assertFalse(exists(join(self.output_dir, '_ignore_run.png')))
        self.assertFalse(exists(join(self.output_dir, '_ignore_config.js')))

        self.assertEquals(
            ['/', '/stuff'],
            self.output_readlines('url_paths.txt'))
Esempio n. 12
0
    def testNotFound(self):
        """Tests when a URL in the crawl is not found."""
        @webserver
        def test(path):
            if path == '/':
                return 200, 'text/html', (
                    'Hello world! <a href="/missing">x</a>')
            elif path == '/missing':
                return 404, 'text/plain', 'Nope'

        site_diff.real_main(start_url='http://%s:%d/' % test.server_address,
                            ignore_prefixes=['/ignore'],
                            output_dir=self.output_dir,
                            coordinator=self.coordinator)
        test.shutdown()

        self.assertTrue(exists(join(self.output_dir, '__run.log')))
        self.assertTrue(exists(join(self.output_dir, '__run.png')))
        self.assertTrue(exists(join(self.output_dir, '__config.js')))
        self.assertTrue(exists(join(self.output_dir, 'url_paths.txt')))

        self.assertEquals(['/'], self.output_readlines('url_paths.txt'))

        self.fail()
Esempio n. 13
0
    def testEndToEnd(self):
        """Tests doing a site diff from end to end."""
        # Create the first release.
        @webserver
        def test1(path):
            if path == '/':
                return 200, 'text/html', '<h1>Hello world!</h1>'

        logging.info('Creating first release')
        site_diff.real_main(
            start_url=test1.server_prefix + '/',
            upload_build_id=self.build_id,
            upload_release_name=self.release_name)

        logging.info('Waiting for first release')
        release = wait_for_release(self.build_id, self.release_name)

        # Verify the first screenshot worked and its status can load.
        logging.info('Checking first screenshot')
        resp = self.client.get(
            '/release?id=%d&name=%s&number=%d' % (
                self.build_id, release.name, release.number),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)
        self.assertIn('Nothing to test', resp.data)
        self.assertIn('Diff not required', resp.data)

        # Mark the release as good.
        logging.info('Marking first release as good')
        resp = self.client.post(
            '/release',
            data=dict(
                id=self.build_id,
                name=release.name,
                number=release.number,
                good=True),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)

        # Create the second release.
        @webserver
        def test2(path):
            if path == '/':
                return 200, 'text/html', '<h1>Hello again!</h1>'

        logging.info('Creating second release')
        site_diff.real_main(
            start_url=test2.server_prefix + '/',
            upload_build_id=self.build_id,
            upload_release_name=self.release_name)

        logging.info('Waiting for second release')
        release = wait_for_release(self.build_id, self.release_name)

        # Verify a diff was computed and found.
        logging.info('Checking second screenshot has a diff')
        resp = self.client.get(
            '/release?id=%d&name=%s&number=%d' % (
                self.build_id, release.name, release.number),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)
        self.assertIn('1 tested', resp.data)
        self.assertIn('1 failure', resp.data)
        self.assertIn('Diff found', resp.data)

        # Create the third release.
        logging.info('Creating third release')
        site_diff.real_main(
            start_url=test1.server_prefix + '/',
            upload_build_id=self.build_id,
            upload_release_name=self.release_name)

        logging.info('Waiting for third release')
        release = wait_for_release(self.build_id, self.release_name)
        test1.shutdown()
        test2.shutdown()

        # No diff found.
        logging.info('Checking third screenshot has no diff')
        resp = self.client.get(
            '/release?id=%d&name=%s&number=%d' % (
                self.build_id, release.name, release.number),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)
        self.assertIn('1 tested', resp.data)
        self.assertIn('All passing', resp.data)
Esempio n. 14
0
    def testEndToEnd(self):
        """Tests doing a site diff from end to end."""
        # Create the first release.
        @webserver
        def test1(path):
            if path == "/":
                return 200, "text/html", "<h1>Hello world!</h1>"

        site_diff.real_main(
            start_url=test1.server_prefix + "/", upload_build_id=self.build_id, upload_release_name=self.release_name
        )

        release = wait_for_release(self.build_id, self.release_name)

        # Verify the first screenshot worked and its status can load.
        resp = self.client.get(
            "/release?id=%d&name=%s&number=%d" % (self.build_id, release.name, release.number), follow_redirects=True
        )
        self.assertEquals("200 OK", resp.status)
        self.assertIn("Nothing to test", resp.data)
        self.assertIn("Diff not required", resp.data)

        # Mark the release as good.
        resp = self.client.post(
            "/release",
            data=dict(id=self.build_id, name=release.name, number=release.number, good=True),
            follow_redirects=True,
        )
        self.assertEquals("200 OK", resp.status)

        # Create the second release.
        @webserver
        def test2(path):
            if path == "/":
                return 200, "text/html", "<h1>Hello again!</h1>"

        site_diff.real_main(
            start_url=test2.server_prefix + "/", upload_build_id=self.build_id, upload_release_name=self.release_name
        )

        release = wait_for_release(self.build_id, self.release_name)

        # Verify a diff was computed and found.
        resp = self.client.get(
            "/release?id=%d&name=%s&number=%d" % (self.build_id, release.name, release.number), follow_redirects=True
        )
        self.assertEquals("200 OK", resp.status)
        self.assertIn("1 tested", resp.data)
        self.assertIn("1 failure", resp.data)
        self.assertIn("Diff found", resp.data)

        # Create the second release.
        site_diff.real_main(
            start_url=test1.server_prefix + "/", upload_build_id=self.build_id, upload_release_name=self.release_name
        )

        release = wait_for_release(self.build_id, self.release_name)
        test1.shutdown()
        test2.shutdown()

        # No diff found.
        resp = self.client.get(
            "/release?id=%d&name=%s&number=%d" % (self.build_id, release.name, release.number), follow_redirects=True
        )
        self.assertEquals("200 OK", resp.status)
        self.assertIn("1 tested", resp.data)
        self.assertIn("All passing", resp.data)
Esempio n. 15
0
    def testEndToEnd(self):
        """Tests doing a site diff from end to end."""
        # Create the first release.
        @webserver
        def test1(path):
            if path == '/':
                return 200, 'text/html', '<h1>Hello world!</h1>'

        site_diff.real_main(
            start_url=test1.server_prefix + '/',
            upload_build_id=self.build_id,
            upload_release_name=self.release_name)

        release = wait_for_release(self.build_id, self.release_name)

        # Verify the first screenshot worked and its status can load.
        resp = self.client.get(
            '/release?id=%d&name=%s&number=%d' % (
                self.build_id, release.name, release.number),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)
        self.assertIn('Nothing to test', resp.data)
        self.assertIn('Diff not required', resp.data)

        # Mark the release as good.
        resp = self.client.post(
            '/release',
            data=dict(
                id=self.build_id,
                name=release.name,
                number=release.number,
                good=True),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)

        # Create the second release.
        @webserver
        def test2(path):
            if path == '/':
                return 200, 'text/html', '<h1>Hello again!</h1>'

        site_diff.real_main(
            start_url=test2.server_prefix + '/',
            upload_build_id=self.build_id,
            upload_release_name=self.release_name)

        release = wait_for_release(self.build_id, self.release_name)

        # Verify a diff was computed and found.
        resp = self.client.get(
            '/release?id=%d&name=%s&number=%d' % (
                self.build_id, release.name, release.number),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)
        self.assertIn('1 tested', resp.data)
        self.assertIn('1 failure', resp.data)
        self.assertIn('Diff found', resp.data)

        # Create the second release.
        site_diff.real_main(
            start_url=test1.server_prefix + '/',
            upload_build_id=self.build_id,
            upload_release_name=self.release_name)

        release = wait_for_release(self.build_id, self.release_name)
        test1.shutdown()
        test2.shutdown()

        # No diff found.
        resp = self.client.get(
            '/release?id=%d&name=%s&number=%d' % (
                self.build_id, release.name, release.number),
            follow_redirects=True)
        self.assertEquals('200 OK', resp.status)
        self.assertIn('1 tested', resp.data)
        self.assertIn('All passing', resp.data)