python312Packages.millheater: 0.11.8 -> 0.12.0
[NixPkgs.git] / nixos / tests / matrix / conduit.nix
blob2b81c23598eba1a59ad5b438fdf41646c71bd492
1 import ../make-test-python.nix ({ pkgs, ... }:
2   let
3     name = "conduit";
4   in
5   {
6     name = "matrix-conduit";
8     nodes = {
9       conduit = args: {
10         services.matrix-conduit = {
11           enable = true;
12           settings.global.server_name = name;
13           settings.global.allow_registration = true;
14           extraEnvironment.RUST_BACKTRACE = "yes";
15         };
16         services.nginx = {
17           enable = true;
18           virtualHosts.${name} = {
19             enableACME = false;
20             forceSSL = false;
21             enableSSL = false;
23             locations."/_matrix" = {
24               proxyPass = "http://[::1]:6167";
25             };
26           };
27         };
28         networking.firewall.allowedTCPPorts = [ 80 ];
29       };
30       client = { pkgs, ... }: {
31         environment.systemPackages = [
32           (
33             pkgs.writers.writePython3Bin "do_test"
34               { libraries = [ pkgs.python3Packages.matrix-nio ]; } ''
35               import asyncio
37               from nio import AsyncClient
40               async def main() -> None:
41                   # Connect to conduit
42                   client = AsyncClient("http://conduit:80", "alice")
44                   # Register as user alice
45                   response = await client.register("alice", "my-secret-password")
47                   # Log in as user alice
48                   response = await client.login("my-secret-password")
50                   # Create a new room
51                   response = await client.room_create(federate=False)
52                   room_id = response.room_id
54                   # Join the room
55                   response = await client.join(room_id)
57                   # Send a message to the room
58                   response = await client.room_send(
59                       room_id=room_id,
60                       message_type="m.room.message",
61                       content={
62                           "msgtype": "m.text",
63                           "body": "Hello conduit!"
64                       }
65                   )
67                   # Sync responses
68                   response = await client.sync(timeout=30000)
70                   # Check the message was received by conduit
71                   last_message = response.rooms.join[room_id].timeline.events[-1].body
72                   assert last_message == "Hello conduit!"
74                   # Leave the room
75                   response = await client.room_leave(room_id)
77                   # Close the client
78                   await client.close()
80               asyncio.get_event_loop().run_until_complete(main())
81             ''
82           )
83         ];
84       };
85     };
87     testScript = ''
88       start_all()
90       with subtest("start conduit"):
91             conduit.wait_for_unit("conduit.service")
92             conduit.wait_for_open_port(80)
94       with subtest("ensure messages can be exchanged"):
95             client.succeed("do_test")
96     '';
97   })