Skip to content

Commit 4da4c27

Browse files
committed
preparations for 0.2.5 version release
1 parent 2ebcf31 commit 4da4c27

6 files changed

+35
-12
lines changed

LICENSE renamed to LICENSE.txt

File renamed without changes.

blynklib.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) 2015-2019 Volodymyr Shymanskyy.
33
# See the file LICENSE for copying permission.
44

5-
__version__ = '0.2.4'
5+
__version__ = '0.2.5'
66

77
try:
88
import usocket as socket
@@ -40,6 +40,7 @@ def stub_log(*args):
4040
class BlynkError(Exception):
4141
pass
4242

43+
4344
class RedirectError(Exception):
4445
def __init__(self, server, port):
4546
self.server = server

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='blynklib',
8-
version='0.2.4',
8+
version='0.2.5',
99
description='Blynk Python/Micropython library',
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

test/test_blynk_connection.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import time
44
import pytest
55
import socket
6-
from blynklib import Connection, BlynkError
6+
from blynklib import Connection, BlynkError, RedirectError
77

88

99
class TestBlynkConnection:
@@ -96,7 +96,7 @@ def test_receive_raise_other_oserror(self, cb, mocker):
9696
with mocker.patch('socket.socket.recv', side_effect=OSError('[Errno 13]')):
9797
with pytest.raises(OSError) as os_err:
9898
cb.receive(10, 1)
99-
assert '[Errno 13]' in str(os_err)
99+
assert '[Errno 13]' in str(os_err.value)
100100

101101
def test_is_server_alive_negative(self, cb):
102102
result = cb.is_server_alive()
@@ -131,7 +131,7 @@ def test_get_socket_exception(self, cb, mocker):
131131
with mocker.patch('socket.getaddrinfo', side_effect=BlynkError('BE')):
132132
with pytest.raises(BlynkError) as b_err:
133133
cb._get_socket()
134-
assert 'Connection with the Blynk server failed: BE' in str(b_err)
134+
assert 'Connection with the Blynk server failed: BE' in str(b_err.value)
135135

136136
def test_authenticate(self, cb, mocker):
137137
with mocker.patch.object(cb, 'send', return_value=None):
@@ -144,35 +144,44 @@ def test_authenticate_invalid_auth_token(self, cb, mocker):
144144
with mocker.patch.object(cb, 'receive', return_value=b'\x00\x00\x02\x00\x09'):
145145
with pytest.raises(BlynkError) as b_err:
146146
cb._authenticate()
147-
assert 'Invalid Auth Token' in str(b_err)
147+
assert 'Invalid Auth Token' in str(b_err.value)
148+
149+
def test_authenticate_redirect_message(self, cb, mocker):
150+
with mocker.patch.object(cb, 'send', return_value=None):
151+
with mocker.patch.object(cb, 'receive', return_value=b'\x29\x00\x02\x00\x11127.0.0.1\x004444'):
152+
with pytest.raises(RedirectError) as r_err:
153+
cb._authenticate()
154+
# pytest exception wraps real exception - so we need access value field first
155+
assert '127.0.0.1' in r_err.value.server
156+
assert '4444' in r_err.value.port
148157

149158
def test_authenticate_not_ok_status(self, cb, mocker):
150159
with mocker.patch.object(cb, 'send', return_value=None):
151160
with mocker.patch.object(cb, 'receive', return_value=b'\x00\x00\x02\x00\x19'):
152161
with pytest.raises(BlynkError) as b_err:
153162
cb._authenticate()
154-
assert 'Auth stage failed. Status=25' in str(b_err)
163+
assert 'Auth stage failed. Status=25' in str(b_err.value)
155164

156165
def test_authenticate_timeout(self, cb, mocker):
157166
with mocker.patch.object(cb, 'send', return_value=None):
158167
with mocker.patch.object(cb, 'receive', return_value=None):
159168
with pytest.raises(BlynkError) as b_err:
160169
cb._authenticate()
161-
assert 'Auth stage timeout' in str(b_err)
170+
assert 'Auth stage timeout' in str(b_err.value)
162171

163172
def test_set_heartbeat_timeout(self, cb, mocker):
164173
with mocker.patch.object(cb, 'send', return_value=None):
165174
with mocker.patch.object(cb, 'receive', return_value=None):
166175
with pytest.raises(BlynkError) as b_err:
167176
cb._set_heartbeat()
168-
assert 'Heartbeat stage timeout' in str(b_err)
177+
assert 'Heartbeat stage timeout' in str(b_err.value)
169178

170179
def test_set_heartbeat_error_status(self, cb, mocker):
171180
with mocker.patch.object(cb, 'send', return_value=None):
172181
with mocker.patch.object(cb, 'receive', return_value=b'\x00\x00\x02\x00\x0e'):
173182
with pytest.raises(BlynkError) as b_err:
174183
cb._set_heartbeat()
175-
assert 'Set heartbeat returned code=14' in str(b_err)
184+
assert 'Set heartbeat returned code=14' in str(b_err.value)
176185

177186
def test_set_heartbeat_positive(self, cb, mocker):
178187
with mocker.patch.object(cb, 'send', return_value=None):

test/test_blynk_main.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import print_function
33
import socket
44
import pytest
5-
from blynklib import Blynk, BlynkError
5+
from blynklib import Blynk, BlynkError, RedirectError
66

77

88
class TestBlynk:
@@ -31,6 +31,19 @@ def test_connect_exception(self, bl, mocker):
3131
assert result is False
3232
assert bl.disconnect.call_count > 1
3333

34+
def test_connect_redirect_exception(self, bl, mocker):
35+
with mocker.patch.object(bl, 'connected', return_value=False):
36+
with mocker.patch.object(bl, '_get_socket', return_value=None):
37+
with mocker.patch.object(bl, '_authenticate', side_effect=RedirectError('127.0.0.1', 4444)):
38+
with mocker.patch.object(bl, 'disconnect', return_value=None):
39+
with mocker.patch('time.sleep', return_value=None):
40+
mocker.spy(bl, 'disconnect')
41+
result = bl.connect(0.001)
42+
assert result is False
43+
assert bl.disconnect.call_count > 1
44+
assert bl.server == '127.0.0.1'
45+
assert bl.port == 4444
46+
3447
def test_connect_timeout(self, bl, mocker):
3548
bl._state = bl.CONNECTING
3649
with mocker.patch.object(bl, 'connected', return_value=False):

test/test_blynk_protocol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_parse_response_msg_hw_unicode(self, pb):
9999

100100
def test_heartbeat_msg(self, pb):
101101
result = pb.heartbeat_msg(20, 2048)
102-
assert result == b'\x11\x00\x02\x00+ver\x000.2.4\x00buff-in\x002048\x00h-beat\x0020\x00dev\x00python'
102+
assert result == b'\x11\x00\x02\x00+ver\x000.2.5\x00buff-in\x002048\x00h-beat\x0020\x00dev\x00python'
103103

104104
def test_login_msg(self, pb):
105105
result = pb.login_msg('1234')

0 commit comments

Comments
 (0)