@@ -0,0 +1,2120 @@
+import json%0A%0Afrom django.core.urlresolvers import reverse%0A%0Afrom rest_framework.test import APITestCase%0Afrom model_mommy import mommy%0A%0Afrom facilities.models import FacilityService%0Afrom ..models import County%0Afrom ..serializers import CountySerializer%0Afrom .test_views import LoginMixin, default%0A%0A%0Aclass TestThrottling(LoginMixin, APITestCase):%0A    def test_non_throttled_view(self):%0A        # the counties view is not throttled:%0A        url = reverse('api:common:counties_list')%0A        county = mommy.make(County)%0A        response = self.client.get(url)%0A        self.assertEquals(200, response.status_code)%0A        expected_data = %7B%0A            %22count%22: 1,%0A            %22next%22: None,%0A            %22previous%22: None,%0A            %22results%22: %5B%0A                CountySerializer(county).data%0A            %5D%0A        %7D%0A        self.assertEquals(%0A            json.loads(json.dumps(response.data, default=default)),%0A            json.loads(json.dumps(expected_data, default=default)))%0A        # call the url again to confirm it returns%0A        # throttle rate is once per day%0A        response_2 = self.client.get(url)%0A        self.assertEquals(200, response_2.status_code)%0A        self.assertEquals(%0A            json.loads(json.dumps(response_2.data, default=default)),%0A            json.loads(json.dumps(expected_data, default=default)))%0A%0A    def test_throttled_view(self):%0A        # facility rating is throttled to once per day%0A        url = reverse(%22api:facilities:facility_service_ratings_list%22)%0A        fs = mommy.make(FacilityService)%0A%0A        data = %7B%0A            %22rating%22: 1,%0A            %22facility_service%22: fs.id%0A        %7D%0A        response = self.client.post(%0A            path=url, data=data, REMOTE_ADDR=%22127.0.0.1%22)%0A        self.assertEquals(201, response.status_code)%0A%0A        # the url for our current ip should not be throttled%0A        # after accessing it the first time%0A%0A        data_2 = %7B%0A            %22rating%22: 5,%0A            %22facility_service%22: fs.id%0A        %7D%0A%0A        response_2 = self.client.post(%0A            path=url, data=data_2, REMOTE_ADDR=%22127.0.0.1%22)%0A        self.assertEquals(429, response_2.status_code)%0A

Add throttling tests