<s> import json <EOL> import os <EOL> import geojson <EOL> os . environ [ '<STR_LIT>' ] = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> from tests import base <EOL> def setUpModule ( ) : <EOL> """<STR_LIT>""" <EOL> base . enabledPlugins . append ( '<STR_LIT>' ) <EOL> base . enabledPlugins . append ( '<STR_LIT>' ) <EOL> base . enabledPlugins . append ( '<STR_LIT>' ) <EOL> base . enabledPlugins . append ( '<STR_LIT>' ) <EOL> base . startServer ( False ) <EOL> def tearDownModule ( ) : <EOL> """<STR_LIT>""" <EOL> base . stopServer ( ) <EOL> class DatasetTestCase ( base . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( DatasetTestCase , self ) . setUp ( ) <EOL> self . _user = self . model ( '<STR_LIT:user>' ) . createUser ( <EOL> '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' , '<STR_LIT:user>' , <EOL> '<STR_LIT>' ) <EOL> def testDataset ( self ) : <EOL> """<STR_LIT>""" <EOL> path = '<STR_LIT>' <EOL> params = { <EOL> '<STR_LIT>' : self . _user [ '<STR_LIT>' ] , <EOL> } <EOL> response = self . request ( path = path , method = '<STR_LIT:GET>' , params = params ) <EOL> self . assertStatusOk ( response ) <EOL> folder = response . json [ '<STR_LIT>' ] <EOL> self . assertEquals ( folder , None ) <EOL> response = self . request ( path = path , method = '<STR_LIT:POST>' , params = params ) <EOL> self . assertStatus ( response , <NUM_LIT> ) <EOL> response = self . request ( path = path , method = '<STR_LIT:POST>' , params = params , user = self . _user ) <EOL> self . assertStatusOk ( response ) <EOL> folder = response . json [ '<STR_LIT>' ] <EOL> self . assertNotEquals ( folder , None ) <EOL> self . assertEquals ( folder [ '<STR_LIT>' ] , '<STR_LIT:user>' ) <EOL> self . assertEquals ( folder [ '<STR_LIT>' ] , str ( self . _user [ '<STR_LIT>' ] ) ) <EOL> response = self . request ( path = path , method = '<STR_LIT:GET>' , params = params ) <EOL> self . assertStatusOk ( response ) <EOL> folder = response . json [ '<STR_LIT>' ] <EOL> self . assertEquals ( folder , None ) <EOL> response = self . request ( path = path , method = '<STR_LIT:GET>' , params = params , user = self . _user ) <EOL> self . assertStatusOk ( response ) <EOL> folder = response . json [ '<STR_LIT>' ] <EOL> self . assertNotEquals ( folder , None ) <EOL> self . assertEquals ( folder [ '<STR_LIT>' ] , '<STR_LIT:user>' ) <EOL> self . assertEquals ( folder [ '<STR_LIT>' ] , str ( self . _user [ '<STR_LIT>' ] ) ) <EOL> params = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : folder [ '<STR_LIT>' ] <EOL> } <EOL> response = self . request ( path = '<STR_LIT>' , method = '<STR_LIT:POST>' , params = params , <EOL> user = self . _user ) <EOL> item1Id = response . json [ '<STR_LIT>' ] <EOL> params = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : folder [ '<STR_LIT>' ] <EOL> } <EOL> response = self . request ( path = '<STR_LIT>' , method = '<STR_LIT:POST>' , params = params , <EOL> user = self . _user ) <EOL> item2Id = response . json [ '<STR_LIT>' ] <EOL> path = '<STR_LIT>' <EOL> params = { <EOL> '<STR_LIT>' : self . _user [ '<STR_LIT>' ] , <EOL> } <EOL> response = self . request ( path = path , method = '<STR_LIT:GET>' , params = params ) <EOL> self . assertStatusOk ( response ) <EOL> self . assertEquals ( len ( response . json ) , <NUM_LIT:0> ) <EOL> response = self . request ( path = path , method = '<STR_LIT:GET>' , params = params , user = self . _user ) <EOL> self . assertStatusOk ( response ) <EOL> self . assertEquals ( len ( response . json ) , <NUM_LIT:2> ) <EOL> datasetIds = [ d [ '<STR_LIT>' ] for d in response . json ] <EOL> self . assertTrue ( item1Id in datasetIds , "<STR_LIT>" ) <EOL> self . assertTrue ( item2Id in datasetIds , "<STR_LIT>" ) <EOL> def createDataset ( itemname , files , error = None ) : <EOL> params = { <EOL> '<STR_LIT:name>' : itemname , <EOL> '<STR_LIT>' : folder [ '<STR_LIT>' ] <EOL> } <EOL> response = self . request ( path = '<STR_LIT>' , method = '<STR_LIT:POST>' , params = params , user = self . _user ) <EOL> self . assertStatusOk ( response ) <EOL> itemId = response . json [ '<STR_LIT>' ] <EOL> for itemfile in files : <EOL> filename = itemfile [ '<STR_LIT:name>' ] <EOL> filepath = itemfile [ '<STR_LIT:path>' ] <EOL> mimeType = itemfile [ '<STR_LIT>' ] <EOL> sizeBytes = os . stat ( filepath ) . st_size <EOL> response = self . request ( <EOL> path = '<STR_LIT>' , <EOL> method = '<STR_LIT:POST>' , <EOL> user = self . _user , <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : itemId , <EOL> '<STR_LIT:name>' : filename , <EOL> '<STR_LIT:size>' : sizeBytes , <EOL> '<STR_LIT>' : mimeType <EOL> } <EOL> ) <EOL> self . assertStatusOk ( response ) <EOL> uploadId = response . json [ '<STR_LIT>' ] <EOL> with open ( filepath , '<STR_LIT:rb>' ) as file : <EOL> filedata = file . read ( ) <EOL> response = self . multipartRequest ( <EOL> path = '<STR_LIT>' , <EOL> user = self . _user , <EOL> fields = [ ( '<STR_LIT>' , <NUM_LIT:0> ) , ( '<STR_LIT>' , uploadId ) ] , <EOL> files = [ ( '<STR_LIT>' , filename , filedata ) ] <EOL> ) <EOL> path = '<STR_LIT>' . format ( itemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:POST>' , <EOL> user = self . _user , <EOL> ) <EOL> if error is not None : <EOL> self . assertStatus ( response , error ) <EOL> else : <EOL> self . assertStatusOk ( response ) <EOL> return response . json , itemId <EOL> pluginTestDir = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> files = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : os . path . join ( pluginTestDir , '<STR_LIT:data>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> geojsonDatasetItem , itemId = createDataset ( '<STR_LIT>' , files ) <EOL> minervaMetadata = geojsonDatasetItem [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertEquals ( minervaMetadata [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEquals ( minervaMetadata [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> files = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : os . path . join ( pluginTestDir , '<STR_LIT:data>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' <EOL> } ] <EOL> jsonDatasetItem , jsonItemId = createDataset ( '<STR_LIT>' , files ) <EOL> jsonMinervaMetadata = jsonDatasetItem [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertEquals ( jsonMinervaMetadata [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> files = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : os . path . join ( pluginTestDir , '<STR_LIT:data>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> csvDatasetItem , csvItemId = createDataset ( '<STR_LIT>' , files ) <EOL> csvMinervaMetadata = csvDatasetItem [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertEquals ( csvMinervaMetadata [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> files = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : os . path . join ( pluginTestDir , '<STR_LIT:data>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> otherDatasetItem , itemId = createDataset ( '<STR_LIT>' , files ) <EOL> path = '<STR_LIT>' . format ( jsonItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:POST>' , <EOL> user = self . _user , <EOL> ) <EOL> self . assertHasKeys ( response . json , [ '<STR_LIT>' ] ) <EOL> self . assertHasKeys ( response . json [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ) <EOL> path = '<STR_LIT>' . format ( jsonItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:GET>' , <EOL> user = self . _user , <EOL> ) <EOL> metadata = response . json <EOL> jsonMinervaMetadata [ "<STR_LIT>" ] = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> metadata [ '<STR_LIT>' ] = jsonMinervaMetadata <EOL> path = '<STR_LIT>' . format ( jsonItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT>' , <EOL> user = self . _user , <EOL> body = json . dumps ( metadata ) , <EOL> type = '<STR_LIT:application/json>' <EOL> ) <EOL> metadata = response . json <EOL> path = '<STR_LIT>' . format ( jsonItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:POST>' , <EOL> user = self . _user , <EOL> ) <EOL> self . assertHasKeys ( response . json , [ '<STR_LIT>' ] ) <EOL> geojsonFileId = response . json [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> path = '<STR_LIT>' . format ( geojsonFileId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:GET>' , <EOL> user = self . _user , <EOL> isJson = False <EOL> ) <EOL> geojsonContents = self . getBody ( response ) <EOL> twopointsGeojson = geojson . loads ( geojsonContents ) <EOL> self . assertEquals ( len ( twopointsGeojson [ '<STR_LIT>' ] ) , <NUM_LIT:2> , '<STR_LIT>' ) <EOL> features = twopointsGeojson [ '<STR_LIT>' ] <EOL> for feature in features : <EOL> coordinates = feature [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertTrue ( - <NUM_LIT> < coordinates [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertTrue ( - <NUM_LIT> > coordinates [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertTrue ( <NUM_LIT:20> < coordinates [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertTrue ( <NUM_LIT:30> > coordinates [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> path = '<STR_LIT>' . format ( csvItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:GET>' , <EOL> user = self . _user , <EOL> ) <EOL> metadata = response . json <EOL> csvMinervaMetadata [ "<STR_LIT>" ] = { <EOL> "<STR_LIT>" : "<STR_LIT:2>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" <EOL> } <EOL> metadata [ '<STR_LIT>' ] = csvMinervaMetadata <EOL> path = '<STR_LIT>' . format ( csvItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT>' , <EOL> user = self . _user , <EOL> body = json . dumps ( metadata ) , <EOL> type = '<STR_LIT:application/json>' <EOL> ) <EOL> metadata = response . json <EOL> path = '<STR_LIT>' . format ( csvItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:POST>' , <EOL> user = self . _user , <EOL> ) <EOL> self . assertStatus ( response , <NUM_LIT> ) <EOL> files = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : os . path . join ( pluginTestDir , '<STR_LIT:data>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' <EOL> } ] <EOL> tweetDatasetItem , tweetItemId = createDataset ( '<STR_LIT>' , files ) <EOL> tweetMinervaMetadata = tweetDatasetItem [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertEquals ( tweetMinervaMetadata [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> path = '<STR_LIT>' . format ( tweetItemId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:POST>' , <EOL> user = self . _user , <EOL> ) <EOL> jsonFileId = response . json [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> path = '<STR_LIT>' . format ( jsonFileId ) <EOL> response = self . request ( <EOL> path = path , <EOL> method = '<STR_LIT:GET>' , <EOL> user = self . _user , <EOL> isJson = False <EOL> ) <EOL> jsonContents = self . getBody ( response ) <EOL> contents = json . loads ( jsonContents ) <EOL> self . assertEquals ( len ( contents ) , <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . assertHasKeys ( contents [ <NUM_LIT:0> ] , [ '<STR_LIT:location>' ] ) <EOL> self . assertHasKeys ( contents [ <NUM_LIT:0> ] [ '<STR_LIT:location>' ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) </s>
