1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
# 20051228 *pike
# 20050628 *pike
# very simple example scripts for pySesame
# this does the same as tests.py, but in a human way.
import pySesame
# CONFIG ---------------------
# select an *empty* test database, plain rdf sail
# on which the user has read and write access
url = 'http://localhost:8080'
path = '/sesame/'
user = 'yourusername'
password = 'youruserpassword'
repository = 'yourrepositoryid'
# toggle tests to perform
tests = {}
tests["anon"] = True
tests["login"] = True
tests["clear"] = True
tests["upload"] = True
tests["uploadbroken"] = True
tests["uploadurl"] = True
tests["extract"] = True
tests["rdql"] = True
tests["rdqlrdf"] = True
tests["serqls"] = True
tests["serqlc"] = True
tests["remove"] = True
# ----------------------------
#import some example data
from tests_data import w3c, w3cRemoved, w3cResult, postURL
from tests_data import serqlSQuery, serqlCQuery, rdqlQuery, rdqlQueryResult
from tests_data import rdqlQueryRDF, serqlCQueryRDF, postcon
print "Note: \nmake sure your repository (%s@%s%s) is *empty*. \nIt will be trashed during the tests."%(repository,url,path)
if tests["anon"]:
resp = raw_input("\nNext test: anonymous login. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
# test some features on anonymous acces
print 24*'='
print 'Testing anonymous connection'
connection = pySesame.SesameConnection(url, path, 'debug')
repos = connection.repositories()
print 'There are %s repositories available for the anonymous user:'%len(repos)
print "\tsesame id\t:read\t:write\t:title"
for repo in repos:
print "\t%(id)s\t:%(readable)s\t:%(writeable)s\t:%(title)s"%repo
print 'closing anonymous connection'
connection.close()
# test login / logoff
if tests["login"]:
resp = raw_input("\nNext test: login / logoff. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'Testing login connection'
connection = pySesame.SesameConnection(url, path, 'debug')
connection.login(user, password)
print 'received sessionid %s '%connection.cookie
repos = connection.repositories()
print 'There are %s repositories available for user %s:'%(len(repos),user)
print "\tsesame id\t:read\t:write\t:title"
for repo in repos:
print "\t%(id)s\t:%(readable)s\t:%(writeable)s\t:%(title)s"%repo
print 'logging out'
connection.logout()
print 'closing sesame connection .. which is useless because I already logged out'
connection.close()
# more tests require logging in
resp = raw_input("\nNext test: clear. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print
print 'loggin in again, for the next set of tests:'
connection = pySesame.SesameConnection(url, path, 'debug')
connection.login(user, password)
if tests["clear"]:
print 24*'='
print 'Testing clearing repo %s'%repository
connection.clear(repository)
print "....ok"
if tests["upload"]:
resp = raw_input("\nNext test: upload. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'Testing uploading good rdf'
connection.uploadData(repository, postcon)
print 'good, clearing repo %s'%repository
connection.clear(repository)
if tests["uploadbroken"]:
resp = raw_input("\nNext test: uploadbroken. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'Testing uploading broken rdf'
try:
connection.uploadData(repository,postcon[:100])
print 'bad ! .. I didn\'t get get an error ?'
except:
print 'good !.. I got an error :)'
if tests["uploadurl"]:
resp = raw_input("\nNext test: uploadurl. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'Testing uploading from url'
connection.uploadURL(repository, postURL)
print 'good, clearing repo %s'%repository
connection.clear(repository)
if tests["extract"]:
resp = raw_input("\nNext test: extract. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'Testing extracting the repo'
print 'uploading----------'
print w3c
connection.uploadData(repository, w3c)
result = connection.extract(repository, 'on', 'on')
print '--------------------'
if result!=w3cResult:
print "unexpected result ? ----------"
print result
print '--------------------'
else:
print "ok"
print 'clearing repo %s'%repository
connection.clear(repository)
if tests["rdql"]:
resp = raw_input("\nNext test: rdql. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'testing rdqlquery with table result'
print 'uploading some dummy data ..'
connection.uploadData(repository, postcon)
print 'submitting query----------'
print rdqlQuery
result = connection.tableQuery(repository, 'RDQL', rdqlQuery)
if result != rdqlQueryResult:
print "unexpected result ? ----------"
print result
print '--------------------'
else:
print "ok"
print 'clearing repo %s'%repository
connection.clear(repository)
if tests["rdqlrdf"]:
resp = raw_input("\nNext test: rdqlrdf. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'testing rdqlquery with rdf result'
print 'uploading some dummy data ..'
connection.uploadData(repository, postcon)
print 'submitting query----------'
print rdqlQuery
result = connection.tableQuery(repository, 'RDQL', rdqlQuery,'rdf', 'rdfxml')
if result != rdqlQueryRDF:
print "unexpected result ? ----------"
print result
print '--------------------'
else:
print "ok"
print 'clearing repo %s'%repository
connection.clear(repository)
if tests["serqls"]:
resp = raw_input("\nNext test: serqls. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'testing serql select query'
print 'uploading some dummy data ..'
connection.uploadData(repository, postcon)
print 'submitting query----------'
print serqlSQuery
result = connection.tableQuery(repository, 'SeRQL', serqlSQuery)
if result != rdqlQueryResult:
print "unexpected result ? ----------"
print result
print '--------------------'
else:
print "ok"
print 'clearing repo %s'%repository
connection.clear(repository)
if tests["serqlc"]:
resp = raw_input("\nNext test: serqlc. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'testing serql construct query'
print 'uploading some dummy data ..'
connection.uploadData(repository, postcon)
print 'submitting query----------'
print serqlCQuery
result = connection.graphQuery(repository, 'SeRQL', serqlCQuery, 'rdfxml')
if result != serqlCQueryRDF:
print "unexpected result ? ----------"
print result
print '--------------------'
else:
print "ok"
print 'clearing repo %s'%repository
connection.clear(repository)
if tests["remove"]:
resp = raw_input("\nNext test: remove. Continue? [Y/n] ")
if (resp.lower()=='n'): exit()
print 24*'='
print 'testing remove query'
print 'uploading some dummy data ..'
connection.uploadData(repository, w3c)
print 'submitting query----------'
connection.remove(repository, '<http://www.w3.org/>',
'<http://purl.org/dc/elements/1.1/title>',
'"World Wide Web Consortium"')
result = connection.extract(repository, 'on', 'on')
if result != w3cRemoved:
print "unexpected result ? ----------"
print result
print '--------------------'
else:
print "ok"
print 'clearing repo %s'%repository
connection.clear(repository)
connection.close()
|