From 253a042314ea5b4f24556c7019e054fdc59a190d Mon Sep 17 00:00:00 2001 From: axolotle Date: Thu, 28 Sep 2023 17:23:51 +0200 Subject: [PATCH] test:domains: dyndns_recovery mock as api call to avoid cli prompts --- src/tests/test_domains.py | 45 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/tests/test_domains.py b/src/tests/test_domains.py index bc2c31465..cc33a87d5 100644 --- a/src/tests/test_domains.py +++ b/src/tests/test_domains.py @@ -1,8 +1,10 @@ import pytest import os -import time import random +from mock import patch + +from moulinette import Moulinette from moulinette.core import MoulinetteError from yunohost.utils.error import YunohostError, YunohostValidationError @@ -87,25 +89,28 @@ def test_domain_add_and_remove_dyndns(): def test_domain_dyndns_recovery(): # Devs: if you get `too_many_request` errors, ask the team to add your IP to the rate limit excempt assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"] - # add domain without recovery password - domain_add(TEST_DYNDNS_DOMAIN) - assert TEST_DYNDNS_DOMAIN in domain_list()["domains"] - # set the recovery password with config panel - domain_config_set(TEST_DYNDNS_DOMAIN, "dns.registrar.recovery_password", TEST_DYNDNS_PASSWORD) - # remove domain without unsubscribing - domain_remove(TEST_DYNDNS_DOMAIN, ignore_dyndns=True) - assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"] - # readding domain with bad password should fail - with pytest.raises(YunohostValidationError): - domain_add( - TEST_DYNDNS_DOMAIN, dyndns_recovery_password="wrong" + TEST_DYNDNS_PASSWORD - ) - assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"] - # readding domain with password should work - domain_add(TEST_DYNDNS_DOMAIN, dyndns_recovery_password=TEST_DYNDNS_PASSWORD) - assert TEST_DYNDNS_DOMAIN in domain_list()["domains"] - # remove the dyndns domain - domain_remove(TEST_DYNDNS_DOMAIN, dyndns_recovery_password=TEST_DYNDNS_PASSWORD) + # mocked as API call to avoid CLI prompts + with patch.object(Moulinette.interface, "type", "api"): + # add domain without recovery password + domain_add(TEST_DYNDNS_DOMAIN) + assert TEST_DYNDNS_DOMAIN in domain_list()["domains"] + # set the recovery password with config panel + domain_config_set(TEST_DYNDNS_DOMAIN, "dns.registrar.recovery_password", TEST_DYNDNS_PASSWORD) + # remove domain without unsubscribing + domain_remove(TEST_DYNDNS_DOMAIN, ignore_dyndns=True) + assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"] + # readding domain with bad password should fail + with pytest.raises(YunohostValidationError): + domain_add( + TEST_DYNDNS_DOMAIN, dyndns_recovery_password="wrong" + TEST_DYNDNS_PASSWORD + ) + assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"] + # readding domain with password should work + domain_add(TEST_DYNDNS_DOMAIN, dyndns_recovery_password=TEST_DYNDNS_PASSWORD) + assert TEST_DYNDNS_DOMAIN in domain_list()["domains"] + # remove the dyndns domain + domain_remove(TEST_DYNDNS_DOMAIN, dyndns_recovery_password=TEST_DYNDNS_PASSWORD) + assert TEST_DYNDNS_DOMAIN not in domain_list()["domains"]