Example #1
0
 def testArea(self):
     f = 'tests/area.apt'
     with Aptofile.create(f,'area') as af:
         af.setGenerator('aptfile.py','Aptomar AS')
         af.setDescription('This is a description of the area.')
         af.setAreaName('The Point')
         af.setAreaDescription('This is a description of the area.')
         af.setAreaGeometry('data:data_describing_the_area')
         self.assertTrue(af.validate())
     self.assertTrue(Aptofile.validateFile(f))
Example #2
0
 def testAreaMissingAreaDescription(self):
     f = 'tests/area_missing_area_desc.apt'
     with Aptofile.create(f,'area') as af:
         af.setGenerator('aptfile.py','Aptomar AS')
         af.setDescription('This is a description of the area.')
         af.setAreaName('The Point')
         af.setAreaDescription('This is a description of a area.')
         af.setAreaGeometry('data:data_describing_the_area')
         self.assertTrue(af.validate())
         del af.manifest['area']['description']
     self.assertFalse(Aptofile.validateFile(f))
Example #3
0
    def testRoute(self):
        f = 'tests/route.apt'
        with Aptofile.create(f,'route') as af:
            af.setGenerator('aptfile.py','Aptomar AS')
            af.setDescription('This is a description of the route.')
            af.setRouteName('The Route')
            af.setRouteDescription('This is a description of the route.')
            af.setRouteGeometry('data:data_describing_the_route')

            self.assertTrue(af.validate())
        self.assertTrue(Aptofile.validateFile(f))
Example #4
0
    def testVideoMissingFile(self):
        f = 'tests/video_missing_file.apt'
        with Aptofile.create(f,'video') as af:
            af.setGenerator(program='aptfile.py',creator='Aptomar AS')
            af.setDescription('This is a description of the video')
            af.setVideoName('The video name')
            af.setVideoDescription('A video of something')
            af.setVideoGeoreference( 10.4344, 63.4181, 150.60)

            self.assertFalse(af.validate())
        self.assertFalse(Aptofile.validateFile(f))
Example #5
0
    def testPoint(self):
        f = 'tests/point.apt'
        with Aptofile.create(f,'point') as af:
            af.setGenerator('aptfile.py','Aptomar AS')
            af.setDescription('This is a description of the point.')
            af.setPointName('The Point')
            af.setPointDescription('This is a description of a point.')
            af.setPointType('boat')
            af.setPointGeometry('data:data_describing_the_point')

            self.assertTrue(af.validate())
        self.assertTrue(Aptofile.validateFile(f))
Example #6
0
    def testVideoFileNotFound(self):
        f = 'tests/video_file_not_found.apt'
        with Aptofile.create(f,'video') as af:
            af.setGenerator(program='aptfile.py',creator='Aptomar AS')
            af.setDescription('This is a description of the video')
            af.setVideoName('The video name')
            af.setVideoDescription('A video of something')
            af.setVideoGeoreference( 10.4344, 63.4181, 150.60)

            af.manifest['video']['data']=['video.avi']
            self.assertFalse(af.validate())
        self.assertFalse(Aptofile.validateFile(f))
Example #7
0
    def testPointInvalidType(self):
        f = 'tests/point_invalid_type.apt'
        with Aptofile.create(f,'point') as af:
            af.setGenerator('aptfile.py','Aptomar AS')
            af.setDescription('This is a description of the point.')
            af.setPointName('The Point')
            af.setPointDescription('This is a description of a point.')
            af.setPointType('boat')
            af.setPointGeometry('data:data_describing_the_point')

            self.assertTrue(af.validate())
            af.manifest['point']['object-type'] = 'UFO'
        self.assertFalse(Aptofile.validateFile(f))
Example #8
0
 def testImageMissingFileAndGenerator(self):
     f = 'tests/image_missing_file_and_generator.apt'
     with Aptofile.create(f,'image') as af:
         af.setGenerator(program='aptfile.py',creator='Aptomar AS')
         af.setDescription('This is a description of the image')
         af.setImageName('The image name')
         af.setImageDescription('An image of something')
         af.setImageGeoreference( 10.4344, 63.4181, 150.60)
         af.setImageBounds(['data:,bounds as a string'])
         af.manifest['image']['data']=['image.jpg']
         del af.manifest['generator']
         self.assertFalse(af.validate())
     self.assertFalse(Aptofile.validateFile(f))
Example #9
0
    def testImage(self):
        f = 'tests/image.apt'
        with Aptofile.create(f,'image') as af:
            af.setGenerator(program='aptfile.py',creator='Aptomar AS')
            af.setDescription('This is a description of the image')
            af.setImageName('The image name')
            af.setImageDescription('An image of something')
            af.setImageGeoreference( 10.4344, 63.4181, 150.60)
            af.setImageBounds(['data:,bounds as a string'])
            af.addImageFile(('tests/image/image.jpg','image.jpg'))

            self.assertTrue(af.validate())

        self.assertTrue(Aptofile.validateFile(f))
Example #10
0
    def testDeleteFile(self):
        with Aptofile.open(testfile) as af:
            if not af.validate():
                raise Exception(str(af.getFailedTests()))

            self.register(af)
            self.geoupload.uploadToStore(af)
            self.geoupload.deleteFile(af)

        self.checkRemoved(resources=False)
Example #11
0
    def testAssetIncorrectDataType(self):
        f = 'tests/asset_incorrect_data_type.apt'
        with Aptofile.create(f,'asset') as af:
            af.setDescription("This is a description of the asset.")
            af.setGenerator("aptfile.py", "Aptomar AS")
            af.addLayer('layer1', name='layer1-name',
                        geometry_data=[('tests/asset/layers/layer1.dbf',
                                        'layers/layer1.dbf'),
                                       ('tests/asset/layers/layer1.shp',
                                        'layers/layer1.shp'),
                                       ('tests/asset/layers/layer1.shx',
                                        'layers/layer1.shx')])
            af.addFile2Layer(('tests/asset/styles/layer1.xml',
                             'styles/layer1.xml'), 'layer1', 'style')
            af.addFile2Layer(('tests/asset/resource1.png','resource1.png'),
                             'layer1', 'resources')
            af.addFile2Layer(('tests/asset/resource2.png','resource2.png'),
                             'layer1', 'resources')
            af.addLayer('layer2',name='layer2-name')
            af.addFile2Layer('layers/layer1.shp', 'layer2',
                             'geometry', writeFile=False)
            af.addFile2Layer('layers/layer1.dbf', 'layer2',
                             'geometry', writeFile=False)
            af.addFile2Layer('layers/layer1.shx', 'layer2',
                             'geometry', writeFile=False)
            af.addFile2Layer('layers/layer1.shp', 'layer2',
                             'geometry', writeFile=False)
            af.addFile2Layer('styles/layer1.xml','layer2',
                             'style', writeFile=False)
            af.addFile2Layer('resource1.png','layer2','resources', writeFile=False)
            af.addFile2Layer('resource2.png','layer2','resources', writeFile=False)
            af.addFile2Layer('http://very-big-file.com/','layer2','resources', writeFile=True)
            af.addGroup('group1','group1-name',['layer1'])
            af.addGroup('group2','group2-name',['layer2'])

            #Validate before write:
            self.assertTrue(af.validate())
            d=af.manifest['asset']['layers']['layer1']['style']['data'].pop()
            af.manifest['asset']['layers']['layer1']['style']['data'] = d

        #Validate after write and open
        self.assertFalse(Aptofile.validateFile(f))
Example #12
0
    def testUpload(self):
        with Aptofile.open(testfile) as af:
            if not af.validate():
                raise Exception(str(af.getFailedTests()))

            self.register(af)
            self.geoupload.uploadToStore(af)

        self.checkUploads()
        self.cleanup()
        self.checkRemoved()
Example #13
0
#! /usr/bin/python

################################################################
#                                                              #
# validateFile.py                                              #
# Copyright (c) 2013 Aptomar AS, All Rights Reserved           #
#                                                              #
# Author: Jarle Bauck Hamar: <*****@*****.**>         #
# Date: 2013-05-23                                             #
#                                                              #
################################################################

import argparse

from aptofile import Aptofile
parser = argparse.ArgumentParser(description="Tool for validating Aptofiles")
parser.add_argument('filename', help="name of aptofile to be validated")
args = parser.parse_args()

f = args.filename
print "Checking file '%s'... "%f,
with Aptofile.open(f) as af:
    if not af.validate():
        print "failed!"
        for test, msg in af.getFailedTests():
            print "Test '%s' failed: %s"%(test,msg)
    else: print "ok"