mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-12 07:54:50 +00:00
4f0dadbf38
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
84 lines
3.2 KiB
Nix
84 lines
3.2 KiB
Nix
import ./make-test-python.nix (
|
|
{ lib, ... }:
|
|
{
|
|
name = "listmonk";
|
|
meta.maintainers = with lib.maintainers; [ raitobezarius ];
|
|
|
|
nodes.machine =
|
|
{ pkgs, ... }:
|
|
{
|
|
services.mailhog.enable = true;
|
|
services.listmonk = {
|
|
enable = true;
|
|
settings = {
|
|
admin_username = "listmonk";
|
|
admin_password = "hunter2";
|
|
};
|
|
database = {
|
|
createLocally = true;
|
|
# https://github.com/knadh/listmonk/blob/174a48f252a146d7e69dab42724e3329dbe25ebe/internal/messenger/email/email.go#L18-L27
|
|
settings.smtp = [
|
|
{
|
|
enabled = true;
|
|
host = "localhost";
|
|
port = 1025;
|
|
tls_type = "none";
|
|
}
|
|
];
|
|
};
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
import json
|
|
|
|
start_all()
|
|
|
|
basic_auth = "listmonk:hunter2"
|
|
def generate_listmonk_request(type, url, data=None):
|
|
if data is None: data = {}
|
|
json_data = json.dumps(data)
|
|
return f'curl -u "{basic_auth}" -X {type} "http://localhost:9000/api/{url}" -H "Content-Type: application/json; charset=utf-8" --data-raw \'{json_data}\'''
|
|
|
|
machine.wait_for_unit("mailhog.service")
|
|
machine.wait_for_unit("postgresql.service")
|
|
machine.wait_for_unit("listmonk.service")
|
|
machine.wait_for_open_port(1025)
|
|
machine.wait_for_open_port(8025)
|
|
machine.wait_for_open_port(9000)
|
|
machine.succeed("[[ -f /var/lib/listmonk/.db_settings_initialized ]]")
|
|
|
|
assert json.loads(machine.succeed(generate_listmonk_request("GET", 'health')))['data'], 'Health endpoint returned unexpected value'
|
|
|
|
# A sample subscriber is guaranteed to exist at install-time
|
|
# A sample transactional template is guaranteed to exist at install-time
|
|
subscribers = json.loads(machine.succeed(generate_listmonk_request('GET', "subscribers")))['data']['results']
|
|
templates = json.loads(machine.succeed(generate_listmonk_request('GET', "templates")))['data']
|
|
tx_template = templates[2]
|
|
|
|
# Test transactional endpoint
|
|
print(machine.succeed(
|
|
generate_listmonk_request('POST', 'tx', data={'subscriber_id': subscribers[0]['id'], 'template_id': tx_template['id']})
|
|
))
|
|
|
|
assert 'Welcome Anon Doe' in machine.succeed(
|
|
"curl --fail http://localhost:8025/api/v2/messages"
|
|
), "Failed to find Welcome John Doe inside the messages API endpoint"
|
|
|
|
# Test campaign endpoint
|
|
# Based on https://github.com/knadh/listmonk/blob/174a48f252a146d7e69dab42724e3329dbe25ebe/cmd/campaigns.go#L549 as docs do not exist.
|
|
campaign_data = json.loads(machine.succeed(
|
|
generate_listmonk_request('POST', 'campaigns/1/test', data={'template_id': templates[0]['id'], 'subscribers': ['john@example.com'], 'name': 'Test', 'subject': 'NixOS is great', 'lists': [1], 'messenger': 'email'})
|
|
))
|
|
|
|
assert campaign_data['data'] # This is a boolean asserting if the test was successful or not: https://github.com/knadh/listmonk/blob/174a48f252a146d7e69dab42724e3329dbe25ebe/cmd/campaigns.go#L626
|
|
|
|
messages = json.loads(machine.succeed(
|
|
"curl --fail http://localhost:8025/api/v2/messages"
|
|
))
|
|
|
|
assert messages['total'] == 2
|
|
'';
|
|
}
|
|
)
|