mirror of
https://github.com/SaraSmiseth/prosody.git
synced 2025-04-19 16:01:14 +00:00
wip tests 3
This commit is contained in:
parent
c8d5367408
commit
49ff748f3e
5 changed files with 76 additions and 56 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
data/*
|
||||
tests/certs/
|
||||
tests/venv/
|
||||
tests/__pycache__/
|
||||
|
|
3
tests/requirements.txt
Normal file
3
tests/requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
aioxmpp==0.11.0
|
||||
pip-chill==1.0.0
|
||||
pytest-asyncio==0.14.0
|
|
@ -1,50 +0,0 @@
|
|||
import asyncio
|
||||
import aioxmpp
|
||||
import aioxmpp.dispatcher
|
||||
|
||||
jid = aioxmpp.JID.fromstr("admin@localhost")
|
||||
recipient_jid = aioxmpp.JID.fromstr("admin@localhost")
|
||||
password = "12345678"
|
||||
|
||||
client = aioxmpp.PresenceManagedClient(
|
||||
jid,
|
||||
aioxmpp.make_security_layer(
|
||||
password,
|
||||
no_verify=True
|
||||
),
|
||||
)
|
||||
|
||||
def message_received(msg):
|
||||
print(msg)
|
||||
print(msg.body)
|
||||
|
||||
# obtain an instance of the service
|
||||
message_dispatcher = client.summon(
|
||||
aioxmpp.dispatcher.SimpleMessageDispatcher
|
||||
)
|
||||
|
||||
# register a message callback here
|
||||
message_dispatcher.register_callback(
|
||||
aioxmpp.MessageType.CHAT,
|
||||
None,
|
||||
message_received,
|
||||
)
|
||||
|
||||
async def sendMessage():
|
||||
async with client.connected() as stream:
|
||||
msg = aioxmpp.Message(
|
||||
to=recipient_jid,
|
||||
type_=aioxmpp.MessageType.CHAT,
|
||||
)
|
||||
# None is for "default language"
|
||||
msg.body[None] = "Hello World!"
|
||||
|
||||
await client.send(msg)
|
||||
|
||||
def main():
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(sendMessage())
|
||||
loop.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
generateCert() {
|
||||
DOMAIN="$1"
|
||||
if [[ ! -d certs/"$DOMAIN" ]] ; then
|
||||
mkdir -p certs/"$DOMAIN"
|
||||
cd certs/"$DOMAIN"
|
||||
openssl req -x509 -newkey rsa:4096 -keyout privkey.pem -out fullchain.pem -days 365 -subj "/CN=$DOMAIN" -nodes
|
||||
chmod 777 *.pem
|
||||
cd ../../
|
||||
fi
|
||||
}
|
||||
|
||||
generateCert "localhost"
|
||||
|
@ -21,6 +23,10 @@ sudo docker-compose up -d
|
|||
|
||||
sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register admin localhost 12345678"
|
||||
|
||||
python test.py
|
||||
python -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
pytest
|
||||
deactivate
|
||||
|
||||
sudo docker-compose down
|
||||
|
|
60
tests/test_prosody.py
Normal file
60
tests/test_prosody.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
import aioxmpp
|
||||
import aioxmpp.dispatcher
|
||||
import asyncio
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
|
||||
jid = aioxmpp.JID.fromstr("admin@localhost")
|
||||
password = "12345678"
|
||||
|
||||
client = aioxmpp.PresenceManagedClient(
|
||||
jid,
|
||||
aioxmpp.make_security_layer(
|
||||
password,
|
||||
no_verify=True
|
||||
),
|
||||
)
|
||||
return client
|
||||
|
||||
@pytest.fixture
|
||||
def client_with_messageDispatcher(client):
|
||||
def message_received(msg):
|
||||
print(msg)
|
||||
print(msg.body)
|
||||
|
||||
# obtain an instance of the service
|
||||
message_dispatcher = client.summon(
|
||||
aioxmpp.dispatcher.SimpleMessageDispatcher
|
||||
)
|
||||
|
||||
# register a message callback here
|
||||
message_dispatcher.register_callback(
|
||||
aioxmpp.MessageType.CHAT,
|
||||
None,
|
||||
message_received,
|
||||
)
|
||||
return client
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sendMessage(client_with_messageDispatcher):
|
||||
client = client_with_messageDispatcher
|
||||
recipient_jid = aioxmpp.JID.fromstr("admin@localhost")
|
||||
async with client.connected() as stream:
|
||||
msg = aioxmpp.Message(
|
||||
to=recipient_jid,
|
||||
type_=aioxmpp.MessageType.CHAT,
|
||||
)
|
||||
# None is for "default language"
|
||||
msg.body[None] = "Hello World!"
|
||||
|
||||
await client.send(msg)
|
||||
|
||||
# def main():
|
||||
# loop = asyncio.get_event_loop()
|
||||
# loop.run_until_complete(sendMessage())
|
||||
# loop.close()
|
||||
|
||||
# if __name__ == '__main__':
|
||||
# main()
|
Loading…
Reference in a new issue