# 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.utils import override_settings
from spotseeker_server.models import *
from django.test.client import Client
from django.test import TestCase
import simplejson as json


ALL_OK = 'spotseeker_server.auth.all_ok'
UW_SPOT_FORM = 'spotseeker_server.org_forms.uw_spot.UWSpotForm'
UW_EXT_INFO_FORM = 'spotseeker_server.org_forms.uw_spot.UWSpotExtendedInfoForm'


@override_settings(SPOTSEEKER_AUTH_MODULE=ALL_OK)
@override_settings(SPOTSEEKER_SPOT_FORM=UW_SPOT_FORM)
@override_settings(SPOTSEEKER_SPOTEXTENDEDINFO_FORM=UW_EXT_INFO_FORM)
class UWSpotSchemaTest(TestCase):

    def test_extended_info(self):
        test_spot = Spot.objects.create(id=1, name="Test")

        SpotExtendedInfo.objects.create(spot=test_spot, key="noise_level",
                                        value=["silent",
                                               "quiet",
                                               "moderate",
                                               "variable"])
        SpotExtendedInfo.objects.create(
            spot=test_spot, key="has_computers", value=["true"])
        SpotExtendedInfo.objects.create(
            spot=test_spot, key="orientation", value="unicode")
        SpotExtendedInfo.objects.create(
            spot=test_spot, key="num_computers", value="int")

        c = Client()
        response = c.get("/api/v1/schema")
        schema = json.loads(response.content)
        extended_info = schema["extended_info"]

        self.assertEquals(extended_info["noise_level"],
                          ["silent", "quiet", "moderate", "variable"],
                          "Schema ExtendedInfo matches actual ExtendedInfo")
        self.assertEquals(extended_info["has_computers"],
                          ["true"],
                          "Schema ExtendedInfo matches actual ExtendedInfo")
        self.assertEquals(extended_info["orientation"],
                          "unicode",
                          "Schema ExtendedInfo matches actual ExtendedInfo")
        self.assertEquals(extended_info["num_computers"],
                          "int",
                          "Schema ExtendedInfo matches actual ExtendedInfo")

@@ -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
@@ -276,17 +276,17 @@
 LL_OK = 
-'
+%22
 spotseek
@@ -306,17 +306,17 @@
 h.all_ok
-'
+%22
 %0AUW_SPOT
@@ -315,33 +315,33 @@
 %0AUW_SPOT_FORM = 
-'
+%22
 spotseeker_serve
@@ -370,17 +370,17 @@
 SpotForm
-'
+%22
 %0AUW_EXT_
@@ -391,17 +391,17 @@
 _FORM = 
-'
+%22
 spotseek
@@ -454,9 +454,9 @@
 Form
-'
+%22
 %0A%0A%0A@
@@ -662,17 +662,16 @@
 tCase):%0A
-%0A
     def 
@@ -796,16 +796,29 @@
 .create(
+%0A            
 spot=tes
@@ -820,24 +820,36 @@
 t=test_spot,
+%0A           
  key=%22noise_
@@ -872,214 +872,45 @@
     
-                            value=%5B%22silent%22,%0A                                               %22quiet%22,%0A                                               %22moderate%22,%0A                                              
+value=%5B%22silent%22, %22quiet%22, %22moderate%22,
  %22va
@@ -917,16 +917,26 @@
 riable%22%5D
+,%0A        
 )%0A      
@@ -1033,16 +1033,25 @@
 %5B%22true%22%5D
+%0A        
 )%0A      
@@ -1147,16 +1147,25 @@
 unicode%22
+%0A        
 )%0A      
@@ -1259,16 +1259,25 @@
 ue=%22int%22
+%0A        
 )%0A%0A     
@@ -1448,32 +1448,45 @@
 lf.assertEquals(
+%0A            
 extended_info%5B%22n
@@ -1495,38 +1495,24 @@
 se_level%22%5D,%0A
-              
             
@@ -1552,38 +1552,24 @@
 variable%22%5D,%0A
-              
             
@@ -1609,32 +1609,42 @@
 al ExtendedInfo%22
+,%0A        
 )%0A        self.a
@@ -1647,32 +1647,45 @@
 lf.assertEquals(
+%0A            
 extended_info%5B%22h
@@ -1712,30 +1712,16 @@
         
-     
-         
 %5B%22true%22%5D
@@ -1718,38 +1718,24 @@
   %5B%22true%22%5D,%0A
-              
             
@@ -1775,32 +1775,42 @@
 al ExtendedInfo%22
+,%0A        
 )%0A        self.a
@@ -1813,32 +1813,45 @@
 lf.assertEquals(
+%0A            
 extended_info%5B%22o
@@ -1876,30 +1876,16 @@
         
-        
-      
 %22unicode
@@ -1887,30 +1887,16 @@
 icode%22,%0A
-              
         
@@ -1948,16 +1948,26 @@
 dedInfo%22
+,%0A        
 )%0A      
@@ -1986,16 +1986,29 @@
 tEquals(
+%0A            
 extended
@@ -2047,43 +2047,15 @@
     
-           
-   
 %22int%22,%0A
-              
     
@@ -2111,10 +2111,20 @@
 dedInfo%22
+,%0A        
 )%0A

Reformat and update copyright.