Пример #1
0
 def setUp(self):
     self.attributes_functions = [
         'filter/sigla/in/rj,es,go/',
         'filter/sigla/uppercase/in/rj,es,go/and/data/between/2017-02-01,2017-06-30/',
         'filter/sigla/in/rj,es,go/and/geom/within/{"type":"Polygon","coordinates":[[[-41.881710164667396,-21.297482165015307],[-28.840495695785098,-21.297482165015307],[-28.840495695785098,-17.886950999070834],[-41.881710164667396,-17.886950999070834],[-41.881710164667396,-21.297482165015307]]]}'
     ]
     self.acr = AbstractCollectionResource()
Пример #2
0
class AbstractResourceTestCase(SimpleTestCase):
    def setUp(self):
        self.tr = TesteResource('name', 'parameters', 'answer')
        self.ar = AbstractCollectionResource()

    def test_attributes(self):
        pass

    def test_operations(self):
        pass

    def test_remove_last_slash(self):

        self.assertEquals(
            self.ar.remove_last_slash(
                'within/__tokenurl__1/collect/geom/buffer/0.2/'),
            'within/__tokenurl__1/collect/geom/buffer/0.2')
        self.assertEquals(
            self.ar.remove_last_slash(
                'within/__tokenurl__1/collect/geom/buffer/0.2'),
            'within/__tokenurl__1/collect/geom/buffer/0.2')
        self.assertEquals(
            self.ar.remove_last_slash(
                'within/__tokenurl__1/collect/geom/buffer/0.2 '),
            'within/__tokenurl__1/collect/geom/buffer/0.2')

    def test_attribute_functions_str_splitted_by_slash(self):
        res = self.ar.attribute_functions_str_splitted_by_slash(
            'within/http://172.30.10.86:8000/ibge/bcim/municipios/3159407/*collect/geom/buffer/0.2/intersects/https://172.30.10.86:8000/instituicoes/bcim/estado/rj/*'
        )
        self.assertEquals(res[0], 'within')
        self.assertEquals(
            res[1], 'http://172.30.10.86:8000/ibge/bcim/municipios/3159407/')
        self.assertEquals(res[2], '*collect')
        self.assertEquals(res[3], 'geom')
        self.assertEquals(res[4], 'buffer')
        self.assertEquals(res[5], '0.2')
        self.assertEquals(res[6], 'intersects')
        self.assertEquals(
            res[7], 'https://172.30.10.86:8000/instituicoes/bcim/estado/rj/')
Пример #3
0
class AbstractCollectionResourceTest(SimpleTestCase):
    def setUp(self):
        self.attributes_functions = [
            'filter/sigla/in/rj,es,go/',
            'filter/sigla/uppercase/in/rj,es,go/and/data/between/2017-02-01,2017-06-30/',
            'filter/sigla/in/rj,es,go/and/geom/within/{"type":"Polygon","coordinates":[[[-41.881710164667396,-21.297482165015307],[-28.840495695785098,-21.297482165015307],[-28.840495695785098,-17.886950999070834],[-41.881710164667396,-17.886950999070834],[-41.881710164667396,-21.297482165015307]]]}'
        ]
        self.acr = AbstractCollectionResource()

    def test_attributes_functions_str_is_filter_with_spatial_operation(self):
        self.assertTrue(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                'filter/sigla/in/rj,es,go/and/geom/within/Point(1,2)'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter/filter'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter/ast/eq/ass/geom/within/asd'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter/within/eq/asd'))
        self.assertTrue(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter/within/eq/geom/and/geom/within/asd'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter/operacao/eq/within'))
        self.assertTrue(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter/eq/within/abxgeom'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/filter/within/eq/abxx'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/within/geom'))
        self.assertFalse(
            self.acr.attributes_functions_str_is_filter_with_spatial_operation(
                '/within/filter'))
Пример #4
0
class AbstractCollectionResourceTestCase(SimpleTestCase):
    def setUp(self):
        self.attributes_functions = [
            'filter/sigla/in/rj,es,go/',
            'filter/sigla/uppercase/in/rj,es,go/and/data/between/2017-02-01,2017-06-30/',
            'filter/sigla/in/rj,es,go/and/geom/within/{"type":"Polygon","coordinates":[[[-41.881710164667396,-21.297482165015307],[-28.840495695785098,-21.297482165015307],[-28.840495695785098,-17.886950999070834],[-41.881710164667396,-17.886950999070834],[-41.881710164667396,-21.297482165015307]]]}'
        ]
        self.acr = AbstractCollectionResource()

    def test_get_operation_name_from_path(self):
        self.assertEquals(
            self.acr.get_operation_name_from_path('collect/geom/buffer/0.2'),
            'collect')
        self.assertEquals(
            self.acr.get_operation_name_from_path('filter/geom/buffer/0.2'),
            'filter')
        self.assertEquals(
            self.acr.get_operation_name_from_path(
                'filter/geom/containing/http://host/aldeias-indigenas/821/*collect/nome.geom/buffer/0.2'
            ), 'filter_collect')
        self.assertEquals(
            self.acr.get_operation_name_from_path(
                'collect/nome&geom/buffer/0.2/containing/http://host/aldeias-indigenas/821/*filter/nome/startswith/rio'
            ), 'collect_filter')
        self.assertEquals(
            self.acr.get_operation_name_from_path('count_resource'),
            'count_resource')
        self.assertEquals(
            self.acr.get_operation_name_from_path('group_by/nome'), 'group_by')
        self.assertEquals(
            self.acr.get_operation_name_from_path('group_by_count/nome'),
            'group_by_count')
        self.assertEquals(self.acr.get_operation_name_from_path('distinct'),
                          'distinct')
        self.assertEquals(
            self.acr.get_operation_name_from_path('offset_limit/1&10'),
            'offset_limit')
        self.assertEquals(self.acr.get_operation_name_from_path('nadahaver'),
                          None)

    def test_attributes_functions_str_is_filter_with_spatial_operation(self):
        pass
        """
        self.assertTrue(self.acr.attributes_functions_str_is_filter_with_spatial_operation('filter/sigla/in/rj,es,go/and/geom/within/Point(1,2)'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter/filter'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter/ast/eq/ass/geom/within/asd'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter/within/eq/asd'))
        self.assertTrue(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter/within/eq/geom/and/geom/within/asd'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter/operacao/eq/within'))
        self.assertTrue(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter/eq/within/abxgeom'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/filter/within/eq/abxx'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/within/geom'))
        self.assertFalse(self.acr.attributes_functions_str_is_filter_with_spatial_operation('/within/filter'))
        """

    def test_attributes_functions_str_splitted_by_slash(self):
        self.acr.attribute_functions_str_splitted_by_slash(
            'collect/geom/buffer/0.2') == ['collect', 'geom', 'buffer', '0.2']
        self.acr.attribute_functions_str_splitted_by_slash(
            'collect/geom/buffer/0.2/') == [
                'collect', 'geom', 'buffer', '0.2'
            ]
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'collect/geom/buffer/0.2'),
            ['collect', 'geom', 'buffer', '0.2'])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'collect/geom/buffer/0.2/transform/3005&True/area'), [
                    'collect', 'geom', 'buffer', '0.2', 'transform',
                    '3005&True', 'area'
                ])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'offsetLimit/1&10/collect/geom/buffer/0.2'),
            ['offsetLimit', '1&10', 'collect', 'geom', 'buffer', '0.2'])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'within/{"type":"Polygon","coordinates":[[[-48.759514611370854,-28.3426735036349],[-48.631647133384185,-28.3426735036349],[-48.631647133384185,-28.082673631081306],[-48.759514611370854,-28.082673631081306],[-48.759514611370854,-28.3426735036349]]]}/collect/geom/buffer/0.2'
            ), [
                'within',
                '{"type":"Polygon","coordinates":[[[-48.759514611370854,-28.3426735036349],[-48.631647133384185,-28.3426735036349],[-48.631647133384185,-28.082673631081306],[-48.759514611370854,-28.082673631081306],[-48.759514611370854,-28.3426735036349]]]}',
                'collect', 'geom', 'buffer', '0.2'
            ])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'within/http://172.30.10.86:8000/instituicoes/ibge/bcim/municipios/3159407/*collect/geom/buffer/0.2/'
            ), [
                'within',
                'http://172.30.10.86:8000/instituicoes/ibge/bcim/municipios/3159407/',
                '*collect', 'geom', 'buffer', '0.2'
            ])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'within/https://172.30.10.86:8000/instituicoes/ibge/bcim/municipios/3159407/*collect/geom/buffer/0.2'
            ), [
                'within',
                'https://172.30.10.86:8000/instituicoes/ibge/bcim/municipios/3159407/',
                '*collect', 'geom', 'buffer', '0.2'
            ])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'within/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/*collect/geom/buffer/0.2/within/http://ibge/unidades-federativas/RJ/*'
            ), [
                'within',
                'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/',
                '*collect', 'geom', 'buffer', '0.2', 'within',
                'http://ibge/unidades-federativas/RJ/'
            ])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'filter/geom/within/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/*'
            ), [
                'filter', 'geom', 'within',
                'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/'
            ])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'filter/geom/within/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom/*and/sigla/eq/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo/*'
            ), [
                'filter', 'geom', 'within',
                'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom/',
                '*and', 'sigla', 'eq',
                'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo/'
            ])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'filter/geom/within/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom/*collect/collect/eq/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo/*'
            ), [
                'filter', 'geom', 'within',
                'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom/',
                '*collect', 'collect', 'eq',
                'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo/'
            ])
        #       self.assertEquals(self.acr.attribute_functions_str_splitted_by_slash('filter/geom/within/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom*/and/geocodigo/eq/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo/*/collect/collect/eq/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo*'),
        #['filter', 'geom', 'within', 'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom','and','geocodigo','eq','http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom/and/geocodigo', 'collect', 'collect', 'eq', 'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo'])
        #self.assertEquals(self.acr.attribute_functions_str_splitted_by_slash('within/WWw.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407*/collect/geom/buffer/0.2'), ['filter', 'geom', 'within', 'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geom', 'and', 'sigla', 'eq', 'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/geocodigo'])
        self.assertEquals(
            self.acr.attribute_functions_str_splitted_by_slash(
                'filter/collect/within/http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/*collect/collect/transform/3005&True/area'
            ), [
                'filter', 'collect', 'within',
                'http://www.ibge.gov.br:8080/instituicoes/ibge/bcim/municipios/3159407/',
                '*collect', 'collect', 'transform', '3005&True', 'area'
            ])

    def test_get_generic_operation_name(self):

        prefix = 'get_objects_from_'
        suffix = '_operation'

        operation_name = self.acr.get_generic_operation_name(
            'filter/geom/within/http://luc00557347.ibge.gov.br/ibge/bcim/unidades-federativas/ES/geom/buffer/0.2*/and/fclass/eq/school/*collect/geom/buffer/0.2'
        )
        self.assertEquals(operation_name,
                          prefix + 'filter_and_collect' + suffix)

        operation_name = self.acr.get_generic_operation_name(
            'filter/sigla/in/RJ,ES/*collect/geom/transform/3005&True/area')
        self.assertEquals(operation_name,
                          prefix + 'filter_and_collect' + suffix)

        operation_name = self.acr.get_generic_operation_name(
            'collect/geom/buffer/0.2/*filter/geom/within/http://luc00557347.ibge.gov.br/ibge/bcim/unidades-federativas/ES/geom/buffer/0.2/and/fclass/eq/school*/'
        )
        self.assertEquals(operation_name,
                          prefix + 'collect_and_filter' + suffix)

        operation_name = self.acr.get_generic_operation_name(
            'filter/geom/within/http://luc00557347.ibge.gov.br/ibge/bcim/unidades-federativas/ES/geom/buffer/0.2'
        )
        self.assertEquals(operation_name, prefix + 'filter' + suffix)

        operation_name = self.acr.get_generic_operation_name(
            'collect/geom/buffer/0.2')
        self.assertEquals(operation_name, prefix + 'collect' + suffix)

        operation_name = self.acr.get_generic_operation_name('groupby/geom/')
        self.assertEquals(operation_name, prefix + 'groupby' + suffix)

        operation_name = self.acr.get_generic_operation_name(
            'groupbycount/geom/')
        self.assertEquals(operation_name, prefix + 'groupbycount' + suffix)

        operation_name = self.acr.get_generic_operation_name(
            'offsetlimit/1:10/')
        self.assertEquals(operation_name, prefix + 'offsetlimit' + suffix)

        operation_name = self.acr.get_generic_operation_name('distinct')
        self.assertEquals(operation_name, prefix + 'distinct' + suffix)

        operation_name = self.acr.get_generic_operation_name('countresource')
        self.assertEquals(operation_name, prefix + 'countresource' + suffix)

        operation_name = self.acr.get_generic_operation_name('annotate/')
        self.assertEquals(operation_name, prefix + 'annotate' + suffix)
Пример #5
0
 def setUp(self):
     self.tr = TesteResource('name', 'parameters', 'answer')
     self.ar = AbstractCollectionResource()