23ws-LLMcoder/LLMcoder-GitHub-Python-Mix-Direct
Dataset Card for LLMcoder-GitHub-Python-Mix-Direct Python target autocomplete suggestions in the format of conversations for OpenAI's fine-tuning. Dataset Details Dataset Description Curated by: [More Information Needed] Funded by [optional]: [More Information Needed] Shared by [optional]: [More Information Needed] Language(s) (NLP): [More Information Needed] License: [More Information Needed] Dataset Sources [optional] The data… See the full description on the dataset page: https://huggingface.co/datasets/23ws-LLMcoder/LLMcoder-GitHub-Python-Mix-Direct.
0216
1"""2Tests for the throttling implementations in the permissions module.3"""4 5import pytest6from django.contrib.auth.models import User7from django.core.cache import cache8from django.core.exceptions import ImproperlyConfigured9from django.http import HttpRequest10from django.test import TestCase11 12from rest_framework.request import Request13from rest_framework.response import Response14from rest_framework.settings import api_settings15from rest_framework.test import APIRequestFactory, force_authenticate16from rest_framework.throttling import (17 AnonRateThrottle, BaseThrottle, ScopedRateThrottle, SimpleRateThrottle,18 UserRateThrottle19)20from rest_framework.views import APIView21 22 23class User3SecRateThrottle(UserRateThrottle):24 rate = '3/sec'25 scope = 'seconds'26 27 28class User3MinRateThrottle(UserRateThrottle):29 rate = '3/min'30 scope = 'minutes'31 32 33class User6MinRateThrottle(UserRateThrottle):34 rate = '6/min'35 scope = 'minutes'36 37 38class NonTimeThrottle(BaseThrottle):39 def allow_request(self, request, view):40 if not hasattr(self.__class__, 'called'):41 self.__class__.called = True42 return True43 return False44 45 46class MockView_DoubleThrottling(APIView):47 throttle_classes = (User3SecRateThrottle, User6MinRateThrottle,)48 49 def get(self, request):50 return Response('foo')51 52 53class MockView(APIView):54 throttle_classes = (User3SecRateThrottle,)55 56 def get(self, request):57 return Response('foo')58 59 60class MockView_MinuteThrottling(APIView):61 throttle_classes = (User3MinRateThrottle,)62 63 def get(self, request):64 return Response('foo')65 66 67class MockView_NonTimeThrottling(APIView):68 throttle_classes = (NonTimeThrottle,)69 70 def get(self, request):71 return Response('foo')72 73 74class ThrottlingTests(TestCase):75 def setUp(self):76 """77 Reset the cache so that no throttles will be active78 """79 cache.clear()80 self.factory = APIRequestFactory()81 82 def test_requests_are_throttled(self):83 """84 Ensure request rate is limited85 """86 request = self.factory.get('/')87 for dummy in range(4):88 response = MockView.as_view()(request)89 assert response.status_code == 42990 91 def set_throttle_timer(self, view, value):92 """93 Explicitly set the timer, overriding time.time()94 """95 for cls in view.throttle_classes:96 cls.timer = lambda self: value97 98 def test_request_throttling_expires(self):99 """100 Ensure request rate is limited for a limited duration only101 """102 self.set_throttle_timer(MockView, 0)103 104 request = self.factory.get('/')105 for dummy in range(4):106 response = MockView.as_view()(request)107 assert response.status_code == 429108 109 # Advance the timer by one second110 self.set_throttle_timer(MockView, 1)111 112 response = MockView.as_view()(request)113 assert response.status_code == 200114 115 def ensure_is_throttled(self, view, expect):116 request = self.factory.get('/')117 request.user = User.objects.create(username='a')118 for dummy in range(3):119 