Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,49 @@ def _skip_if_version_under(minimum_version):

@pytest.fixture
def skip_if_no_license(logged_rocket):
try:
licenses_info = logged_rocket.licenses_info()
if "license" in licenses_info and "license" in licenses_info.get("license"):
return
except (RocketApiException, RocketBadStatusCodeException):
pytest.fail("License endpoint not available")
pytest.skip("No license available")
licenses_info = logged_rocket.licenses_info()
if "license" in licenses_info and "license" in licenses_info.get("license"):
return
pytest.skip("No license available") # pragma: no cover


@pytest.fixture(scope="session", autouse=True)
def grant_message_impersonate(logged_rocket):
"""Grant the 'message-impersonate' permission to the admin role.

Incoming integrations that post as a user require that user to hold the
'message-impersonate' permission. It is granted to the 'bot' and 'app' roles
by default but not to 'admin', so the integration tests would otherwise fail
with 'error-user-lacks-message-impersonate-permission'.
"""
logged_rocket.permissions_update(
permissions=[{"_id": "message-impersonate", "roles": ["admin", "bot", "app"]}]
)


@pytest.fixture
def accept_chats_with_no_agents(logged_rocket):
"""Allow opening livechat rooms while no agent is online.

In a headless test environment there is no persistent connection keeping an
agent's presence 'online', so Rocket.Chat would otherwise refuse to open a
room with 'no-agent-online'. Accepting chats with no agents online lets the
room be created and the inquiry queued regardless.
"""
original_accept = logged_rocket.settings_get(
"Livechat_accept_chats_with_no_agents"
).get("value")
logged_rocket.settings_update("Livechat_accept_chats_with_no_agents", True)

yield

logged_rocket.settings_update(
"Livechat_accept_chats_with_no_agents", original_accept
)


@pytest.fixture
def livechat_inquiry(logged_rocket):
def livechat_inquiry(logged_rocket, accept_chats_with_no_agents):
"""Create a livechat agent, visitor, and room to generate an inquiry."""
# Save original routing method and set to Manual_Selection to prevent auto-assignment
original_routing = logged_rocket.settings_get("Livechat_Routing_Method")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_livechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_livechat_visitor_minimal(logged_rocket):
assert "visitor" in new_visitor


def test_livechat_visitor_room_and_message(logged_rocket):
def test_livechat_visitor_room_and_message(logged_rocket, accept_chats_with_no_agents):
token = str(uuid.uuid1())
name = str(uuid.uuid1())
new_visitor = logged_rocket.livechat_register_visitor(
Expand All @@ -69,7 +69,9 @@ def test_livechat_visitor_room_and_message(logged_rocket):
get_visitor = logged_rocket.livechat_get_visitor(token=token)
assert name == get_visitor.get("visitor").get("username")

# We need to create a livechat agent and set the user online in order to be able to get a room
# We need to create a livechat agent and set the user online in order to be able to get a room.
# The accept_chats_with_no_agents fixture allows the room to open despite the agent's presence
# not staying online in a headless test environment.
username = logged_rocket.me().get("username")
new_user = logged_rocket.livechat_create_user(user_type="agent", username=username)
logged_rocket.users_set_status(message="working on it", status="online")
Expand Down
Loading