def get_request(self, package=None, perms='', user=None):
        """ Construct a fake request """
        request = MagicMock()
        request.registry.fallback = self.fallback
        request.registry.always_show_upstream = self.always_show_upstream
        request.registry.fallback_url = self.fallback_url
        request.userid = user
        request.access.can_update_cache = lambda: 'c' in perms
        request.access.has_permission.side_effect = lambda n, p: 'r' in perms
        request.is_logged_in = user is not None
        request.request_login = MethodType(
            _request_login,
            request,
            request.__class__)
        pkgs = []
        if package is not None:
            pkgs.append(package)
        request.db.all.return_value = pkgs
        return request
dataset/ETHPy150Open mathcamp/pypicloud/tests/test_simple.py/PackageReadTestBase.get_request/original