def test_empty_format_headers(self): xml = graph.serialize(format='xml') accepts = '' response = output(graph, accepts) self.assertEqual('application/rdf+xml', response.headers['content-type']) self.assertEqual('Accept', response.headers['vary'])
def test_format_tuple(self): turtle = graph.serialize(format='turtle') view = (graph, 202) accepts = 'text/n3;q=0.5, text/turtle;q=0.9' response = output(view, accepts) self.assertEqual(turtle, response.get_data()) self.assertEqual('text/turtle; charset=utf-8', response.headers['content-type']) self.assertEqual(202, response.status_code)
def test_format_quads_lowprio(self): """ Test that quads are not used even if possible """ g = ctx_graph quads = g.serialize(format='turtle') view = (g, 202) accepts = 'text/turtle;q=0.9, application/n-quads;q=0.4' response = output(view, accepts) self.assertEqual(quads, response.get_data()) self.assertEqual('text/turtle; charset=utf-8', response.headers['content-type']) self.assertEqual(202, response.status_code)
def test_format_quads_context(self): g = ctx_graph self.assertTrue(g.context_aware) quads = g.serialize(format='nquads') view = (g, 202) accepts = 'application/n-quads;q=0.9' response = output(view, accepts) self.assertEqual(quads, response.get_data()) self.assertEqual('application/n-quads', response.headers['content-type']) self.assertEqual(202, response.status_code)
def test_format_quads_unavailable(self): """ Test that quads are not used with contextless store """ g = graph quads = g.serialize(format='turtle') view = (g, 202) accepts = 'text/turtle;q=0.4, application/n-quads;q=0.9' response = output(view, accepts) self.assertEqual(quads, response.get_data()) self.assertEqual('text/turtle; charset=utf-8', response.headers['content-type']) self.assertEqual(202, response.status_code)
def test_format_quads_highprio(self): """ Test that quads are used with alternative """ g = ctx_graph quads = g.serialize(format='nquads') view = (g, 202) accepts = 'text/turtle;q=0.4, application/n-quads;q=0.9' response = output(view, accepts) self.assertEqual(quads, response.get_data()) self.assertEqual('application/n-quads', response.headers['content-type']) self.assertEqual(202, response.status_code)
def test_format_headers(self): turtle = graph.serialize(format='turtle') view = (graph, 203, {'x-custom': '12'}) accepts = 'text/n3;q=0.5, text/turtle;q=0.9' response = output(view, accepts) self.assertEqual(turtle, response.get_data()) self.assertEqual('text/turtle; charset=utf-8', response.headers['content-type']) self.assertEqual('Accept', response.headers['vary']) self.assertEqual('12', response.headers['x-custom']) self.assertEqual(203, response.status_code)
def test_unicode(self): mygraph = graph mygraph.add((BNode(), FOAF.name, Literal('\u2603'))) turtle = mygraph.serialize(format='turtle') accepts = 'text/turtle' response = output(mygraph, accepts) data = response.get_data() datastr = data.decode('utf-8') self.assertEqual(turtle, response.get_data()) self.assertEqual('text/turtle; charset=utf-8', response.headers['content-type']) self.assertEqual(200, response.status_code) self.assertTrue('\u2603' in datastr)
def test_text(self): test_str = 'This is a test string' accepts = 'text/n3;q=0.5, text/turtle;q=0.9' response = output(test_str, accepts) self.assertEqual(test_str, response)
def test_empty_format_headers(self): xml = graph.serialize(format='xml') accepts = '' response = output(graph, accepts) self.assertEqual('application/rdf+xml', response.headers['content-type'])