def test_unauthorized_access(self):
        for url_obj in self.widgy_site.get_urls():
            regex = url_obj.regex

            # Creates as many positional arguments as needed.
            args = ('a',) * (regex.groups - len(regex.groupindex))

            # Creates all the keyword arguments
            kwargs = dict((key, 'a') for key in regex.groupindex.keys())

            url = self.widgy_site.reverse(url_obj.callback, args=args, kwargs=kwargs)

            for method in self.client.options(url)['Allow'].lower().split(','):
                method = method.strip()

                # The view should call widgy_site.authorize_view before doing
                # anything.  If there is an exception raised here, it is likely
                # that the view didn't call widgy_site.authorize_view.
                with mock.patch.object(self.widgy_site, 'authorize_view') as authorize_mock:
                    authorize_mock.side_effect = PermissionDenied
                    resp = getattr(self.client, method)(url)
                    self.assertEqual(resp.status_code, 403)
                    self.assertEqual(authorize_mock.call_count, 1)
Verify each URL defined in the WidgySite uses the WidgySite.authorize
dataset/ETHPy150Open fusionbox/django-widgy/tests/core_tests/tests/test_api.py/TestApi.test_unauthorized_access