wip tests 5

This commit is contained in:
Sara Aimée Smiseth 2020-10-06 17:36:14 +02:00
parent 9187c52ec6
commit 42401df95e
3 changed files with 55 additions and 15 deletions

View file

@ -12,8 +12,9 @@ services:
- "5281:5281"
environment:
DOMAIN: localhost
E2E_POLICY_CHAT: optional
E2E_POLICY_MUC: optional
#E2E_POLICY_CHAT: optional
#E2E_POLICY_MUC: optional
E2E_POLICY_WHITELIST: "admin@localhost"
LOG_LEVEL: debug
PROSODY_ADMINS: "admin@localhost, admin2@localhost"
extra_hosts:

View file

@ -19,14 +19,24 @@ generateCert "pubsub.localhost"
generateCert "proxy.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
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
# TODO Call bats and create tests to check log output
sudo docker-compose down

View file

@ -4,9 +4,9 @@ import asyncio
import pytest
@pytest.fixture
def client():
def client(client_username):
jid = aioxmpp.JID.fromstr("admin@localhost")
jid = aioxmpp.JID.fromstr(client_username)
password = "12345678"
client = aioxmpp.PresenceManagedClient(
@ -19,10 +19,11 @@ def client():
return client
@pytest.fixture
def client_with_messageDispatcher(client):
def client_with_message_dispatcher(client):
def message_received(msg):
print(msg)
print(msg.body)
assert msg.body == "Hello World!"
# obtain an instance of the service
message_dispatcher = client.summon(
@ -38,9 +39,37 @@ def client_with_messageDispatcher(client):
return client
@pytest.mark.asyncio
async def test_sendMessage(client_with_messageDispatcher):
client = client_with_messageDispatcher
recipient_jid = aioxmpp.JID.fromstr("admin@localhost")
@pytest.mark.parametrize("client_username", ["admin@localhost"])
async def test_send_message_from_admin_to_user(client):
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:
msg = aioxmpp.Message(
to=recipient_jid,