#    Copyright 2016 SAS Project Authors. All Rights Reserved.
#
#    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.

import json
import os
import unittest

import sas
from util import winnforum_testcase


class SpectrumInquiryTestcase(unittest.TestCase):

  def setUp(self):
    self._sas, self._sas_admin = sas.GetTestingSas()
    self._sas_admin.Reset()

  def tearDown(self):
    pass

  @winnforum_testcase
  def test_WINFF_FT_S_SIQ_10(self):
    """Send Spectrum Inquiry with missing highFrequency parameter.

    The response should be MISSING_PARAM, code 102
    """
    # Register the device
    device_a = json.load(
        open(os.path.join('testcases', 'testdata', 'device_a.json')))
    self._sas_admin.InjectFccId({'fccId': device_a['fccId']})
    request = {'registrationRequest': [device_a]}
    response = self._sas.Registration(request)['registrationResponse'][0]
    # Check registration response
    self.assertEqual(response['response']['responseCode'], 0)
    cbsd_id = response['cbsdId']
    del request, response

    # Send Spectrum Inquiry request
    spectrum_inquiry_0 = json.load(
        open(os.path.join('testcases', 'testdata', 'spectrum_inquiry_0.json')))
    spectrum_inquiry_0['cbsdId'] = cbsd_id
    del spectrum_inquiry_0['inquiredSpectrum'][0]['highFrequency']
    request = {'spectrumInquiryRequest': [spectrum_inquiry_0]}
    # Check Spectrum Inquiry Response
    response = self._sas.SpectrumInquiry(request)['spectrumInquiryResponse'][0]
    self.assertTrue('cbsdId' in response)
    self.assertEqual(response['cbsdId'], cbsd_id)
    self.assertEqual(response['response']['responseCode'], 102)

@@ -2149,8 +2149,1180 @@
 %5D, 102)%0A
+%0A  @winnforum_testcase%0A  def test_WINFF_FT_S_SIQ_12(self):%0A    %22%22%22Send Spectrum Inquiry with non-existent cbsdId parameter.%0A%0A    The response should be INVALID_PARAM, code 103%0A    %22%22%22%0A    # Register the device%0A    device_a = json.load(%0A        open(os.path.join('testcases', 'testdata', 'device_a.json')))%0A    self._sas_admin.InjectFccId(%7B'fccId': device_a%5B'fccId'%5D%7D)%0A    request = %7B'registrationRequest': %5Bdevice_a%5D%7D%0A    response = self._sas.Registration(request)%5B'registrationResponse'%5D%5B0%5D%0A    # Check registration response%0A    self.assertEqual(response%5B'response'%5D%5B'responseCode'%5D, 0)%0A    cbsd_id = response%5B'cbsdId'%5D%0A    del request, response%0A%0A    # Send Spectrum Inquiry request%0A    spectrum_inquiry_0 = json.load(%0A        open(os.path.join('testcases', 'testdata', 'spectrum_inquiry_0.json')))%0A    spectrum_inquiry_0%5B'cbsdId'%5D = cbsd_id + '-changed'%0A    self.assertNotEqual(cbsd_id, spectrum_inquiry_0%5B'cbsdId'%5D)%0A    request = %7B'spectrumInquiryRequest': %5Bspectrum_inquiry_0%5D%7D%0A    # Check Spectrum Inquiry Response%0A    response = self._sas.SpectrumInquiry(request)%5B'spectrumInquiryResponse'%5D%5B0%5D%0A    self.assertTrue(response%5B'response'%5D%5B'responseCode'%5D in (103, 105))%0A

Implement WINFF.FT.S.SIQ.12