Skip to content
This repository was archived by the owner on Sep 2, 2026. It is now read-only.
Draft
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ cd app
docker compose up --detach
```

### Exécution des tests

1. Activer l'environnement virtuel et installer les dépendances de développement.

2. Naviguer dans le répertoire `app` :
```bash
cd app
```

3. Exécuter les tests avec :
```bash
pytest
```


### Troubleshooting

Expand Down Expand Up @@ -198,6 +212,20 @@ cd app
docker compose up --detach
```

### Run tests

1. Activate the virtual environment and install the dev dependencies.

2. Navigate to the `app` directory:
```bash
cd app
```

1. Run the tests with:
```bash
pytest
```

### Troubleshooting

The first sync is quite long, and apparently non-blocking. If you interact with the bot before it has synced properly, you risk leaving it in an unstable state (where the bot does not have the room listing).
Expand Down
1 change: 1 addition & 0 deletions app/matrix_bot/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

from matrix_bot.config import bot_lib_config, logger


Expand Down
33 changes: 33 additions & 0 deletions app/test_tchap_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: 2024 Etalab <etalab@modernisation.gouv.fr>
#
# SPDX-License-Identifier: MIT

from config import Config
from nio import MatrixRoom, MatrixUser, PowerLevels
from tchap_utils import (
get_salon_moderators,
get_salon_users_str,
get_user_to_power_level,
user_name_to_non_hl_user,
users_print,
)


def test_get_user_to_power_level() -> None:
user1 = MatrixUser(user_id="@alice:matrix.org", power_level=0)
user2 = MatrixUser(user_id="@bob:matrix.org", power_level=50)
user3 = MatrixUser(user_id="@charlie:matrix.org", power_level=100)
salon = MatrixRoom(
room_id="!room:matrix.org",
own_user_id="@alice:matrix.org",
)
salon.users = {
"@alice:matrix.org": user1,
"@bob:matrix.org": user2,
"@charlie:matrix.org": user3,
}
assert get_user_to_power_level(salon) == {
"Alice": 0,
"Bob": 50,
"Charlie": 100,
}
7 changes: 7 additions & 0 deletions app/tests/test_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2024 Etalab <etalab@modernisation.gouv.fr>
#
# SPDX-License-Identifier: MIT


def test_import():
from bot import main # noqa
50 changes: 50 additions & 0 deletions app/tests/test_pyalbert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2024 Etalab <etalab@modernisation.gouv.fr>
#
# SPDX-License-Identifier: MIT

from config import Config
from pyalbert_utils import (
generate,
generate_sources,
get_available_modes,
new_chat,
)


def test_get_available_modes() -> None:
test_config = Config()
assert len(get_available_modes(test_config)) > 0

test_config = Config(albert_model_name="not_existing_model_name")
assert get_available_modes(test_config) is None


def test_new_chat() -> None:
test_config = Config()
assert isinstance(new_chat(test_config), int)


def test_generate() -> None:
test_config = Config()
assert isinstance(generate(test_config, "Hello"), str)
assert isinstance(test_config.albert_chat_id, int)
assert isinstance(test_config.albert_stream_id, int)


def test_generate_sources() -> None:
test_config = Config()
generate(test_config, "Hello")
assert isinstance(test_config.albert_stream_id, int)
sources = generate_sources(test_config, test_config.albert_stream_id)
assert isinstance(sources, list)
assert len(sources) > 0
assert isinstance(sources[0], dict)
assert isinstance(sources[0].get("hash"), str)
assert isinstance(sources[0].get("sid"), str)
assert isinstance(sources[0].get("title"), str)
assert isinstance(sources[0].get("url"), str)
assert isinstance(sources[0].get("introduction"), str)
assert isinstance(sources[0].get("text"), str)
assert isinstance(sources[0].get("context"), str)
assert isinstance(sources[0].get("surtitre"), str)
assert isinstance(sources[0].get("source"), str)
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ dependencies = [

[tool.pdm]
distribution = false
dev-dependencies = { dev = ["ruff==0.4.4"] }
dev-dependencies = { dev = ["ruff==0.4.4", "pytest>=8.2.2"] }

[tool.rye]
dev-dependencies = ["ruff==0.4.4"]
dev-dependencies = ["ruff==0.4.4", "pytest>=8.2.2"]

[tool.ruff]
line-length = 100
Expand Down