Exemplo n.º 1
0
 def functional_test(self, queries, url):
     with self.assertNumQueries(queries):
         result = test.client.Client().get(
             url,
             HTTP_ACCEPT='application/json; indent=4',
         )
     Response.for_test(self).assertNoDiff(result)
Exemplo n.º 2
0
    def functional_test(self, queries, url):
        client = test.client.Client()

        # First query to setup session
        client.get(url)

        with self.assertNumQueries(queries):
            result = client.get(url)
        Response.for_test(self).assertNoDiff(result)
    def functional_test(self, queries, url):
        client = test.client.Client()

        # First query to setup session
        client.get(url)

        with self.assertNumQueries(queries):
            result = client.get(url)
        Response.for_test(self).assertNoDiff(result)
    def test_path(self):
        expected = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'response_fixtures',
            'TestResponseDiff.test_path'
        )

        assert Response.for_test(self).path == expected
Exemplo n.º 5
0
def test_mrsrequest_cancel_get(name, url, status, client):
    mrsrequest = mrsrequest_factory(status)
    resp = client.get(cancel_url(mrsrequest, url))
    Response(os.path.join(
        os.path.dirname(__file__),
        'response_fixtures',
        '_'.join(['cancel', name]),
    )).assertNoDiff(resp, '.mrs-std-page--wrapper')
    def sorting_test(self, num_queries, field='', dir=''):
        url = '%s?sort_by=%s&sort_dir=%s' % (self.url, field, dir)

        # Cancel out one-time queries (session)
        self.client.get('%s&paginate_by=12&active_only=1' % url)

        with self.assertNumQueries(num_queries):
            self.response = self.client.get(self.url)

        expected = Response.for_test(self)
        expected.assertNoDiff(self.response)
Exemplo n.º 7
0
    def test_recursion(self):
        subject = Response.for_test(self, url='/')

        # Ensure we're clean
        if os.path.exists(os.path.dirname(subject.content_path)):
            # pragma: no cover
            shutil.rmtree(os.path.dirname(subject.content_path))

        client = mock.Mock()
        client.get.return_value = http.HttpResponse(content='"/a" "/b"')

        result = self.responsediff_website_crawl(client=client)
        assert result[0] == ['/', '/a', '/b']
    def filter_test(self, num_queries, search='', country='', chamber='',
                    group=''):
        url = '%s?search=%s&country=%s&chamber=%s&group=%s' % (self.url,
            search, country, chamber, group)

        # Cancel out one-time queries (session)
        self.client.get('%s&paginate_by=12&active_only=1' % url)

        with self.assertNumQueries(num_queries):
            self.response = self.client.get(url)

        expected = Response.for_test(self)
        expected.assertNoDiff(self.response)
Exemplo n.º 9
0
    def test_recursion(self):
        subject = Response.for_test(self, url='/')

        # Ensure we're clean
        if os.path.exists(os.path.dirname(subject.content_path)):
            # pragma: no cover
            shutil.rmtree(os.path.dirname(subject.content_path))

        client = mock.Mock()
        client.get.return_value = http.HttpResponse(
            content='href="/a" href="/b"')

        result = self.responsediff_website_crawl(client=client)
        assert result[0] == ['/', '/a', '/b']
    def functional_test(self, page, paginate_by, display, search=''):
        url = '%s?page=%s&search=%s' % (self.url, page, search)

        # Cancel out one-time queries (session)
        self.client.get('%s&paginate_by=%s&display=%s' %
            (url, paginate_by, display))

        with self.assertNumQueries(3):
            """
            - A count for pagination
            - One query for representative + score
            - One query for mandates (including country + main_mandate)
            """
            self.response = self.client.get(url)

        expected = Response.for_test(self)
        expected.assertNoDiff(self.response)
Exemplo n.º 11
0
    def test_assertWebsiteSame(self):  # noqa
        subject = Response.for_test(self, url='/')

        # Ensure we're clean
        if os.path.exists(os.path.dirname(subject.content_path)):
            # pragma: no cover
            shutil.rmtree(os.path.dirname(subject.content_path))

        # First run should fail
        with self.assertRaises(DiffsFound):
            self.assertWebsiteSame()

        # Second run should pass
        self.assertWebsiteSame()

        # Let's break it
        with open(subject.content_path, 'w') as f:
            f.write('is this magic or actual software test engineering ?')

        # Should be broken
        with self.assertRaises(DiffsFound):
            self.assertWebsiteSame()
Exemplo n.º 12
0
    def test_assertWebsiteSame(self):  # noqa
        subject = Response.for_test(self, url='/')

        # Ensure we're clean
        if os.path.exists(os.path.dirname(subject.content_path)):
            # pragma: no cover
            shutil.rmtree(os.path.dirname(subject.content_path))

        # First run should fail
        with self.assertRaises(DiffsFound):
            self.assertWebsiteSame()

        # Second run should pass
        self.assertWebsiteSame()

        # Let's break it
        with open(subject.content_path, 'w') as f:
            f.write('is this magic or actual software test engineering ?')

        # Should be broken
        with self.assertRaises(DiffsFound):
            self.assertWebsiteSame()
Exemplo n.º 13
0
    def test_websiteTest(self):  # noqa
        path = Response.for_test(self).path
        if os.path.exists(path):  # pragma: no cover
            # Only makes sense when you're running the tests over and over
            # locally, makes no sense on single-usage containers like travis,
            # hence "no cover" above.
            shutil.rmtree(path)

        fixtures = [
            '/notrailing',
            '/notrailing?foo=bar',
            '/trailing/',
            '/trailing/?foo=bar',
        ]

        client = self.get_client(fixtures)
        covered, diffs, created = self.responsediff_website_crawl(client=client)

        expected_covered = ['/'] + fixtures
        assert covered == expected_covered

        expected_created = [
            'MixinTest.test_websiteTest/content',
            'MixinTest.test_websiteTest/metadata',
            'MixinTest.test_websiteTest/trailing/metadata',
            'MixinTest.test_websiteTest/trailing/content',
            'MixinTest.test_websiteTest/trailing/?foo=bar.metadata',
            'MixinTest.test_websiteTest/trailing/?foo=bar.content',
            'MixinTest.test_websiteTest/notrailing.content',
            'MixinTest.test_websiteTest/notrailing.metadata',
            'MixinTest.test_websiteTest/notrailing?foo=bar.metadata',
            'MixinTest.test_websiteTest/notrailing?foo=bar.content',
        ]
        result_created = [
            re.sub(
                '.*MixinTest.test_websiteTest',
                'MixinTest.test_websiteTest',
                c
            ) for c in created
        ]
        assert sorted(result_created) == sorted(expected_created)

        for path in created.keys():
            if 'MixinTest.test_websiteTest/content' in path:
                break

        with open(path, 'w') as f:
            f.write('fail please')

        covered, diffs, created = self.responsediff_website_crawl(
            client=self.get_client(fixtures)
        )

        expected = six.b('''
@@ -1 +1,4 @@
-fail please
\ No newline at end of file
+"/notrailing"
+"/notrailing?foo=bar"
+"/trailing/"
+"/trailing/?foo=bar"
\ No newline at end of file
        ''')

        assert list(diffs.values())[0].strip() == expected.strip()
    def test_story(self):
        result = test.Client().get('/admin/')
        expected = Response.for_test(self)

        if os.path.exists(expected.content_path):  # pragma: no cover
            # Only makes sense when you're running the tests over and over
            # locally, makes no sense on single-usage containers like travis,
            # hence "no cover" above.
            os.unlink(expected.content_path)

        if os.path.exists(expected.metadata_path):  # pragma: no cover
            os.unlink(expected.metadata_path)

        with self.assertRaises(DiffsFound) as raises_result:
            expected.assertNoDiff(result)

        msg = (
            raises_result.exception.message
            if six.PY2 else raises_result.exception.args[0]
        )

        assert expected.content_path in msg
        assert expected.metadata_path in msg

        # should have been created
        assert os.path.exists(expected.content_path)

        # should pass now
        expected.assertNoDiff(result)

        with open(expected.content_path, 'w') as f:
            f.write('bla')

        with self.assertRaises(DiffsFound) as e:
            expected.assertNoDiff(result)

        expected_diff = '''
@@ -1 +1 @@
-bla
\ No newline at end of file
+<h1>Not Found</h1><p>The requested URL /admin/ was not found on this server.</p>
\ No newline at end of file
'''.lstrip()

        diff = e.exception.message if six.PY2 else e.exception.args[0]
        result_diff = '\n'.join(diff.split('\n')[2:])
        assert result_diff == expected_diff

        # Let's fix it and test status code now
        with open(expected.content_path, 'wb') as f:
            f.write(result.content)

        # Let's mess with the status code now
        with open(expected.metadata_path, 'w') as f:
            json.dump(
                {
                    'status_code': 418,  # RFC 2324 LOL
                },
                f,
                indent=4
            )

        with self.assertRaises(DiffsFound) as e:
            expected.assertNoDiff(result)
Exemplo n.º 15
0
    def test_story(self):
        result = test.Client().get('/admin/')
        expected = Response.for_test(self)

        if os.path.exists(expected.content_path):  # pragma: no cover
            # Only makes sense when you're running the tests over and over
            # locally, makes no sense on single-usage containers like travis,
            # hence "no cover" above.
            os.unlink(expected.content_path)

        if os.path.exists(expected.metadata_path):  # pragma: no cover
            os.unlink(expected.metadata_path)

        with self.assertRaises(DiffsFound) as raises_result:
            expected.assertNoDiff(result)

        msg = (raises_result.exception.message
               if six.PY2 else raises_result.exception.args[0])

        assert expected.content_path in msg
        assert expected.metadata_path in msg

        # should have been created
        assert os.path.exists(expected.content_path)

        # should pass now
        expected.assertNoDiff(result)

        with open(expected.content_path, 'w') as f:
            f.write('bla')

        with self.assertRaises(DiffsFound) as e:
            expected.assertNoDiff(result)

        expected_diff = '''
@@ -1 +1 @@
-bla
\ No newline at end of file
+<h1>Not Found</h1><p>The requested URL /admin/ was not found on this server.</p>
\ No newline at end of file
'''.lstrip()

        diff = e.exception.message if six.PY2 else e.exception.args[0]
        result_diff = '\n'.join(diff.split('\n')[2:])
        assert result_diff == expected_diff

        # Let's fix it and test status code now
        with open(expected.content_path, 'wb') as f:
            f.write(result.content)

        # Let's mess with the status code now
        with open(expected.metadata_path, 'w') as f:
            json.dump(
                {
                    'status_code': 418,  # RFC 2324 LOL
                },
                f,
                indent=4)

        with self.assertRaises(DiffsFound) as e:
            expected.assertNoDiff(result)
Exemplo n.º 16
0
    def test_path(self):
        expected = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                'response_fixtures',
                                'TestResponseDiff.test_path')

        assert Response.for_test(self).path == expected
Exemplo n.º 17
0
 def functional_test(self, queries, url):
     with self.assertNumQueries(queries):
         result = test.client.Client().get(url)
     Response.for_test(self).assertNoDiff(result)
Exemplo n.º 18
0
    def test_websiteTest(self):  # noqa
        path = Response.for_test(self).path
        if os.path.exists(path):  # pragma: no cover
            # Only makes sense when you're running the tests over and over
            # locally, makes no sense on single-usage containers like travis,
            # hence "no cover" above.
            shutil.rmtree(path)

        fixtures = [
            '/notrailing',
            '/notrailing?foo=bar',
            '/trailing/',
            '/trailing/?foo=bar',
        ]

        client = self.get_client(fixtures)
        covered, diffs, created = self.responsediff_website_crawl(
            client=client)

        expected_covered = ['/'] + fixtures
        assert covered == expected_covered

        expected_created = [
            'MixinTest.test_websiteTest/content',
            'MixinTest.test_websiteTest/metadata',
            'MixinTest.test_websiteTest/trailing/metadata',
            'MixinTest.test_websiteTest/trailing/content',
            'MixinTest.test_websiteTest/trailing/?foo=bar.metadata',
            'MixinTest.test_websiteTest/trailing/?foo=bar.content',
            'MixinTest.test_websiteTest/notrailing.content',
            'MixinTest.test_websiteTest/notrailing.metadata',
            'MixinTest.test_websiteTest/notrailing?foo=bar.metadata',
            'MixinTest.test_websiteTest/notrailing?foo=bar.content',
        ]
        result_created = [
            re.sub('.*MixinTest.test_websiteTest',
                   'MixinTest.test_websiteTest', c) for c in created
        ]
        assert sorted(result_created) == sorted(expected_created)

        for path in created.keys():
            if 'MixinTest.test_websiteTest/content' in path:
                break

        with open(path, 'w') as f:
            f.write('fail please')

        covered, diffs, created = self.responsediff_website_crawl(
            client=self.get_client(fixtures))

        expected = six.b('''
@@ -1 +1,4 @@
-fail please
\ No newline at end of file
+href="/notrailing"
+href="/notrailing?foo=bar"
+href="/trailing/"
+href="/trailing/?foo=bar"
\ No newline at end of file
        ''')

        assert list(diffs.values())[0].strip() == expected.strip()