-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
302 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
request = b"""NOTIFY * HTTP/1.1 | ||
Host: 239.255.255.250:1982 | ||
Cache-Control: max-age=3600 | ||
Location: yeelight://192.168.1.239:55443 | ||
NTS: ssdp:alive | ||
Server: POSIX, UPnP/1.0 YGLC/1 | ||
id: 0x000000000015243f | ||
model: color | ||
fw_ver: 18 | ||
support: get_prop set_default set_power toggle set_bright start_cf stop_cf set_scene cron_add cron_get cron_del set_ct_abx set_rgb | ||
power: on | ||
bright: 100 | ||
color_mode: 2 | ||
ct: 4000 | ||
rgb: 16711680 | ||
hue: 100 | ||
sat: 35 | ||
name: my_bulb""".replace(b'\n', b'\r\n') | ||
|
||
response = b"""HTTP/1.1 200 OK | ||
Cache-Control: max-age=3600 | ||
Date: | ||
Ext: | ||
Location: yeelight://192.168.1.239:55443 | ||
Server: POSIX UPnP/1.0 YGLC/1 | ||
id: 0x000000000015243f | ||
model: color | ||
fw_ver: 18 | ||
support: get_prop set_default set_power toggle set_bright start_cf stop_cf set_scene cron_add cron_get cron_del set_ct_abx set_rgb | ||
power: on | ||
bright: 100 | ||
color_mode: 2 | ||
ct: 4000 | ||
rgb: 16711680 | ||
hue: 100 | ||
sat: 35 | ||
name: my_bulb""".replace(b'\n', b'\r\n') | ||
|
||
response_wrong_location = b"""HTTP/1.1 200 OK | ||
Cache-Control: max-age=3600 | ||
Date: | ||
Ext: | ||
Location: yeelight://not.an.ip:55443 | ||
Server: POSIX UPnP/1.0 YGLC/1""".replace(b'\n', b'\r\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pytest | ||
|
||
from yeelib.upnp import SSDPMessage, SSDPResponse, SSDPRequest | ||
from . import fixtures | ||
|
||
|
||
class TestSSDPMessage: | ||
def test_headers_copy(self): | ||
headers = [('Cache-Control', 'max-age=3600')] | ||
msg = SSDPMessage(headers=headers) | ||
assert msg.headers == headers | ||
assert msg.headers is not headers | ||
|
||
def test_headers_dict(self): | ||
headers = {'Cache-Control': 'max-age=3600'} | ||
msg = SSDPMessage(headers=headers) | ||
assert msg.headers == [('Cache-Control', 'max-age=3600')] | ||
|
||
def test_headers_none(self): | ||
msg = SSDPMessage(headers=None) | ||
assert msg.headers == [] | ||
|
||
def test_parse(self): | ||
with pytest.raises(NotImplementedError): | ||
SSDPMessage.parse('') | ||
|
||
def test_parse_headers(self): | ||
headers = SSDPMessage.parse_headers('Cache-Control: max-age=3600') | ||
assert headers == [('Cache-Control', 'max-age=3600')] | ||
|
||
|
||
class TestSSDPResponse: | ||
def test_parse(self): | ||
response = SSDPResponse.parse(fixtures.response.decode()) | ||
assert response.status_code == 200 | ||
assert response.reason == 'OK' | ||
|
||
|
||
class TestSSDPRequest: | ||
def test_parse(self): | ||
request = SSDPRequest.parse(fixtures.request.decode()) | ||
assert request.method == 'NOTIFY' | ||
assert request.uri == '*' | ||
|
||
def test_str(self): | ||
request = SSDPRequest('NOTIFY', '*', headers=[('Cache-Control', 'max-age=3600')]) | ||
assert str(request) == ( | ||
'NOTIFY * HTTP/1.1\n' | ||
'Cache-Control: max-age=3600' | ||
) | ||
|
||
def test_bytes(self): | ||
request = SSDPRequest.parse(fixtures.request.decode()) | ||
assert bytes(request) == fixtures.request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.