def test_validate_ip_invalid(self, settings):
        settings.ADMIN_API_ALLOWED_SUBNETS = [IPv4Network("127.0.0.1")]

        request = Request({"HTTP_X_FORWARDED_FOR": "0.0.0.0"}, "")
        middleware = AdminRestrictMiddleware(None)
        with pytest.raises(SuspiciousOperation):
            middleware._validate_ip(request)
    def test_validate_ip_valid(self, settings):
        settings.ADMIN_API_ALLOWED_SUBNETS = [IPv4Network("127.0.0.1")]

        request = Request({"HTTP_X_FORWARDED_FOR": "127.0.0.1"}, "")
        middleware = AdminRestrictMiddleware(None)
        assert middleware._validate_ip(request) is None