conftest.py 2.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
import pytest


def clients():
    return {
        "client-1": {
            "client_id": "client-1",
            "client_name": "Client 1",
            "subscription": "soar.#",
            "secret": "abc123",
        },
        "client-2": {
            "client_id": "client-2",
            "client_name": "Client 2",
            "subscription": "soar.client-2.#",
            "secret": "xyz789",
        },
    }


def get_auth_header(client, credentials):
    token_response = client.get("/token", query_string=credentials)
    if token_response.status_code == 200:
        token = token_response.json["token"]
        return {"Authorization": f"Bearer {token}"}
    else:
        return None


@pytest.fixture
def mock_clients():
    return clients()


@pytest.fixture
def mock_new_client():
    return {
        "client_id": "client-3",
        "client_name": "Client 3",
        "subscription": "soar.client-3.#",
    }


@pytest.fixture
def mock_client_credentials():
    mock_clients = clients()
    return {
        "client_id": mock_clients["client-1"]["client_id"],
        "secret": mock_clients["client-1"]["secret"],
    }


@pytest.fixture
def mock_invalid_credentials():
    return {"client_id": "client-invalid", "secret": "fake-secret"}


@pytest.fixture
def mock_token_secret():
    return "2UrRyeb9c6hq8Gj9nmI5safPz9LpPeUFtifeMNx4GQo="


def posts():
    return {
        "send": {
            "topic": "soar.client-1.message",
            "body": "this is a pub/sub message from client-1",
        },
        "notify": {"body": "this is a broadcast message from client-1"},
    }


@pytest.fixture
def mock_post_send():
    return posts()["send"]


@pytest.fixture
def mock_message_send():
    post = posts()["send"]
    return {"topic": post["topic"], "message": post["body"]}


@pytest.fixture
def mock_post_notify():
    return posts()["notify"]


@pytest.fixture
def mock_message_notify():
91 92 93 94 95 96 97 98 99
    post = posts()["notify"]
    return {"topic": "broadcast", "message": post["body"]}


@pytest.fixture
def mock_read_from_queue_return():
    return [
        {
            "topic": "soar.client-1.something",
100
            "message": "this is a pub/sub message from client-1",
101 102
        }
    ]