def test_polygons_equal(self):
        poly_ref = sgeo.Point(0, 0).buffer(1)

        poly = sgeo.Point(0, 0).buffer(1)
        self.assertTrue(utils.PolygonsAlmostEqual(poly_ref, poly, 1e-6))

        poly = sgeo.Point(0, 0).buffer(1.1)
        self.assertTrue(utils.PolygonsAlmostEqual(poly_ref, poly, 21.2))

        poly = sgeo.Point(0, 0).buffer(1.1)
        self.assertFalse(utils.PolygonsAlmostEqual(poly_ref, poly, 20.8))

        poly = sgeo.Point(0, 0.1).buffer(1)
        self.assertTrue(utils.PolygonsAlmostEqual(poly_ref, poly, 15))
Example #2
0
def areTwoPpasEqual(first_ppa, second_ppa, delta=10):
    """ Deep comparison of two PPAs considering

  Args:
    first_ppa: a dictionary contains  the firt PPA data.
    second_ppa: a dictionary contains the second PPA data.
    delta: an accepted margin for comparing the polygons of PPAs

 Returns: boolean set to true if the PPAs are equal and false otherwise.
 Note: the PPA should contain a key 'zone' holding a GeoJSON feature collection with first feature
     defining the PPA zone as a polygon (or multipolygon) geometry
  """
    geometry_of_first_ppa = first_ppa['zone']['features'][0]['geometry']
    geometry_of_second_ppa = second_ppa['zone']['features'][0]['geometry']

    if not utils.PolygonsAlmostEqual(geometry_of_first_ppa,
                                     geometry_of_second_ppa, delta):
        return False
    if geometry_of_first_ppa['type'] != geometry_of_second_ppa['type']:
        return False
    # check other Ppa parameters
    del first_ppa['zone']['features'][0]['geometry']
    del second_ppa['zone']['features'][0]['geometry']
    result = compareDictWithUnorderedLists(first_ppa, second_ppa)
    first_ppa['zone']['features'][0]['geometry'] = geometry_of_first_ppa
    second_ppa['zone']['features'][0]['geometry'] = geometry_of_second_ppa
    return result
    def test_WINNF_FT_S_PCR_2(self, config_filename):
        """Successful Maximum PPA Boundary Creation Clipped by Service Area Boundary.

    Checks the maximum PPA boundary, being clipped by the Service Area composed of
    one or more adjacent Census Tracts.
    Checks PPA generated by SAS UUT shall be fully contained within the service area.
    """
        # Load the Config file.
        config = loadConfig(config_filename)

        # Register devices and  check response.
        cbsd_ids = self.assertRegistered(config['registrationRequests'],
                                         config['conditionalRegistrationData'])

        # Asserts the REG-Conditional value doesn't exist in the registrationRequest,
        # it is required to be exist in the registrationRequest data.
        assertRegConditionalsForPpaRefModel(
            config['registrationRequests'],
            config['conditionalRegistrationData'])

        # Trigger PPA creation to calculate maximum PPA boundary and check if any errors
        # encountered in PPA creation reference model.
        test_harness_ppa_geometry = ppa.PpaCreationModel(
            config['registrationRequests'], config['palRecords'])

        # Inject the PAL records.
        for pal_record in config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Prepares the PAL Ids to trigger ppa creation request.
        pal_ids = [record['palId'] for record in config['palRecords']]
        ppa_creation_request = {"cbsdIds": cbsd_ids, "palIds": pal_ids}

        # Trigger PPA Creation to SAS UUT.
        ppa_id = self.triggerPpaCreationAndWaitUntilComplete(
            ppa_creation_request)
        logging.debug('ppa_id received from SAS UUT:%s', ppa_id)

        # Trigger Full Activity Dump and retrieves the PPA Zone record.
        uut_ppa_zone_data = self.triggerFadGenerationAndRetrievePpaZone(
            ssl_cert=config['sasTestHarnessCert'],
            ssl_key=config['sasTestHarnessKey'])

        # Check if the PPA generated by the SAS UUT is fully contained within the service area.
        logging.debug(
            "SAS UUT PPA - retrieved through FAD:%s",
            json.dumps(uut_ppa_zone_data,
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))
        logging.debug(
            "Reference model PPA - retrieved through PpaCreationModel:%s",
            json.dumps(json.loads(test_harness_ppa_geometry),
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))

        uut_ppa_geometry = uut_ppa_zone_data['zone']['features'][0]['geometry']
        self.assertTrue(isPpaWithinServiceArea(config['palRecords'],
                                               uut_ppa_geometry),
                        msg="PPA Zone is not within service area")

        # Check the Equation 8.3.1 in Test Specfification is satisified w.r t
        # [n.12, R2-PAL-05]. Check the area of the non-overlapping difference between
        # the maximum PPA boundary created by SAS UUT shall be no more than 10% of the area
        # of the maximum PPA boundary created by the Reference Model.
        self.assertTrue(
            utils.PolygonsAlmostEqual(test_harness_ppa_geometry,
                                      uut_ppa_geometry))
    def test_WINNF_FT_S_PCR_3(self, config_filename):
        """Successful PPA Confirmation with Claimed Boundary by PAL Holder.

    Checks PPA generated by SAS UUT shall be fully contained within the service area.
    Checks SAS UUT shall confirm a valid PPA boundary claimed by the PAL holder,
    composed of one or more adjacent Census Tracts.
    """
        # Load the Config file.
        config = loadConfig(config_filename)

        # Load the test_WINNF_FT_S_PCR_1 config. All other inputs must be identical
        # to those used in the corresponding configuration of PCR.1.
        pcr_1_test_config = loadConfig(config['configPCR_1'])

        # Inject the PAL records.
        for pal_record in pcr_1_test_config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Register devices and check the response.
        cbsd_ids = self.assertRegistered(
            pcr_1_test_config['registrationRequests'],
            pcr_1_test_config['conditionalRegistrationData'])

        # Prepares the PAL Ids to trigger ppa creation request.
        pal_ids = [
            record['palId'] for record in pcr_1_test_config['palRecords']
        ]

        # Create PPA creation request with user claimed ppa contour.
        ppa_creation_request = {
            "cbsdIds": cbsd_ids,
            "palIds": pal_ids,
            "providedContour": config['userClaimedPpaContour']
        }

        # Trigger PPA Creation to SAS UUT.
        ppa_id = self.triggerPpaCreationAndWaitUntilComplete(
            ppa_creation_request)
        logging.debug('ppa_id received from SAS UUT:%s', ppa_id)

        # Trigger Full Activity Dump and retrieves the PPA Zone record.
        uut_ppa_zone_data = self.triggerFadGenerationAndRetrievePpaZone(
            ssl_cert=pcr_1_test_config['sasTestHarnessCert'],
            ssl_key=pcr_1_test_config['sasTestHarnessKey'])

        # Check if the PPA generated by the SAS UUT is fully contained within the service area.
        logging.debug(
            "SAS UUT PPA - retrieved through FAD:%s",
            json.dumps(uut_ppa_zone_data,
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))
        logging.debug(
            "User claimed PPA boundary:%s",
            json.dumps(config['userClaimedPpaContour'],
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))
        uut_ppa_geometry = uut_ppa_zone_data['zone']['features'][0]['geometry']
        self.assertTrue(isPpaWithinServiceArea(pcr_1_test_config['palRecords'],
                                               uut_ppa_geometry),
                        msg="PPA Zone is not within service area")

        # Check the maximum PPA boundary created by SAS UUT is identical with the maximum
        # PPA claimed boundary.
        test_harness_ppa_geometry = config['userClaimedPpaContour'][
            'features'][0]['geometry']
        self.assertTrue(
            utils.PolygonsAlmostEqual(test_harness_ppa_geometry,
                                      uut_ppa_geometry))
    def test_WINNF_FT_S_PCR_1(self, config_filename):
        """Successful Maximum PPA Creation.

    Checks PPA generated by SAS UUT shall be fully contained within the service area.
    """
        # Load the Config file
        config = loadConfig(config_filename)
        # Very light checking of the config file.
        self.assertValidConfig(
            config, {
                'registrationRequests': list,
                'conditionalRegistrationData': list,
                'palRecords': list,
                'sasTestHarnessCert': basestring,
                'sasTestHarnessKey': basestring
            })

        # Register devices and  check response.
        cbsd_ids = self.assertRegistered(config['registrationRequests'],
                                         config['conditionalRegistrationData'])

        # Asserts the REG-Conditional value doesn't exist in the registrationRequest,
        # it required to be exist in the registrationRequest data.
        assertRegConditionalsForPpaRefModel(
            config['registrationRequests'],
            config['conditionalRegistrationData'])

        # Trigger PPA creation to calculate maximum PPA boundary and check if any errors
        # encountered in PPA creation reference model.
        test_harness_ppa_geometry = ppa.PpaCreationModel(
            config['registrationRequests'], config['palRecords'])

        # Inject the PAL records.
        for pal_record in config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Trigger SAS UUT to create a PPA boundary.
        pal_ids = [record['palId'] for record in config['palRecords']]
        ppa_creation_request = {"cbsdIds": cbsd_ids, "palIds": pal_ids}

        # Trigger PPA Creation to SAS UUT.
        ppa_id = self.triggerPpaCreationAndWaitUntilComplete(
            ppa_creation_request)
        logging.debug('ppa_id received from SAS UUT:%s', ppa_id)

        # Notify SAS UUT about SAS Harness and trigger Full Activity Dump and
        # retrieves the PPA Zone record.
        uut_ppa_zone_data = self.triggerFadGenerationAndRetrievePpaZone(
            ssl_cert=config['sasTestHarnessCert'],
            ssl_key=config['sasTestHarnessKey'])

        # Write SAS UUT PPA to output directory of PCR.1 test.
        # PPA Zone received from SAS UUT in PCR.1 test will be considered as input
        # for PCR 3,PCR 6 and PCR 7 tests.
        ppa_zone_data_file_path = getSasUutClaimedPpaBoundaryFilePath(
            config_filename.split('/')[-1])
        ppa_zone_data_dir_path = os.path.dirname(ppa_zone_data_file_path)
        if not os.path.exists(ppa_zone_data_dir_path):
            os.makedirs(ppa_zone_data_dir_path)
        with open(ppa_zone_data_file_path, 'w') as file_handle:
            file_handle.write(
                json.dumps(uut_ppa_zone_data['zone'],
                           indent=2,
                           sort_keys=False,
                           separators=(',', ': ')))

        # Check if the PPA generated by the SAS UUT is fully contained within the
        # service area.
        logging.debug(
            "SAS UUT PPA - retrieved through FAD:%s",
            json.dumps(uut_ppa_zone_data,
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))
        logging.debug(
            "Reference model PPA - retrieved through PpaCreationModel:%s",
            json.dumps(json.loads(test_harness_ppa_geometry),
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))

        uut_ppa_geometry = uut_ppa_zone_data['zone']['features'][0]['geometry']
        self.assertTrue(isPpaWithinServiceArea(config['palRecords'],
                                               uut_ppa_geometry),
                        msg="PPA Zone is not within service area")

        # Check the Equation 8.3.1 in Test Specfification is satisified w.r t
        # [n.12, R2-PAL-05]. Check the area of the non-overlapping difference between
        # the maximum PPA boundary created by SAS UUT shall be no more than 10% of the area
        # of the maximum PPA boundary created by the Reference Model.
        self.assertTrue(
            utils.PolygonsAlmostEqual(test_harness_ppa_geometry,
                                      uut_ppa_geometry))