return (proc, reader, writer)
+
async def tearDown(proc):
+ await asyncio.sleep(0.2)
+
proc.kill()
await proc.wait()
if os.path.exists(config):
os.remove(config)
+
async def test_registering_device(event_loop):
(proc, reader, writer) = await setUp(event_loop)
writer.write(b'PALAVER ADD MENTION-KEYWORD {nick}\r\n')
writer.write(b'PALAVER END\r\n')
await writer.drain()
- time.sleep(1)
await tearDown(proc)
+
async def test_loading_module_new_cap(event_loop):
await requires_znc_version('1.7.0')
line = await reader.readline()
assert line == b':*status!znc@znc.in PRIVMSG admin :Loaded module palaver: [test/fixtures/modules/palaver.so]\r\n'
- time.sleep(1)
-
await tearDown(proc)
+
async def test_unloading_module_del_cap(event_loop):
await requires_znc_version('1.7.0')
line = await reader.readline()
assert line == b':*status!znc@znc.in PRIVMSG admin :Module palaver unloaded.\r\n'
- time.sleep(1)
+ await tearDown(proc)
+
+
+async def test_receiving_notification(event_loop):
+ (proc, reader, writer) = await setUp(event_loop)
+
+ async def connected(reader, writer):
+ line = await reader.readline()
+ assert line == b'POST /push HTTP/1.1\r\n'
+
+ line = await reader.readline()
+ assert line == b'Host: 127.0.0.1\r\n'
+
+ line = await reader.readline()
+ assert line == b'Authorization: Bearer 9167e47b01598af7423e2ecd3d0a3ec4\r\n'
+
+ line = await reader.readline()
+ assert line == b'Connection: close\r\n'
+
+ line = await reader.readline()
+ assert line == b'Content-Length: 109\r\n'
+
+ line = await reader.readline()
+ assert line == b'Content-Type: application/json\r\n'
+
+ line = await reader.readline()
+ assert line == b'User-Agent: ZNC\r\n'
+
+ line = await reader.readline()
+ assert line == b'\r\n'
+
+ line = await reader.readline()
+ assert line == b'{"badge": 1,"message": "Test notification","sender": "palaver","network": "b758eaab1a4611a310642a6e8419fbff"}'
+
+ writer.write(b'HTTP/1.1 204 No Content\r\n\r\n')
+ await writer.drain()
+ writer.close()
+
+ connected.called = True
+
+ server = await asyncio.start_server(connected, host='127.0.0.1', port=0, loop=event_loop)
+ await asyncio.sleep(0.2)
+ addr = server.sockets[0].getsockname()
+ url = f'Serving on http://{addr[0]}:{addr[1]}/push'
+
+ writer.write(b'PALAVER IDENTIFY 9167e47b01598af7423e2ecd3d0a3ec4 611d3a30a3d666fc491cdea0d2e1dd6e b758eaab1a4611a310642a6e8419fbff\r\n')
+ await writer.drain()
+
+ line = await reader.readline()
+ assert line == b'PALAVER REQ *\r\n'
+
+ writer.write(b'PALAVER BEGIN 9167e47b01598af7423e2ecd3d0a3ec4 611d3a30a3d666fc491cdea0d2e1dd6e\r\n')
+ writer.write(f'PALAVER SET PUSH-ENDPOINT {url}\r\n'.encode('utf-8'))
+ writer.write(b'PALAVER END\r\n')
+ await writer.drain()
+
+ writer.write(b'PRIVMSG *palaver :test\r\n')
+ await writer.drain()
+
+ await asyncio.sleep(0.2)
+ server.close()
+ await server.wait_closed()
await tearDown(proc)
+
+ assert connected.called