mirror of
https://github.com/SaraSmiseth/prosody.git
synced 2025-04-19 16:01:14 +00:00
wip tests 5
This commit is contained in:
parent
9187c52ec6
commit
42401df95e
3 changed files with 55 additions and 15 deletions
|
@ -12,8 +12,9 @@ services:
|
||||||
- "5281:5281"
|
- "5281:5281"
|
||||||
environment:
|
environment:
|
||||||
DOMAIN: localhost
|
DOMAIN: localhost
|
||||||
E2E_POLICY_CHAT: optional
|
#E2E_POLICY_CHAT: optional
|
||||||
E2E_POLICY_MUC: optional
|
#E2E_POLICY_MUC: optional
|
||||||
|
E2E_POLICY_WHITELIST: "admin@localhost"
|
||||||
LOG_LEVEL: debug
|
LOG_LEVEL: debug
|
||||||
PROSODY_ADMINS: "admin@localhost, admin2@localhost"
|
PROSODY_ADMINS: "admin@localhost, admin2@localhost"
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
|
|
|
@ -19,14 +19,24 @@ generateCert "pubsub.localhost"
|
||||||
generateCert "proxy.localhost"
|
generateCert "proxy.localhost"
|
||||||
generateCert "upload.localhost"
|
generateCert "upload.localhost"
|
||||||
|
|
||||||
sudo docker-compose up -d
|
# If updates are available --> update and create new version with 'pip-chill > requirements.txt'
|
||||||
|
|
||||||
sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register admin localhost 12345678"
|
sudo docker-compose down \
|
||||||
|
&& sudo docker-compose up -d \
|
||||||
|
\
|
||||||
|
&& sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register admin localhost 12345678" \
|
||||||
|
&& sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register user localhost 12345678" \
|
||||||
|
&& sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register user2 localhost 12345678" \
|
||||||
|
\
|
||||||
|
&& python -m venv venv \
|
||||||
|
&& source venv/bin/activate \
|
||||||
|
&& pip install -r requirements.txt \
|
||||||
|
&& pytest \
|
||||||
|
&& deactivate \
|
||||||
|
&& sleep 1 \
|
||||||
|
&& sudo docker-compose logs | grep "message to" \
|
||||||
|
&& sudo docker-compose logs | grep "type='error'"
|
||||||
|
|
||||||
python -m venv venv
|
# TODO Call bats and create tests to check log output
|
||||||
source venv/bin/activate
|
|
||||||
pip install -r requirements.txt # If updates are available --> update and create new version with 'pip-chill > requirements.txt'
|
|
||||||
pytest
|
|
||||||
deactivate
|
|
||||||
|
|
||||||
sudo docker-compose down
|
sudo docker-compose down
|
||||||
|
|
|
@ -4,9 +4,9 @@ import asyncio
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client(client_username):
|
||||||
|
|
||||||
jid = aioxmpp.JID.fromstr("admin@localhost")
|
jid = aioxmpp.JID.fromstr(client_username)
|
||||||
password = "12345678"
|
password = "12345678"
|
||||||
|
|
||||||
client = aioxmpp.PresenceManagedClient(
|
client = aioxmpp.PresenceManagedClient(
|
||||||
|
@ -19,10 +19,11 @@ def client():
|
||||||
return client
|
return client
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client_with_messageDispatcher(client):
|
def client_with_message_dispatcher(client):
|
||||||
def message_received(msg):
|
def message_received(msg):
|
||||||
print(msg)
|
print(msg)
|
||||||
print(msg.body)
|
print(msg.body)
|
||||||
|
assert msg.body == "Hello World!"
|
||||||
|
|
||||||
# obtain an instance of the service
|
# obtain an instance of the service
|
||||||
message_dispatcher = client.summon(
|
message_dispatcher = client.summon(
|
||||||
|
@ -38,9 +39,37 @@ def client_with_messageDispatcher(client):
|
||||||
return client
|
return client
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_sendMessage(client_with_messageDispatcher):
|
@pytest.mark.parametrize("client_username", ["admin@localhost"])
|
||||||
client = client_with_messageDispatcher
|
async def test_send_message_from_admin_to_user(client):
|
||||||
recipient_jid = aioxmpp.JID.fromstr("admin@localhost")
|
recipient_jid = aioxmpp.JID.fromstr("user@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)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize("client_username", ["admin@localhost"])
|
||||||
|
async def test_send_message_from_admin_to_user2(client):
|
||||||
|
recipient_jid = aioxmpp.JID.fromstr("user2@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)
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize("client_username", ["user@localhost"])
|
||||||
|
async def test_send_message_from_user_to_user2(client):
|
||||||
|
recipient_jid = aioxmpp.JID.fromstr("user2@localhost")
|
||||||
async with client.connected() as stream:
|
async with client.connected() as stream:
|
||||||
msg = aioxmpp.Message(
|
msg = aioxmpp.Message(
|
||||||
to=recipient_jid,
|
to=recipient_jid,
|
||||||
|
|
Loading…
Reference in a new issue