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