#    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


class DeregistrationTestcase(unittest.TestCase):

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

  def tearDown(self):
    pass

  def test_10_15_4_1_1(self):
    """Successful CBSD deregistration request.

    CBSD sends deregistration request to SAS with its correct and valid CBSD
    ID, the response should be SUCCESS.
    """

    # 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

    # Deregister the device
    request = {'deregistrationRequest': [{'cbsdId': cbsd_id}]}
    response = self._sas.Deregistration(request)['deregistrationResponse'][0]
    # Check the deregistration response
    self.assertEqual(response['cbsdId'], cbsd_id)
    self.assertEqual(response['response']['responseCode'], 0)

@@ -1832,28 +1832,980 @@
 ponse'%5D%5B'responseCode'%5D, 0)%0A
+%0A  def test_10_15_4_2_1(self):%0A    %22%22%22CBSD deregistration request with missing required parameter.%0A%0A    The required parameter 'cbsdId' is missing in a deregistration request,%0A    the response should be FAIL.%0A    %22%22%22%0A%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    del request, response%0A%0A    # Deregister the device%0A    request = %7B'deregistrationRequest': %5B%7B%7D%5D%7D%0A    response = self._sas.Deregistration(request)%5B'deregistrationResponse'%5D%5B0%5D%0A    # Check the deregistration response%0A    self.assertFalse('cbsdId' in response)%0A    self.assertEqual(response%5B'response'%5D%5B'responseCode'%5D, 102)    %0A

Add deregistration missing cbsd id test case