コード例 #1
0
 def test_feature_versioning__updating(self):
     feature = get_sample_feature('irthorn_base_condition',
                                  DemoDbEntityKey.EXISTING_LAND_USE_PARCELS)
     user = User.objects.get(username=UserGroupKey.SUPERADMIN)
     runs = 2
     land_use_definitions = SacogLandUseDefinition.objects.all()[0:runs]
     perform_updates(feature_revision_manager, feature,
                     land_use_definitions, 'land_use_definition', [user])
     for i, land_use_definition in enumerate(land_use_definitions):
         # Make sure that we have the expected comment and land_use_definition id for each version
         feature_version = feature_revision_manager.get_unique_for_object(
             feature)[runs - 1 - i]
         expected_comment = "Comment %s" % land_use_definition.id
         assert_equals(
             feature_version.revision.comment, expected_comment,
             "Expected feature version %s comment to have comment %s" %
             (feature_version.revision.id, expected_comment))
         expected_association_id = int(land_use_definition.id)
         actual_association_id = feature_version.field_dict[
             'land_use_definition']
         assert_equals(
             actual_association_id, expected_association_id,
             "Expected association for version %s comment to have id %s, but alas it has id %s"
             % (feature_version.revision.id, expected_association_id,
                actual_association_id))
コード例 #2
0
    def test_feature_revision_api(self):
        """
            Make sure that the API can return all the versions of a feature
        :return:
        """
        feature = get_sample_feature(
            'irthorn_base_condition',
            SacogDbEntityKey.EXISTING_LAND_USE_PARCELS)
        user = User.objects.get(username=UserGroupKey.SUPERADMIN)
        runs = 2
        land_use_definitions = SacogLandUseDefinition.objects.all()[0:runs]
        # Update the feature [runs] times
        perform_updates(feature_revision_manager, feature,
                        land_use_definitions, 'land_use_definition', [user])
        # Fetch the feature revisions from the API
        resource_name = 'feature_revision'
        # We currently use the user's LayerSelection along with the feature id to fetch the revision history
        # Alternatively the resource could be configured accept a config_entity id, db_entity id, and feature id
        # Or we could use a combination of these ids to define a unique_id like we do with layer_selection
        feature_class = feature.__class__
        config_entity = feature_class.config_entity
        db_entity_key = feature_class.db_entity_key
        layer = Layer.objects.get(db_entity_key=db_entity_key,
                                  presentation__config_entity=config_entity)

        response = self.get(resource_name,
                            user=user,
                            query_params=dict(layer__id=layer.id,
                                              id=feature.id))
        api_feature_versions = self.deserialize(response)['objects']

        for i, land_use_definition in enumerate(land_use_definitions):
            # Make sure that we have the expected comment and land_use_definition id for each version
            reverse_i = runs - 1 - i
            feature_version = feature_revision_manager.get_unique_for_object(
                feature)[reverse_i]
            # These should be in the same order--newest to oldest
            api_feature_version = api_feature_versions[reverse_i]

            assert_equals(
                api_feature_version['revision']['comment'],
                feature_version.revision.comment,
                "Expected api feature version %s comment to have comment %s but it has comment %s" %\
                    (feature_version.revision.id, feature_version.revision.comment, api_feature_version['revision']['comment']))
            expected_association_id = int(land_use_definition.id)
            actual_association_id = api_feature_version[
                'object_version'].land_use_definition
            assert_equals(
                actual_association_id, expected_association_id,
                "Expected association for version %s comment to have id %s, but alas it has id %s"
                % (feature_version.revision.id, expected_association_id,
                   actual_association_id))
コード例 #3
0
 def test_feature_versioning__reverting(self):
     feature = get_sample_feature('irthorn_base_condition', DemoDbEntityKey.EXISTING_LAND_USE_PARCELS)
     user = User.objects.get(username=UserGroupKey.SUPERADMIN)
     runs = 2
     land_use_definitions = SacogLandUseDefinition.objects.all()[0:runs]
     logger.info(map(lambda x: x.id, land_use_definitions))
     perform_updates(feature_revision_manager, feature, land_use_definitions, 'land_use_definition', [user])
     for i, land_use_definition in enumerate(land_use_definitions):
         # Revert to each version from newest to oldest and validate the object state
         feature_version = feature_revision_manager.get_unique_for_object(feature)[runs-1-i]  # newest is always first
         feature_version.revision.revert()
         reverted_feature = feature.__class__.objects.get(id=feature.id)
         expected_association_id = int(land_use_definition.id)
         actual_association_id = reverted_feature.land_use_definition.id
         logger.info('%s-%s' %(expected_association_id, actual_association_id))
         assert_equals(actual_association_id,
                       expected_association_id,
                       "Expected association for version %s comment to have id %s, but alas it has id %s" % (feature_version.revision.id, expected_association_id, actual_association_id))
コード例 #4
0
 def test_feature_versioning__updating(self):
     feature = get_sample_feature('irthorn_base_condition', DemoDbEntityKey.EXISTING_LAND_USE_PARCELS)
     user = User.objects.get(username=UserGroupKey.SUPERADMIN)
     runs = 2
     land_use_definitions = SacogLandUseDefinition.objects.all()[0:runs]
     perform_updates(feature_revision_manager, feature, land_use_definitions, 'land_use_definition', [user])
     for i, land_use_definition in enumerate(land_use_definitions):
         # Make sure that we have the expected comment and land_use_definition id for each version
         feature_version = feature_revision_manager.get_unique_for_object(feature)[runs-1-i]
         expected_comment = "Comment %s" % land_use_definition.id
         assert_equals(feature_version.revision.comment,
                       expected_comment,
                       "Expected feature version %s comment to have comment %s" % (feature_version.revision.id, expected_comment))
         expected_association_id = int(land_use_definition.id)
         actual_association_id = feature_version.field_dict['land_use_definition']
         assert_equals(actual_association_id,
                       expected_association_id,
                       "Expected association for version %s comment to have id %s, but alas it has id %s" % (feature_version.revision.id, expected_association_id, actual_association_id))
コード例 #5
0
    def test_feature_revision_api(self):
        """
            Make sure that the API can return all the versions of a feature
        :return:
        """
        feature = get_sample_feature('irthorn_base_condition', SacogDbEntityKey.EXISTING_LAND_USE_PARCELS)
        user = User.objects.get(username=UserGroupKey.SUPERADMIN)
        runs = 2
        land_use_definitions = SacogLandUseDefinition.objects.all()[0:runs]
        # Update the feature [runs] times
        perform_updates(feature_revision_manager, feature, land_use_definitions, 'land_use_definition', [user])
        # Fetch the feature revisions from the API
        resource_name = 'feature_revision'
        # We currently use the user's LayerSelection along with the feature id to fetch the revision history
        # Alternatively the resource could be configured accept a config_entity id, db_entity id, and feature id
        # Or we could use a combination of these ids to define a unique_id like we do with layer_selection
        feature_class = feature.__class__
        config_entity = feature_class.config_entity
        db_entity_key = feature_class.db_entity_key
        layer = Layer.objects.get(db_entity_key=db_entity_key, presentation__config_entity=config_entity)

        response = self.get(resource_name, user=user, query_params=dict(layer__id=layer.id, id=feature.id))
        api_feature_versions = self.deserialize(response)['objects']

        for i, land_use_definition in enumerate(land_use_definitions):
            # Make sure that we have the expected comment and land_use_definition id for each version
            reverse_i = runs - 1 - i
            feature_version = feature_revision_manager.get_unique_for_object(feature)[reverse_i]
            # These should be in the same order--newest to oldest
            api_feature_version = api_feature_versions[reverse_i]

            assert_equals(
                api_feature_version['revision']['comment'],
                feature_version.revision.comment,
                "Expected api feature version %s comment to have comment %s but it has comment %s" %\
                    (feature_version.revision.id, feature_version.revision.comment, api_feature_version['revision']['comment']))
            expected_association_id = int(land_use_definition.id)
            actual_association_id = api_feature_version['object_version'].land_use_definition
            assert_equals(actual_association_id,
                          expected_association_id,
                          "Expected association for version %s comment to have id %s, but alas it has id %s" % (feature_version.revision.id, expected_association_id, actual_association_id))
コード例 #6
0
 def test_feature_versioning__reverting(self):
     feature = get_sample_feature('irthorn_base_condition',
                                  DemoDbEntityKey.EXISTING_LAND_USE_PARCELS)
     user = User.objects.get(username=UserGroupKey.SUPERADMIN)
     runs = 2
     land_use_definitions = SacogLandUseDefinition.objects.all()[0:runs]
     logger.info(map(lambda x: x.id, land_use_definitions))
     perform_updates(feature_revision_manager, feature,
                     land_use_definitions, 'land_use_definition', [user])
     for i, land_use_definition in enumerate(land_use_definitions):
         # Revert to each version from newest to oldest and validate the object state
         feature_version = feature_revision_manager.get_unique_for_object(
             feature)[runs - 1 - i]  # newest is always first
         feature_version.revision.revert()
         reverted_feature = feature.__class__.objects.get(id=feature.id)
         expected_association_id = int(land_use_definition.id)
         actual_association_id = reverted_feature.land_use_definition.id
         logger.info('%s-%s' %
                     (expected_association_id, actual_association_id))
         assert_equals(
             actual_association_id, expected_association_id,
             "Expected association for version %s comment to have id %s, but alas it has id %s"
             % (feature_version.revision.id, expected_association_id,
                actual_association_id))