forked from chrysn/aiocoap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_blockwise.py
49 lines (40 loc) · 1.84 KB
/
test_blockwise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# This file is part of the Python aiocoap library project.
#
# Copyright (c) 2012-2014 Maciej Wasilak <http://sixpinetrees.blogspot.com/>,
# 2013-2014 Christian Amsüss <[email protected]>
#
# aiocoap is free software, this file is published under the MIT license as
# described in the accompanying LICENSE file.
"""This tests advanced cases of blockwise transfer; simple sequential transfers
are covered in test_server.TestServer.test_replacing_resource."""
import asyncio
import unittest
import aiocoap
from .test_server import WithTestServer, WithClient, no_warnings
from . import test_server
class TestBlockwise(WithTestServer, WithClient):
@unittest.expectedFailure
@no_warnings
def test_sequential(self):
"""Test whether the client serializes simultaneous block requests"""
self.loop.run_until_complete(self._test_sequential())
@asyncio.coroutine
def _test_sequential(self):
pattern1 = b"01234 first pattern" + b"01" * 1024
pattern2 = b"01234 second pattern" + b"02" * 1024
request1 = aiocoap.Message(
uri='coap://' + self.servernetloc + '/replacing/one',
code=aiocoap.POST,
payload=pattern1,
)
request2 = aiocoap.Message(
uri='coap://' + self.servernetloc + '/replacing/one',
code=aiocoap.POST,
payload=pattern2,
)
responses = []
for response in asyncio.as_completed([self.client.request(r).response for r in [request1, request2]]):
response = yield from response
self.assertTrue(response.code.is_successful(), "Simultaneous blockwise requests caused error.")
responses.append(response.payload)
self.assertSetEqual(set(responses), set(x.replace(b'0', b'O') for x in (pattern1, pattern2)))