# Copyright 2021 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

""" Copyright 2012, 2013 UW Information Technology, University of Washington

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

from django.test import TestCase
from django.test.client import Client
from spotseeker_server.models import Spot
import simplejson as json
from django.test.utils import override_settings
from mock import patch
from spotseeker_server import models


@override_settings(SPOTSEEKER_AUTH_MODULE='spotseeker_server.auth.all_ok')
class SpotSearchLimitTest(TestCase):
    def setUp(self):
        num_spots = 25
        self.num_spots = num_spots
        for i in range(num_spots):
            i = i + 1
            Spot.objects.create(name="spot %s" % (i))

    def test_more_than_20_no_limit(self):
        c = Client()
        get_request = "/api/v1/spot?"
        num_spots = self.num_spots

        for i in Spot.objects.all():
            get_request = get_request + "id=%s&" % (i.id)

        response = c.get(get_request)
        self.assertEquals(
            response.status_code,
            400,
            ("400 is thrown if more than 20 spots "
             "are requested without a limit")
        )

    def test_less_than_20_no_limit(self):
        c = Client()
        get_request = "/api/v1/spot?"
        num_spots = self.num_spots - 10

        for i in range(num_spots):
            i = i + 1
            get_request = get_request + "id=%s&" % (Spot.objects.all()[i].id)

        response = c.get(get_request)
        spots = json.loads(response.content)
        self.assertEquals(
            len(spots),
            num_spots,
            ("Spots requested were returned if "
             "less than 20 spots are requested without a limit")
        )

    def test_more_than_20_with_limit(self):
        c = Client()
        get_request = "/api/v1/spot?"
        num_spots = self.num_spots

        for i in Spot.objects.all():
            get_request = get_request + "id=%s&" % (i.id)
        get_request = get_request + "limit=%d" % (num_spots)

        response = c.get(get_request)
        spots = json.loads(response.content)
        self.assertEquals(
            len(spots),
            num_spots,
            ("Spots requested were returned even though "
             "more than 20 because a limit was included")
        )

@@ -85,647 +85,8 @@
 .0%0A%0A
-%22%22%22 Copyright 2012, 2013 UW Information Technology, University of Washington%0A%0A    Licensed under the Apache License, Version 2.0 (the %22License%22);%0A    you may not use this file except in compliance with the License.%0A    You may obtain a copy of the License at%0A%0A    http://www.apache.org/licenses/LICENSE-2.0%0A%0A    Unless required by applicable law or agreed to in writing, software%0A    distributed under the License is distributed on an %22AS IS%22 BASIS,%0A    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A    See the License for the specific language governing permissions and%0A    limitations under the License.%0A%22%22%22%0A%0A
 from
@@ -372,17 +372,17 @@
 _MODULE=
-'
+%22
 spotseek
@@ -406,9 +406,9 @@
 l_ok
-'
+%22
 )%0Acl
@@ -995,16 +995,33 @@
        (
+%0A                
 %22400 is 
@@ -1064,16 +1064,19 @@
         
+   
 %22are req
@@ -1090,33 +1090,47 @@
 without a limit%22
-)
+%0A            ),
 %0A        )%0A%0A    
@@ -1565,32 +1565,49 @@
 s,%0A            (
+%0A                
 %22Spots requested
@@ -1639,16 +1639,19 @@
         
+   
 %22less th
@@ -1692,17 +1692,31 @@
 a limit%22
-)
+%0A            ),
 %0A       
@@ -2185,16 +2185,33 @@
        (
+%0A                
 %22Spots r
@@ -2260,16 +2260,19 @@
         
+   
 %22more th
@@ -2306,17 +2306,31 @@
 ncluded%22
-)
+%0A            ),
 %0A       

Reformat and update copyright.