run pyupgrade

This commit is contained in:
Robert Resch 2022-01-30 10:33:37 +01:00
parent bf2514cb09
commit 04bd6b3ef0
29 changed files with 173 additions and 221 deletions

View file

@ -1,4 +1,4 @@
import mock
from unittest import mock
import bumper
import asyncio
import pytest

View file

@ -79,7 +79,7 @@ def test_user_db():
{
"userid": "testuser",
"token": "token_1234",
"expiration": "{}".format(datetime.now() + timedelta(seconds=-10)),
"expiration": f"{datetime.now() + timedelta(seconds=-10)}",
}
) # Add expired token
db.close()
@ -93,7 +93,7 @@ def test_user_db():
{
"userid": "testuser",
"token": "token_1234",
"expiration": "{}".format(datetime.now() + timedelta(seconds=-10)),
"expiration": f"{datetime.now() + timedelta(seconds=-10)}",
}
) # Add expired token
db.close()

View file

@ -1,5 +1,5 @@
import mock
from mock import patch
from unittest import mock
from unittest.mock import patch
import pytest
from tinydb.storages import MemoryStorage
from tinydb import TinyDB, Query

View file

@ -1,4 +1,4 @@
import mock
from unittest import mock
import bumper
import asyncio
import pytest
@ -398,7 +398,7 @@ async def test_mqttserver():
)
await test_client.Client.connect(
"mqtts://{}:{}/".format(test_client.address[0], test_client.address[1]),
f"mqtts://{test_client.address[0]}:{test_client.address[1]}/",
cafile=bumper.ca_cert,
)
assert (

View file

@ -1,4 +1,4 @@
import mock
from unittest import mock
import bumper
import asyncio
import pytest
@ -66,9 +66,7 @@ async def test_client_connect_no_starttls(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode(
"utf-8"
)
test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
xmppclient._parse_data(test_data)
# Expect 2 calls to send
@ -88,9 +86,7 @@ async def test_client_connect_no_starttls(*args, **kwargs):
mock_send.reset_mock()
# Client sendss auth - Ignoring the starttls, we don't force this with bumper
test_data = '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'.encode(
"utf-8"
)
test_data = b'<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'
xmppclient._parse_data(test_data)
assert (
@ -109,7 +105,7 @@ async def test_client_end_stream(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send end stream from "client"
test_data = "</stream:stream>".encode("utf-8")
test_data = b"</stream:stream>"
xmppclient._parse_data(test_data)
# Expect 2 calls to send
@ -121,14 +117,14 @@ async def test_client_end_stream(*args, **kwargs):
mock_send.reset_mock()
# Send abnormal stream from "client"
test_data = "<badstr />".encode("utf-8")
test_data = b"<badstr />"
xmppclient._parse_data(test_data)
# Reset mock calls
mock_send.reset_mock()
# Send blank from "client"
test_data = "".encode("utf-8")
test_data = b""
xmppclient._parse_data(test_data)
@ -141,9 +137,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode(
"utf-8"
)
test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
xmppclient._parse_data(test_data)
# Expect 2 calls to send
@ -165,7 +159,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
mock_tls = xmppclient._handle_starttls = mock.Mock()
# Send start tls from "client"
test_data = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>".encode("utf-8")
test_data = b"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
xmppclient._parse_data(test_data)
# After upgrading connection, server tells client to proceed with auth again
@ -174,9 +168,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
# After TLS is upgraded, Client establishes session again and will auth this time
# Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode(
"utf-8"
)
test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
xmppclient._parse_data(test_data)
# Expect 2 calls to send
@ -195,9 +187,7 @@ async def test_client_connect_starttls_called(*args, **kwargs):
mock_send.reset_mock()
# Client sends auth
test_data = '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'.encode(
"utf-8"
)
test_data = b'<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'
xmppclient._parse_data(test_data)
assert (
@ -277,9 +267,7 @@ async def test_client_init(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "client"
test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode(
"utf-8"
)
test_data = b"<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>"
xmppclient._parse_data(test_data)
# Expect 2 calls to send
@ -299,9 +287,7 @@ async def test_client_init(*args, **kwargs):
mock_send.reset_mock()
# Send bind from "client"
test_data = '<iq type="set" id="5E9872D5-547E-49AF-AE51-9EFAA282F952"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>IOSF53D07BA</resource></bind></iq>'.encode(
"utf-8"
)
test_data = b'<iq type="set" id="5E9872D5-547E-49AF-AE51-9EFAA282F952"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>IOSF53D07BA</resource></bind></iq>'
xmppclient._parse_data(test_data)
assert (
@ -314,9 +300,7 @@ async def test_client_init(*args, **kwargs):
mock_send.reset_mock()
# Send set session from client
test_data = '<iq type="set" id="FA1041E7-AA27-43DD-BAA3-64DE2DE56AA3"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>'.encode(
"utf-8"
)
test_data = b'<iq type="set" id="FA1041E7-AA27-43DD-BAA3-64DE2DE56AA3"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>'
xmppclient._parse_data(test_data)
assert xmppclient.state == xmppclient.READY # client moved to READY state
@ -329,7 +313,7 @@ async def test_client_init(*args, **kwargs):
mock_send.reset_mock()
# Send presense from client
test_data = '<presence type="available"/>'.encode("utf-8")
test_data = b'<presence type="available"/>'
xmppclient._parse_data(test_data)
assert (
@ -347,9 +331,7 @@ async def test_bot_connect(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "bot"
test_data = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>".encode(
"utf-8"
)
test_data = b"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>"
xmppclient._parse_data(test_data)
# Expect 2 calls to send
@ -369,9 +351,7 @@ async def test_bot_connect(*args, **kwargs):
mock_send.reset_mock()
# Send auth from "bot"
test_data = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AEUwMDAwMDAwMDAwMDAwMDAxMjM0AGVuY3J5cHRlZF9wYXNz</auth>".encode(
"utf-8"
)
test_data = b"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AEUwMDAwMDAwMDAwMDAwMDAxMjM0AGVuY3J5cHRlZF9wYXNz</auth>"
xmppclient._parse_data(test_data)
assert (
@ -394,9 +374,7 @@ async def test_bot_init(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Send connect stream from "bot"
test_data = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>".encode(
"utf-8"
)
test_data = b"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>"
xmppclient._parse_data(test_data)
# Expect 2 calls to send
@ -416,9 +394,7 @@ async def test_bot_init(*args, **kwargs):
mock_send.reset_mock()
# Send bind from "bot"
test_data = "<iq type='set' id='2521'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>atom</resource></bind></iq>".encode(
"utf-8"
)
test_data = b"<iq type='set' id='2521'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>atom</resource></bind></iq>"
xmppclient._parse_data(test_data)
assert (
@ -431,9 +407,7 @@ async def test_bot_init(*args, **kwargs):
mock_send.reset_mock()
# Send set session from bot
test_data = "<iq type='set' id='2522'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>".encode(
"utf-8"
)
test_data = b"<iq type='set' id='2522'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>"
xmppclient._parse_data(test_data)
assert xmppclient.state == xmppclient.READY # Bot moved to READY state
@ -445,9 +419,7 @@ async def test_bot_init(*args, **kwargs):
mock_send.reset_mock()
# Send presense from bot
test_data = "<presence><status>hello world</status></presence><iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>".encode(
"utf-8"
)
test_data = b"<presence><status>hello world</status></presence><iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>"
xmppclient._parse_data(test_data)
assert (
@ -467,9 +439,7 @@ async def test_ping_server(*args, **kwargs):
mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
# Ping from bot
test_data = '<iq xmlns:ns0="urn:xmpp:ping" from="E000BVTNX18700260382@159.ecorobot.net/atom" id="2542" to="159.ecorobot.net" type="get"><ping /></iq>'.encode(
"utf-8"
)
test_data = b'<iq xmlns:ns0="urn:xmpp:ping" from="E000BVTNX18700260382@159.ecorobot.net/atom" id="2542" to="159.ecorobot.net" type="get"><ping /></iq>'
xmppclient._parse_data(test_data)
assert (
@ -501,9 +471,7 @@ async def test_ping_client_to_client(*args, **kwargs):
bumper.xmppserver.XMPPServer.clients.append(xmppclient2)
# Ping from user to bot
test_data = '<iq id="104934615" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="get"><ping xmlns="urn:xmpp:ping" /></iq>'.encode(
"utf-8"
)
test_data = b'<iq id="104934615" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="get"><ping xmlns="urn:xmpp:ping" /></iq>'
xmppclient._parse_data(test_data)
assert (
@ -512,9 +480,7 @@ async def test_ping_client_to_client(*args, **kwargs):
) # ping response
# Ping response from bot to user
test_data = "<iq type='result' to='E0000000000000001234@159.ecorobot.net/atom' id='104934615'/>".encode(
"utf-8"
)
test_data = b"<iq type='result' to='E0000000000000001234@159.ecorobot.net/atom' id='104934615'/>"
xmppclient2._parse_data(test_data)
assert (
@ -547,9 +513,7 @@ async def test_client_send_iq(*args, **kwargs):
bumper.xmppserver.XMPPServer.clients.append(xmppclient2)
# Roster IQ - Only seen from Android app so far
test_data = '<iq id="EE0XQ-2" type="get"><query xmlns="jabber:iq:roster" ></query></iq>'.encode(
"utf-8"
)
test_data = b'<iq id="EE0XQ-2" type="get"><query xmlns="jabber:iq:roster" ></query></iq>'
xmppclient._parse_data(test_data)
assert (
@ -561,9 +525,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock()
# Bot Command
test_data = '<iq id="7" to="E0000000000000001234@159.ecorobot.net/atom" type="set"><query xmlns="com:ctl"><ctl id="72107787" td="GetCleanState" /></query></iq>'.encode(
"utf-8"
)
test_data = b'<iq id="7" to="E0000000000000001234@159.ecorobot.net/atom" type="set"><query xmlns="com:ctl"><ctl id="72107787" td="GetCleanState" /></query></iq>'
xmppclient._parse_data(test_data)
assert (
@ -575,9 +537,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock()
# Bot response to query
test_data = '<iq xmlns:ns0="com:ctl" id="2679" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="set"><query><ctl td="ChargeState"><charge h="0" r="a" type="Going" /></ctl></query></iq>'.encode(
"utf-8"
)
test_data = b'<iq xmlns:ns0="com:ctl" id="2679" to="fuid_tmpuser@ecouser.net/IOSF53D07BA" type="set"><query><ctl td="ChargeState"><charge h="0" r="a" type="Going" /></ctl></query></iq>'
xmppclient2._parse_data(test_data)
assert (
@ -589,9 +549,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock()
# Bot result
test_data = "<iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>".encode(
"utf-8"
)
test_data = b"<iq type='result' from='E0000000000000001234@159.ecorobot.net/atom' to='ecouser.net' id='s2c1'/>"
xmppclient2._parse_data(test_data)
assert (
@ -603,9 +561,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock()
# Bot iq set
test_data = "<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='2700'><query xmlns='com:ctl'><ctl td='BatteryInfo'><battery power='100'/></ctl></query></iq>".encode(
"utf-8"
)
test_data = b"<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='2700'><query xmlns='com:ctl'><ctl td='BatteryInfo'><battery power='100'/></ctl></query></iq>"
xmppclient2._parse_data(test_data)
assert (
@ -617,9 +573,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock()
# Bot error report
test_data = "<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='631'><query xmlns='com:ctl'><ctl td='error' errs='102'/></query></iq>".encode(
"utf-8"
)
test_data = b"<iq to='fuid_tmpuser@ecouser.net/IOSF53D07BA' type='set' id='631'><query xmlns='com:ctl'><ctl td='error' errs='102'/></query></iq>"
xmppclient2._parse_data(test_data)
assert (
@ -631,9 +585,7 @@ async def test_client_send_iq(*args, **kwargs):
mock_send.reset_mock()
# Bot "DorpError" to all
test_data = "<iq to='rl.ecorobot.net' type='set' id='1234'><query xmlns='com:sf'><sf td='pub' t='log' ts='1559893796000' tp='p' k='DeviceAlert' v='DorpError' f='E0000000000000001234@159.ecorobot.net' g='fuid_tmpuser@ecouser.net'/></query></iq>".encode(
"utf-8"
)
test_data = b"<iq to='rl.ecorobot.net' type='set' id='1234'><query xmlns='com:sf'><sf td='pub' t='log' ts='1559893796000' tp='p' k='DeviceAlert' v='DorpError' f='E0000000000000001234@159.ecorobot.net' g='fuid_tmpuser@ecouser.net'/></query></iq>"
xmppclient2._parse_data(test_data)
assert (
mock_send.mock_calls[0].args[0]

View file

@ -1,4 +1,4 @@
from mock import patch
from unittest.mock import patch
import bumper