示例#1
0
def service_rdfa_content_type_test():
    '''Test of RDFa content type header for service invocation.'''
    i = '''<div xmlns="http://www.w3.org/1999/xhtml"
  prefix="
    foaf: http://xmlns.com/foaf/0.1/
    ns1: http://sadiframework.org/examples/hello.owl#
    rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
    rdfs: http://www.w3.org/2000/01/rdf-schema#"
  >
  <div typeof="ns1:NamedIndividual" about="http://tw.rpi.edu/instances/JamesMcCusker">
    <div property="foaf:name" content="Jim McCusker"></div>
  </div>
</div>'''
    c = sadi.setup_test_client(resource)
    resp = c.post('/',
                  data=i,
                  headers={
                      'Content-Type': 'text/html',
                      'Accept': 'text/turtle'
                  })
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(unicode(resp.data)), format='turtle')
    print resp.data
    assert len(g) > 0
示例#2
0
def service_get_attachment_test():
    '''Test of a SADI service that GETs data from an attachment.'''
    testInput = unicode('''--gc0p4Jq0M2Yt08jU534c0p
Content-Type: text/turtle

<http://www.google.com> a <http://www.w3.org/2002/07/owl#Thing>. 
--gc0p4Jq0M2Yt08jU534c0p
Content-Type:text/html
Content-Disposition: attachment; filename="http://www.google.com"

<html><head><title>Welcome to Google.</title></head><body><h1>Hello, World!</h1></body></html>'''
                        )
    c = sadi.setup_test_client(valuator)
    resp = c.post('/',
                  data=testInput,
                  headers={
                      'Content-Type':
                      'multipart/related; boundary=gc0p4Jq0M2Yt08jU534c0p',
                      'Accept': '*/*'
                  })
    assert resp.status_code == 200
    g = Graph()
    print resp.data
    assert '<html><head><title>Welcome to Google.</title></head><body><h1>Hello, World!</h1></body></html>' in resp.data
    g.parse(StringIO(unicode(resp.data)), format="turtle")
    assert len(g) > 0
示例#3
0
def service_JSON_accept_content_type_test():
    '''Test of JSON accept and content type headers for service invocation.'''
    i = '''{
  "http://tw.rpi.edu/instances/JamesMcCusker": {
    "http://xmlns.com/foaf/0.1/name": [
      {
        "type": "literal", 
        "value": "Jim McCusker"
      }
    ], 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [
      {
        "type": "uri", 
        "value": "http://sadiframework.org/examples/hello.owl#NamedIndividual"
      }
    ]
  }
}'''
    c = sadi.setup_test_client(resource)
    resp = c.post('/',
                  data=i,
                  headers={
                      'Content-Type': 'application/json',
                      'Accept': 'application/json'
                  })
    assert resp.status_code == 200
    g = Graph()
    print resp.data
    s = JSONSerializer()
    s.deserialize(g, resp.data, "application/json")
    assert len(g) > 0
示例#4
0
def service_accept_content_types_test():
    '''Test of accept and content type headers for service invocation.'''
    inputGraph = Graph()
    inputGraph.parse(StringIO(
        unicode(
            '''<http://tw.rpi.edu/instances/JamesMcCusker> <http://xmlns.com/foaf/0.1/name> "Jim McCusker";
     a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. ''')),
                     format="turtle")
    c = sadi.setup_test_client(resource)

    def fn(mimetype, f, of):
        resp = c.post('/',
                      data=inputGraph.serialize(format=f),
                      headers={
                          'Content-Type': mimetype,
                          'Accept': mimetype
                      })
        assert resp.status_code == 200
        g = Graph()
        print resp.data
        g.parse(StringIO(unicode(resp.data)), format=of)
        assert len(g) > 0

    for mimetype, f, of in supported_mimetypes:
        yield fn, mimetype, f, of
示例#5
0
文件: tests.py 项目: jimmccusker/sadi
def service_JSON_accept_content_type_test():
    '''Test of JSON accept and content type headers for service invocation.'''
    i = '''{
  "http://tw.rpi.edu/instances/JamesMcCusker": {
    "http://xmlns.com/foaf/0.1/name": [
      {
        "type": "literal", 
        "value": "Jim McCusker"
      }
    ], 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [
      {
        "type": "uri", 
        "value": "http://sadiframework.org/examples/hello.owl#NamedIndividual"
      }
    ]
  }
}'''
    c = sadi.setup_test_client(resource)
    resp = c.post('/',data=i,
                  headers={'Content-Type':'application/json','Accept':'application/json'})
    assert resp.status_code == 200
    g = Graph()
    print(resp.data)
    s = JSONSerializer()
    s.deserialize(g,resp.data,"application/json")
    assert len(g) > 0
示例#6
0
def oddball_accept_descriptor_test():
    '''Test of sending an oddball accept header.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/', headers={'Accept': 'image/png'})
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(unicode(resp.data)), format="xml")
    assert len(g) > 0
示例#7
0
def no_accept_header_test():
    '''Test to make sure that SADI services will work even if the Accept header isn't included.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/')
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(unicode(resp.data)), format="xml")
    assert len(g) > 0
示例#8
0
文件: tests.py 项目: jimmccusker/sadi
def no_accept_header_test():
    '''Test to make sure that SADI services will work even if the Accept header isn't included.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/')
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(str(resp.data)),format="xml")
    assert len(g) > 0
示例#9
0
文件: tests.py 项目: jimmccusker/sadi
def oddball_accept_descriptor_test():
    '''Test of sending an oddball accept header.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/',headers={'Accept':'image/png'})
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(str(resp.data)),format="xml")
    assert len(g) > 0
示例#10
0
def descriptor_test():
    '''Basic test of getting a service description from a SADI service.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/', headers={'Accept': '*/*'})
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(unicode(resp.data)), format="turtle")
    assert len(g) > 0
示例#11
0
文件: tests.py 项目: jimmccusker/sadi
def descriptor_test():
    '''Basic test of getting a service description from a SADI service.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/',headers={'Accept':'*/*'})
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(str(resp.data)),format="turtle")
    assert len(g) > 0
示例#12
0
文件: tests.py 项目: jimmccusker/sadi
def non_allowed_methods_test():
    '''Test of non-allowed methods.'''
    c = sadi.setup_test_client(resource)
    resp = c.put('/',headers={'Accept':'*/*'})
    assert resp.status_code == 405
    resp = c.delete('/',headers={'Accept':'*/*'})
    assert resp.status_code == 405
    resp = c.head('/',headers={'Accept':'*/*'})
    assert resp.status_code == 405
示例#13
0
def non_allowed_methods_test():
    '''Test of non-allowed methods.'''
    c = sadi.setup_test_client(resource)
    resp = c.put('/', headers={'Accept': '*/*'})
    assert resp.status_code == 405
    resp = c.delete('/', headers={'Accept': '*/*'})
    assert resp.status_code == 405
    resp = c.head('/', headers={'Accept': '*/*'})
    assert resp.status_code == 405
示例#14
0
文件: tests.py 项目: jimmccusker/sadi
def service_get_no_attachment_test():
    '''Test of a SADI service that GETs data from the web.'''
    testInput = str('''<http://www.google.com> a <http://www.w3.org/2002/07/owl#Thing>. ''')
    c = sadi.setup_test_client(valuator)
    resp = c.post('/',data=testInput, headers={'Content-Type':'text/turtle','Accept':'*/*'})
    assert resp.status_code == 200
    g = Graph()
    print(resp.data)
    g.parse(StringIO(str(resp.data)),format="turtle")
    assert len(g) > 0
示例#15
0
文件: tests.py 项目: jimmccusker/sadi
def json_descriptor_test():
    '''Basic test of getting a service description in JSON from a SADI service.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/',headers={'Accept':'application/json'})
    assert resp.status_code == 200
    g = Graph()
    print(resp.data)
    s = JSONSerializer()
    s.deserialize(g,resp.data,"application/json")
    assert len(g) > 0
示例#16
0
def json_descriptor_test():
    '''Basic test of getting a service description in JSON from a SADI service.'''
    c = sadi.setup_test_client(resource)
    resp = c.get('/', headers={'Accept': 'application/json'})
    assert resp.status_code == 200
    g = Graph()
    print resp.data
    s = JSONSerializer()
    s.deserialize(g, resp.data, "application/json")
    assert len(g) > 0
示例#17
0
文件: tests.py 项目: jimmccusker/sadi
def service_test():
    '''Basic test of using a SADI service.'''
    testInput = str('''<http://tw.rpi.edu/instances/JamesMcCusker> <http://xmlns.com/foaf/0.1/name> "Jim McCusker";
     a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. ''')
    c = sadi.setup_test_client(resource)
    resp = c.post('/',data=testInput, headers={'Content-Type':'text/turtle','Accept':'*/*'})
    assert resp.status_code == 200
    g = Graph()
    print(resp.data)
    g.parse(StringIO(str(resp.data)),format="turtle")
    assert len(g) > 0
示例#18
0
def oddball_accept_service_test():
    '''Test of sending an oddball accept header to a SADI service.'''
    testInput = unicode('''<http://tw.rpi.edu/instances/JamesMcCusker> <http://xmlns.com/foaf/0.1/name> "Jim McCusker";
     a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. ''')
    c = sadi.setup_test_client(resource)
    resp = c.post('/',data=testInput, headers={'Content-Type':'text/turtle','Accept':'image/png'})
    assert resp.status_code == 200
    g = Graph()
    print resp.data
    g.parse(StringIO(unicode(resp.data)),format="xml")
    assert len(g) > 0
示例#19
0
文件: tests.py 项目: jimmccusker/sadi
def descriptor_accept_types_test():
    '''Test of possible Accept mime types.'''
    c = sadi.setup_test_client(resource)
    def fn(mimetype,f,of):
        resp = c.get('/',headers={'Accept':mimetype})
        assert resp.status_code == 200
        g = Graph()
        print(resp.data)
        g.parse(StringIO(str(resp.data)),format=of)
        assert len(g) > 0
    for mimetype, f, of in supported_mimetypes:
        yield fn, mimetype, f, of
示例#20
0
def async_service_test():
    '''Basic test of using an asynchronous SADI service.'''
    testInput = unicode(
        '''<http://tw.rpi.edu/instances/JamesMcCusker> <http://xmlns.com/foaf/0.1/name> "Jim McCusker";
     a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. ''')
    c = sadi.setup_test_client(async_resource)
    resp = c.post('/',
                  data=testInput,
                  headers={
                      'Content-Type': 'text/turtle',
                      'Accept': '*/*'
                  })
    assert resp.status_code == 202
    g = Graph()
    g.parse(StringIO(unicode(resp.data)), format="turtle")
    jim = URIRef('http://tw.rpi.edu/instances/JamesMcCusker')
    idb = [x for x in g[jim:RDFS.isDefinedBy]]
    assert len(idb) == 1
    idb = idb[0]
    notDone = True
    while notDone:
        idb = make_relative(idb)
        print idb
        resp = c.get(idb, headers={'Accept': 'text/turtle'})
        if resp.status_code == 302:
            location = resp.headers['Location']
            try:
                loc = URIRef(location)
                idb = loc
            except:
                assert False
            try:
                pragma = get_pragmas(resp)
                wait = int(pragma['sadi-please-wait'])
                time.sleep(wait / 1000.0)
            except:
                print traceback.print_exc()
                assert False
        elif resp.status_code == 200:
            notDone = False
        else:
            raise Exception(str(resp))
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(unicode(resp.data)), format="turtle")
    assert len(g) > 0
    jim = URIRef('http://tw.rpi.edu/instances/JamesMcCusker')
    triples = [x for x in g[jim]]
    assert len(triples) > 0
    print g.serialize(format="turtle")
示例#21
0
def descriptor_accept_types_test():
    '''Test of possible Accept mime types.'''
    c = sadi.setup_test_client(resource)

    def fn(mimetype, f, of):
        resp = c.get('/', headers={'Accept': mimetype})
        assert resp.status_code == 200
        g = Graph()
        print resp.data
        g.parse(StringIO(unicode(resp.data)), format=of)
        assert len(g) > 0

    for mimetype, f, of in supported_mimetypes:
        yield fn, mimetype, f, of
示例#22
0
文件: tests.py 项目: jimmccusker/sadi
def service_unicode_test():
    '''Test of sending and recieving (parsing and serializing) unicode characters.'''
    inputGraph = Graph()
    inputGraph.parse(StringIO(u'<http://example.com/weirdname> <http://xmlns.com/foaf/0.1/name> "a\xac\u1234\u20ac\U00008000"; a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. '),format='turtle')
    c = sadi.setup_test_client(resource)
    def fn(mimetype,f,of):
        resp = c.post('/',data=inputGraph.serialize(format=f),
                      headers={'Content-Type':mimetype,'Accept':mimetype})
        assert resp.status_code == 200
        g = Graph()
        print(resp.data)
        g.parse(StringIO(str(resp.data,'utf-8')),format=of)
        assert len(g) > 0
    for mimetype, f, of in supported_mimetypes:
        yield fn, mimetype, f,of
示例#23
0
文件: tests.py 项目: jimmccusker/sadi
def service_accept_content_types_test():
    '''Test of accept and content type headers for service invocation.'''
    inputGraph = Graph()
    inputGraph.parse(StringIO(str('''<http://tw.rpi.edu/instances/JamesMcCusker> <http://xmlns.com/foaf/0.1/name> "Jim McCusker";
     a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. ''')),format="turtle")
    c = sadi.setup_test_client(resource)
    def fn(mimetype,f,of):
        resp = c.post('/',data=inputGraph.serialize(format=f),
                      headers={'Content-Type':mimetype,'Accept':mimetype})
        assert resp.status_code == 200
        g = Graph()
        print(resp.data)
        g.parse(StringIO(str(resp.data)),format=of)
        assert len(g) > 0
    for mimetype, f, of in supported_mimetypes:
        yield fn, mimetype, f,of
示例#24
0
def oddball_accept_service_test():
    '''Test of sending an oddball accept header to a SADI service.'''
    testInput = unicode(
        '''<http://tw.rpi.edu/instances/JamesMcCusker> <http://xmlns.com/foaf/0.1/name> "Jim McCusker";
     a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. ''')
    c = sadi.setup_test_client(resource)
    resp = c.post('/',
                  data=testInput,
                  headers={
                      'Content-Type': 'text/turtle',
                      'Accept': 'image/png'
                  })
    assert resp.status_code == 200
    g = Graph()
    print resp.data
    g.parse(StringIO(unicode(resp.data)), format="xml")
    assert len(g) > 0
示例#25
0
def service_get_no_attachment_test():
    '''Test of a SADI service that GETs data from the web.'''
    testInput = unicode(
        '''<http://www.google.com> a <http://www.w3.org/2002/07/owl#Thing>. '''
    )
    c = sadi.setup_test_client(valuator)
    resp = c.post('/',
                  data=testInput,
                  headers={
                      'Content-Type': 'text/turtle',
                      'Accept': '*/*'
                  })
    assert resp.status_code == 200
    g = Graph()
    print resp.data
    g.parse(StringIO(unicode(resp.data)), format="turtle")
    assert len(g) > 0
示例#26
0
文件: tests.py 项目: jimmccusker/sadi
def async_service_test():
    '''Basic test of using an asynchronous SADI service.'''
    testInput = str('''<http://tw.rpi.edu/instances/JamesMcCusker> <http://xmlns.com/foaf/0.1/name> "Jim McCusker";
     a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. ''')
    c = sadi.setup_test_client(async_resource)
    resp = c.post('/',data=testInput, headers={'Content-Type':'text/turtle','Accept':'*/*'})
    assert resp.status_code == 202
    g = Graph()
    g.parse(StringIO(str(resp.data)),format="turtle")
    jim = URIRef('http://tw.rpi.edu/instances/JamesMcCusker')
    idb = [x for x in g[jim:RDFS.isDefinedBy]]
    assert len(idb) == 1
    idb = idb[0]
    notDone = True
    while notDone:
        idb = make_relative(idb)
        print(idb)
        resp = c.get(idb,headers={'Accept':'text/turtle'})
        if resp.status_code == 302:
            location = resp.headers['Location']
            try:
                loc = URIRef(location)
                idb = loc
            except:
                assert False
            try:
                pragma = get_pragmas(resp)
                wait = int(pragma['sadi-please-wait'])
                time.sleep(wait/1000.0)
            except:
                print(traceback.print_exc())
                assert False
        elif resp.status_code == 200:
            notDone = False
        else:
            raise Exception(str(resp))
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(str(resp.data)),format="turtle")
    assert len(g) > 0
    jim = URIRef('http://tw.rpi.edu/instances/JamesMcCusker')
    triples = [x for x in g[jim]]
    assert len(triples) > 0
    print(g.serialize(format="turtle"))
示例#27
0
文件: tests.py 项目: jimmccusker/sadi
def service_get_attachment_test():
    '''Test of a SADI service that GETs data from an attachment.'''
    testInput = str('''--gc0p4Jq0M2Yt08jU534c0p
Content-Type: text/turtle

<http://www.google.com> a <http://www.w3.org/2002/07/owl#Thing>. 
--gc0p4Jq0M2Yt08jU534c0p
Content-Type:text/html
Content-Disposition: attachment; filename="http://www.google.com"

<html><head><title>Welcome to Google.</title></head><body><h1>Hello, World!</h1></body></html>''')
    c = sadi.setup_test_client(valuator)
    resp = c.post('/',data=testInput, headers={'Content-Type':'multipart/related; boundary=gc0p4Jq0M2Yt08jU534c0p',
                                               'Accept':'*/*'})
    assert resp.status_code == 200
    g = Graph()
    print(resp.data)
    assert '<html><head><title>Welcome to Google.</title></head><body><h1>Hello, World!</h1></body></html>' in resp.data
    g.parse(StringIO(str(resp.data)),format="turtle")
    assert len(g) > 0
示例#28
0
文件: tests.py 项目: jimmccusker/sadi
def service_rdfa_content_type_test():
    '''Test of RDFa content type header for service invocation.'''
    i='''<div xmlns="http://www.w3.org/1999/xhtml"
  prefix="
    foaf: http://xmlns.com/foaf/0.1/
    ns1: http://sadiframework.org/examples/hello.owl#
    rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
    rdfs: http://www.w3.org/2000/01/rdf-schema#"
  >
  <div typeof="ns1:NamedIndividual" about="http://tw.rpi.edu/instances/JamesMcCusker">
    <div property="foaf:name" content="Jim McCusker"></div>
  </div>
</div>'''
    c = sadi.setup_test_client(resource)
    resp = c.post('/',data=i,
                  headers={'Content-Type':'text/html','Accept':'text/turtle'})
    assert resp.status_code == 200
    g = Graph()
    g.parse(StringIO(str(resp.data)),format='turtle')
    print(resp.data)
    assert len(g) > 0
示例#29
0
def service_unicode_test():
    '''Test of sending and recieving (parsing and serializing) unicode characters.'''
    inputGraph = Graph()
    inputGraph.parse(StringIO(
        u'<http://example.com/weirdname> <http://xmlns.com/foaf/0.1/name> "a\xac\u1234\u20ac\U00008000"; a <http://sadiframework.org/examples/hello.owl#NamedIndividual>. '
    ),
                     format='turtle')
    c = sadi.setup_test_client(resource)

    def fn(mimetype, f, of):
        resp = c.post('/',
                      data=inputGraph.serialize(format=f),
                      headers={
                          'Content-Type': mimetype,
                          'Accept': mimetype
                      })
        assert resp.status_code == 200
        g = Graph()
        print resp.data
        g.parse(StringIO(unicode(resp.data, 'utf-8')), format=of)
        assert len(g) > 0

    for mimetype, f, of in supported_mimetypes:
        yield fn, mimetype, f, of