10
|
1 from pathlib import Path
|
11
|
2 import logging
|
10
|
3 import pytest
|
|
4
|
11
|
5 from examples._run_server_child import RunHttpServerChildProcess, assert_event_stream_starts_with
|
10
|
6
|
11
|
7 log = logging.getLogger('test')
|
|
8 logging.basicConfig(level=logging.INFO)
|
10
|
9 server_path = Path('examples/serve_inline_graph.py')
|
|
10
|
|
11
|
|
12 @pytest.mark.asyncio
|
|
13 async def test_server_returns_n3():
|
|
14 async with RunHttpServerChildProcess(server_path) as http_server:
|
|
15 response = await http_server.get('http://localhost:8005/g1')
|
|
16 assert (await response.text()
|
|
17 ) == '''@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
|
18
|
|
19 <http://example.com/process> {
|
|
20 <http://example.com/greeting> rdfs:label "hello world" .
|
|
21 }
|
|
22
|
|
23 '''
|
|
24
|
|
25
|
|
26 @pytest.mark.asyncio
|
|
27 async def test_server_returns_trig():
|
|
28 async with RunHttpServerChildProcess(server_path) as http_server:
|
|
29 response = await http_server.get(
|
|
30 'http://localhost:8005/g1',
|
|
31 headers={'accept': "application/n-quads"})
|
|
32 assert (
|
|
33 await response.text()
|
|
34 ) == '''<http://example.com/greeting> <http://www.w3.org/2000/01/rdf-schema#label> "hello world" <http://example.com/process> .
|
|
35
|
|
36 '''
|
|
37
|
|
38
|
11
|
39 @pytest.mark.asyncio
|
|
40 async def test_server_returns_startup_events():
|
|
41 async with RunHttpServerChildProcess(server_path) as http_server:
|
|
42 await assert_event_stream_starts_with(
|
|
43 http_server,
|
|
44 'http://localhost:8005/g1/events',
|
|
45 expected_events=[
|
|
46 ('clear', 'ferry1'),
|
|
47 ('patch',
|
|
48 '-\n+\n["http://example.com/greeting", "http://www.w3.org/2000/01/rdf-schema#label", "hello world", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/process"]'
|
|
49 ),
|
|
50 ])
|