mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-10 01:49:32 +00:00
Reorganize tests
This commit is contained in:
parent
c92294350f
commit
07f4da2f23
|
@ -186,7 +186,9 @@ def resize_block_mock(mocker):
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
def test_call_resize_from_block_device(lsblk_singular_mock, resize_block_mock, authorized_client):
|
def test_call_resize_from_block_device(
|
||||||
|
lsblk_singular_mock, resize_block_mock, authorized_client
|
||||||
|
):
|
||||||
block_device = BlockDevice(json.loads(VOLUME_LSBLK_OUTPUT)["blockdevices"][0])
|
block_device = BlockDevice(json.loads(VOLUME_LSBLK_OUTPUT)["blockdevices"][0])
|
||||||
block_device.resize()
|
block_device.resize()
|
||||||
assert resize_block_mock.call_count == 1
|
assert resize_block_mock.call_count == 1
|
||||||
|
@ -223,7 +225,9 @@ def test_get_stats_from_block_device(lsblk_singular_mock, authorized_client):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_mount_block_device(lsblk_singular_mock, only_root_in_userdata, authorized_client):
|
def test_mount_block_device(
|
||||||
|
lsblk_singular_mock, only_root_in_userdata, authorized_client
|
||||||
|
):
|
||||||
block_device = BlockDevice(json.loads(SINGLE_LSBLK_OUTPUT)["blockdevices"][0])
|
block_device = BlockDevice(json.loads(SINGLE_LSBLK_OUTPUT)["blockdevices"][0])
|
||||||
result = block_device.mount()
|
result = block_device.mount()
|
||||||
assert result is False
|
assert result is False
|
||||||
|
@ -270,7 +274,9 @@ def test_mount_block_device_when_undefined(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_unmount_block_device(lsblk_singular_mock, only_root_in_userdata, authorized_client):
|
def test_unmount_block_device(
|
||||||
|
lsblk_singular_mock, only_root_in_userdata, authorized_client
|
||||||
|
):
|
||||||
block_device = BlockDevice(json.loads(SINGLE_LSBLK_OUTPUT)["blockdevices"][0])
|
block_device = BlockDevice(json.loads(SINGLE_LSBLK_OUTPUT)["blockdevices"][0])
|
||||||
result = block_device.unmount()
|
result = block_device.unmount()
|
||||||
assert result is True
|
assert result is True
|
||||||
|
|
|
@ -124,6 +124,7 @@ def mock_dkim_key(mocker):
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value="I am a DKIM key",
|
return_value="I am a DKIM key",
|
||||||
)
|
)
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
API_PYTHON_VERSION_INFO = """
|
API_PYTHON_VERSION_INFO = """
|
||||||
|
@ -137,7 +138,7 @@ def test_graphql_get_python_version_wrong_auth(
|
||||||
wrong_auth_client, mock_subprocess_check_output
|
wrong_auth_client, mock_subprocess_check_output
|
||||||
):
|
):
|
||||||
"""Test wrong auth"""
|
"""Test wrong auth"""
|
||||||
response = wrong_auth_client.get(
|
response = wrong_auth_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_PYTHON_VERSION_INFO]),
|
"query": generate_system_query([API_PYTHON_VERSION_INFO]),
|
||||||
|
@ -149,7 +150,7 @@ def test_graphql_get_python_version_wrong_auth(
|
||||||
|
|
||||||
def test_graphql_get_python_version(authorized_client, mock_subprocess_check_output):
|
def test_graphql_get_python_version(authorized_client, mock_subprocess_check_output):
|
||||||
"""Test get python version"""
|
"""Test get python version"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_PYTHON_VERSION_INFO]),
|
"query": generate_system_query([API_PYTHON_VERSION_INFO]),
|
||||||
|
@ -173,7 +174,7 @@ def test_graphql_get_system_version_unauthorized(
|
||||||
wrong_auth_client, mock_subprocess_check_output
|
wrong_auth_client, mock_subprocess_check_output
|
||||||
):
|
):
|
||||||
"""Test wrong auth"""
|
"""Test wrong auth"""
|
||||||
response = wrong_auth_client.get(
|
response = wrong_auth_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_SYSTEM_VERSION_INFO]),
|
"query": generate_system_query([API_SYSTEM_VERSION_INFO]),
|
||||||
|
@ -188,7 +189,7 @@ def test_graphql_get_system_version_unauthorized(
|
||||||
|
|
||||||
def test_graphql_get_system_version(authorized_client, mock_subprocess_check_output):
|
def test_graphql_get_system_version(authorized_client, mock_subprocess_check_output):
|
||||||
"""Test get system version"""
|
"""Test get system version"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_SYSTEM_VERSION_INFO]),
|
"query": generate_system_query([API_SYSTEM_VERSION_INFO]),
|
||||||
|
@ -209,7 +210,7 @@ domainInfo {
|
||||||
hostname
|
hostname
|
||||||
provider
|
provider
|
||||||
requiredDnsRecords {
|
requiredDnsRecords {
|
||||||
type
|
recordType
|
||||||
name
|
name
|
||||||
content
|
content
|
||||||
ttl
|
ttl
|
||||||
|
@ -219,14 +220,14 @@ domainInfo {
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def dns_record(type="A", name="test.tld", content=None, ttl=3600, priority=None):
|
def dns_record(record_type="A", name="test-domain.tld", content=None, ttl=3600, priority=None):
|
||||||
if content is None:
|
if content is None:
|
||||||
if type == "A":
|
if record_type == "A":
|
||||||
content = "157.90.247.192"
|
content = "157.90.247.192"
|
||||||
elif type == "AAAA":
|
elif record_type == "AAAA":
|
||||||
content = "fe80::9400:ff:fef1:34ae"
|
content = "fe80::9400:ff:fef1:34ae"
|
||||||
return {
|
return {
|
||||||
"type": type,
|
"recordType": record_type,
|
||||||
"name": name,
|
"name": name,
|
||||||
"content": content,
|
"content": content,
|
||||||
"ttl": ttl,
|
"ttl": ttl,
|
||||||
|
@ -237,7 +238,7 @@ def dns_record(type="A", name="test.tld", content=None, ttl=3600, priority=None)
|
||||||
def is_dns_record_in_array(records, dns_record) -> bool:
|
def is_dns_record_in_array(records, dns_record) -> bool:
|
||||||
for record in records:
|
for record in records:
|
||||||
if (
|
if (
|
||||||
record["type"] == dns_record["type"]
|
record["recordType"] == dns_record["recordType"]
|
||||||
and record["name"] == dns_record["name"]
|
and record["name"] == dns_record["name"]
|
||||||
and record["content"] == dns_record["content"]
|
and record["content"] == dns_record["content"]
|
||||||
and record["ttl"] == dns_record["ttl"]
|
and record["ttl"] == dns_record["ttl"]
|
||||||
|
@ -248,10 +249,10 @@ def is_dns_record_in_array(records, dns_record) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_get_domain(
|
def test_graphql_get_domain(
|
||||||
authorized_client, domain_file, mock_get_ip4, mock_get_ip6, turned_on
|
authorized_client, domain_file, mock_get_ip4, mock_get_ip6, turned_on, mock_dkim_key
|
||||||
):
|
):
|
||||||
"""Test get domain"""
|
"""Test get domain"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_GET_DOMAIN_INFO]),
|
"query": generate_system_query([API_GET_DOMAIN_INFO]),
|
||||||
|
@ -263,53 +264,53 @@ def test_graphql_get_domain(
|
||||||
assert (
|
assert (
|
||||||
response.json()["data"]["system"]["domainInfo"]["hostname"] == "test-instance"
|
response.json()["data"]["system"]["domainInfo"]["hostname"] == "test-instance"
|
||||||
)
|
)
|
||||||
assert response.json()["data"]["system"]["domainInfo"]["provider"] == "HETZNER"
|
assert response.json()["data"]["system"]["domainInfo"]["provider"] == "CLOUDFLARE"
|
||||||
dns_records = response.json()["data"]["system"]["domainInfo"]["requiredDnsRecords"]
|
dns_records = response.json()["data"]["system"]["domainInfo"]["requiredDnsRecords"]
|
||||||
assert is_dns_record_in_array(dns_records, dns_record())
|
assert is_dns_record_in_array(dns_records, dns_record())
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(type="AAAA"))
|
assert is_dns_record_in_array(dns_records, dns_record(record_type="AAAA"))
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(name="api.test.tld"))
|
assert is_dns_record_in_array(dns_records, dns_record(name="api"))
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records, dns_record(name="api.test.tld", type="AAAA")
|
dns_records, dns_record(name="api", record_type="AAAA")
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(name="cloud.test.tld"))
|
assert is_dns_record_in_array(dns_records, dns_record(name="cloud"))
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records, dns_record(name="cloud.test.tld", type="AAAA")
|
dns_records, dns_record(name="cloud", record_type="AAAA")
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(name="git.test.tld"))
|
assert is_dns_record_in_array(dns_records, dns_record(name="git"))
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records, dns_record(name="git.test.tld", type="AAAA")
|
dns_records, dns_record(name="git", record_type="AAAA")
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(name="meet.test.tld"))
|
assert is_dns_record_in_array(dns_records, dns_record(name="meet"))
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records, dns_record(name="meet.test.tld", type="AAAA")
|
dns_records, dns_record(name="meet", record_type="AAAA")
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(name="password.test.tld"))
|
assert is_dns_record_in_array(dns_records, dns_record(name="password"))
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records, dns_record(name="password.test.tld", type="AAAA")
|
dns_records, dns_record(name="password", record_type="AAAA")
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(name="social.test.tld"))
|
assert is_dns_record_in_array(dns_records, dns_record(name="social"))
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records, dns_record(name="social.test.tld", type="AAAA")
|
dns_records, dns_record(name="social", record_type="AAAA")
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(dns_records, dns_record(name="vpn.test.tld"))
|
assert is_dns_record_in_array(dns_records, dns_record(name="vpn"))
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records, dns_record(name="vpn.test.tld", type="AAAA")
|
dns_records, dns_record(name="vpn", record_type="AAAA")
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records,
|
dns_records,
|
||||||
dns_record(name="test.tld", type="MX", content="test.tld", priority=10),
|
dns_record(name="test-domain.tld", record_type="MX", content="test-domain.tld", priority=10),
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records,
|
dns_records,
|
||||||
dns_record(
|
dns_record(
|
||||||
name="_dmarc.test.tld", type="TXT", content="v=DMARC1; p=none", ttl=18000
|
name="_dmarc", record_type="TXT", content="v=DMARC1; p=none", ttl=18000
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records,
|
dns_records,
|
||||||
dns_record(
|
dns_record(
|
||||||
name="test.tld",
|
name="test-domain.tld",
|
||||||
type="TXT",
|
record_type="TXT",
|
||||||
content="v=spf1 a mx ip4:157.90.247.192 -all",
|
content="v=spf1 a mx ip4:157.90.247.192 -all",
|
||||||
ttl=18000,
|
ttl=18000,
|
||||||
),
|
),
|
||||||
|
@ -317,8 +318,8 @@ def test_graphql_get_domain(
|
||||||
assert is_dns_record_in_array(
|
assert is_dns_record_in_array(
|
||||||
dns_records,
|
dns_records,
|
||||||
dns_record(
|
dns_record(
|
||||||
name="selector._domainkey.test.tld",
|
name="selector._domainkey",
|
||||||
type="TXT",
|
record_type="TXT",
|
||||||
content="I am a DKIM key",
|
content="I am a DKIM key",
|
||||||
ttl=18000,
|
ttl=18000,
|
||||||
),
|
),
|
||||||
|
@ -334,7 +335,7 @@ settings {
|
||||||
|
|
||||||
def test_graphql_get_timezone_unauthorized(client, turned_on):
|
def test_graphql_get_timezone_unauthorized(client, turned_on):
|
||||||
"""Test get timezone without auth"""
|
"""Test get timezone without auth"""
|
||||||
response = client.get(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_GET_TIMEZONE]),
|
"query": generate_system_query([API_GET_TIMEZONE]),
|
||||||
|
@ -346,7 +347,7 @@ def test_graphql_get_timezone_unauthorized(client, turned_on):
|
||||||
|
|
||||||
def test_graphql_get_timezone(authorized_client, turned_on):
|
def test_graphql_get_timezone(authorized_client, turned_on):
|
||||||
"""Test get timezone"""
|
"""Test get timezone"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_GET_TIMEZONE]),
|
"query": generate_system_query([API_GET_TIMEZONE]),
|
||||||
|
@ -359,7 +360,7 @@ def test_graphql_get_timezone(authorized_client, turned_on):
|
||||||
|
|
||||||
def test_graphql_get_timezone_on_undefined(authorized_client, undefined_config):
|
def test_graphql_get_timezone_on_undefined(authorized_client, undefined_config):
|
||||||
"""Test get timezone when none is defined in config"""
|
"""Test get timezone when none is defined in config"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": generate_system_query([API_GET_TIMEZONE]),
|
"query": generate_system_query([API_GET_TIMEZONE]),
|
||||||
|
@ -484,7 +485,7 @@ def test_graphql_change_timezone_with_invalid_timezone(authorized_client, turned
|
||||||
API_GET_AUTO_UPGRADE_SETTINGS_QUERY = """
|
API_GET_AUTO_UPGRADE_SETTINGS_QUERY = """
|
||||||
settings {
|
settings {
|
||||||
autoUpgrade {
|
autoUpgrade {
|
||||||
enableAutoUpgrade
|
enable
|
||||||
allowReboot
|
allowReboot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -493,10 +494,10 @@ settings {
|
||||||
|
|
||||||
def test_graphql_get_auto_upgrade_unauthorized(client, turned_on):
|
def test_graphql_get_auto_upgrade_unauthorized(client, turned_on):
|
||||||
"""Test get auto upgrade settings without auth"""
|
"""Test get auto upgrade settings without auth"""
|
||||||
response = client.get(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_GET_AUTO_UPGRADE_SETTINGS_QUERY,
|
"query": generate_system_query([API_GET_AUTO_UPGRADE_SETTINGS_QUERY]),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -505,66 +506,66 @@ def test_graphql_get_auto_upgrade_unauthorized(client, turned_on):
|
||||||
|
|
||||||
def test_graphql_get_auto_upgrade(authorized_client, turned_on):
|
def test_graphql_get_auto_upgrade(authorized_client, turned_on):
|
||||||
"""Test get auto upgrade settings"""
|
"""Test get auto upgrade settings"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_GET_AUTO_UPGRADE_SETTINGS_QUERY,
|
"query": generate_system_query([API_GET_AUTO_UPGRADE_SETTINGS_QUERY]),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json().get("data") is not None
|
assert response.json().get("data") is not None
|
||||||
assert (
|
assert (
|
||||||
response.json()["data"]["settings"]["autoUpgrade"]["enableAutoUpgrade"] is True
|
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is True
|
||||||
)
|
)
|
||||||
assert response.json()["data"]["settings"]["autoUpgrade"]["allowReboot"] is True
|
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is True
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_get_auto_upgrade_on_undefined(authorized_client, undefined_config):
|
def test_graphql_get_auto_upgrade_on_undefined(authorized_client, undefined_config):
|
||||||
"""Test get auto upgrade settings when none is defined in config"""
|
"""Test get auto upgrade settings when none is defined in config"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_GET_AUTO_UPGRADE_SETTINGS_QUERY,
|
"query": generate_system_query([API_GET_AUTO_UPGRADE_SETTINGS_QUERY]),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json().get("data") is not None
|
assert response.json().get("data") is not None
|
||||||
assert (
|
assert (
|
||||||
response.json()["data"]["settings"]["autoUpgrade"]["enableAutoUpgrade"] is True
|
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is True
|
||||||
)
|
)
|
||||||
assert response.json()["data"]["settings"]["autoUpgrade"]["allowReboot"] is False
|
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_get_auto_upgrade_without_vlaues(authorized_client, no_values):
|
def test_graphql_get_auto_upgrade_without_vlaues(authorized_client, no_values):
|
||||||
"""Test get auto upgrade settings without values"""
|
"""Test get auto upgrade settings without values"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_GET_AUTO_UPGRADE_SETTINGS_QUERY,
|
"query": generate_system_query([API_GET_AUTO_UPGRADE_SETTINGS_QUERY]),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json().get("data") is not None
|
assert response.json().get("data") is not None
|
||||||
assert (
|
assert (
|
||||||
response.json()["data"]["settings"]["autoUpgrade"]["enableAutoUpgrade"] is True
|
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is True
|
||||||
)
|
)
|
||||||
assert response.json()["data"]["settings"]["autoUpgrade"]["allowReboot"] is False
|
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_get_auto_upgrade_turned_off(authorized_client, turned_off):
|
def test_graphql_get_auto_upgrade_turned_off(authorized_client, turned_off):
|
||||||
"""Test get auto upgrade settings when turned off"""
|
"""Test get auto upgrade settings when turned off"""
|
||||||
response = authorized_client.get(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_GET_AUTO_UPGRADE_SETTINGS_QUERY,
|
"query": generate_system_query([API_GET_AUTO_UPGRADE_SETTINGS_QUERY]),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json().get("data") is not None
|
assert response.json().get("data") is not None
|
||||||
assert (
|
assert (
|
||||||
response.json()["data"]["settings"]["autoUpgrade"]["enableAutoUpgrade"] is False
|
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is False
|
||||||
)
|
)
|
||||||
assert response.json()["data"]["settings"]["autoUpgrade"]["allowReboot"] is False
|
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is False
|
||||||
|
|
||||||
|
|
||||||
API_CHANGE_AUTO_UPGRADE_SETTINGS = """
|
API_CHANGE_AUTO_UPGRADE_SETTINGS = """
|
||||||
|
@ -805,7 +806,7 @@ def test_graphql_change_auto_upgrade_with_empty_input(authorized_client, turned_
|
||||||
|
|
||||||
|
|
||||||
API_PULL_SYSTEM_CONFIGURATION_MUTATION = """
|
API_PULL_SYSTEM_CONFIGURATION_MUTATION = """
|
||||||
mutation testPullSystemConfiguration() {
|
mutation testPullSystemConfiguration {
|
||||||
pullRepositoryChanges {
|
pullRepositoryChanges {
|
||||||
success
|
success
|
||||||
message
|
message
|
|
@ -33,7 +33,7 @@
|
||||||
},
|
},
|
||||||
"username": "tester",
|
"username": "tester",
|
||||||
"gitea": {
|
"gitea": {
|
||||||
"enable": false
|
"enable": true
|
||||||
},
|
},
|
||||||
"ocserv": {
|
"ocserv": {
|
||||||
"enable": true
|
"enable": true
|
||||||
|
@ -49,4 +49,4 @@
|
||||||
"sshKeys": [
|
"sshKeys": [
|
||||||
"ssh-rsa KEY test@pc"
|
"ssh-rsa KEY test@pc"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,3 +30,21 @@ def test_jobs(authorized_client, jobs_file, shared_datadir):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert jobs.get_jobs() == [test_job]
|
assert jobs.get_jobs() == [test_job]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_subprocess_run(mocker):
|
||||||
|
mock = mocker.patch("subprocess.run", autospec=True)
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_shutil_move(mocker):
|
||||||
|
mock = mocker.patch("shutil.move", autospec=True)
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_shutil_chown(mocker):
|
||||||
|
mock = mocker.patch("shutil.chown", autospec=True)
|
||||||
|
return mock
|
||||||
|
|
1
tests/test_rest_endpoints/data/jobs.json
Normal file
1
tests/test_rest_endpoints/data/jobs.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
14
tests/test_rest_endpoints/data/tokens.json
Normal file
14
tests/test_rest_endpoints/data/tokens.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"tokens": [
|
||||||
|
{
|
||||||
|
"token": "TEST_TOKEN",
|
||||||
|
"name": "test_token",
|
||||||
|
"date": "2022-01-14 08:31:10.789314"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "TEST_TOKEN2",
|
||||||
|
"name": "test_token2",
|
||||||
|
"date": "2022-01-14 08:31:10.789314"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -12,68 +12,78 @@ def call_args_asserts(mocked_object):
|
||||||
assert mocked_object.call_count == 7
|
assert mocked_object.call_count == 7
|
||||||
assert mocked_object.call_args_list[0][0][0] == [
|
assert mocked_object.call_args_list[0][0][0] == [
|
||||||
"systemctl",
|
"systemctl",
|
||||||
"status",
|
"show",
|
||||||
"dovecot2.service",
|
"dovecot2.service",
|
||||||
]
|
]
|
||||||
assert mocked_object.call_args_list[1][0][0] == [
|
assert mocked_object.call_args_list[1][0][0] == [
|
||||||
"systemctl",
|
"systemctl",
|
||||||
"status",
|
"show",
|
||||||
"postfix.service",
|
"postfix.service",
|
||||||
]
|
]
|
||||||
assert mocked_object.call_args_list[2][0][0] == [
|
assert mocked_object.call_args_list[2][0][0] == [
|
||||||
"systemctl",
|
"systemctl",
|
||||||
"status",
|
"show",
|
||||||
"vaultwarden.service",
|
"vaultwarden.service",
|
||||||
]
|
]
|
||||||
assert mocked_object.call_args_list[3][0][0] == [
|
assert mocked_object.call_args_list[3][0][0] == [
|
||||||
"systemctl",
|
"systemctl",
|
||||||
"status",
|
"show",
|
||||||
"gitea.service",
|
"gitea.service",
|
||||||
]
|
]
|
||||||
assert mocked_object.call_args_list[4][0][0] == [
|
assert mocked_object.call_args_list[4][0][0] == [
|
||||||
"systemctl",
|
"systemctl",
|
||||||
"status",
|
"show",
|
||||||
"phpfpm-nextcloud.service",
|
"phpfpm-nextcloud.service",
|
||||||
]
|
]
|
||||||
assert mocked_object.call_args_list[5][0][0] == [
|
assert mocked_object.call_args_list[5][0][0] == [
|
||||||
"systemctl",
|
"systemctl",
|
||||||
"status",
|
"show",
|
||||||
"ocserv.service",
|
"ocserv.service",
|
||||||
]
|
]
|
||||||
assert mocked_object.call_args_list[6][0][0] == [
|
assert mocked_object.call_args_list[6][0][0] == [
|
||||||
"systemctl",
|
"systemctl",
|
||||||
"status",
|
"show",
|
||||||
"pleroma.service",
|
"pleroma.service",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ProcessMock:
|
SUCCESSFUL_STATUS = b"""
|
||||||
"""Mock subprocess.Popen"""
|
Type=oneshot
|
||||||
|
ExitType=main
|
||||||
|
Restart=no
|
||||||
|
NotifyAccess=none
|
||||||
|
RestartUSec=100ms
|
||||||
|
LoadState=loaded
|
||||||
|
ActiveState=active
|
||||||
|
FreezerState=running
|
||||||
|
SubState=exited
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, args, **kwargs):
|
FAILED_STATUS = b"""
|
||||||
self.args = args
|
Type=oneshot
|
||||||
self.kwargs = kwargs
|
ExitType=main
|
||||||
|
Restart=no
|
||||||
def communicate():
|
NotifyAccess=none
|
||||||
return (b"", None)
|
RestartUSec=100ms
|
||||||
|
LoadState=loaded
|
||||||
returncode = 0
|
ActiveState=failed
|
||||||
|
FreezerState=running
|
||||||
|
SubState=exited
|
||||||
class BrokenServiceMock(ProcessMock):
|
"""
|
||||||
returncode = 3
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_subproccess_popen(mocker):
|
def mock_subproccess_popen(mocker):
|
||||||
mock = mocker.patch("subprocess.Popen", autospec=True, return_value=ProcessMock)
|
mock = mocker.patch(
|
||||||
|
"subprocess.check_output", autospec=True, return_value=SUCCESSFUL_STATUS
|
||||||
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_broken_service(mocker):
|
def mock_broken_service(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"subprocess.Popen", autospec=True, return_value=BrokenServiceMock
|
"subprocess.check_output", autospec=True, return_value=FAILED_STATUS
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
@ -116,13 +126,13 @@ def test_no_dkim_key(authorized_client, mock_broken_service):
|
||||||
response = authorized_client.get("/services/status")
|
response = authorized_client.get("/services/status")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"imap": 3,
|
"imap": 1,
|
||||||
"smtp": 3,
|
"smtp": 1,
|
||||||
"http": 0,
|
"http": 0,
|
||||||
"bitwarden": 3,
|
"bitwarden": 1,
|
||||||
"gitea": 3,
|
"gitea": 1,
|
||||||
"nextcloud": 3,
|
"nextcloud": 1,
|
||||||
"ocserv": 3,
|
"ocserv": 1,
|
||||||
"pleroma": 3,
|
"pleroma": 1,
|
||||||
}
|
}
|
||||||
call_args_asserts(mock_broken_service)
|
call_args_asserts(mock_broken_service)
|
|
@ -2,12 +2,10 @@
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
# pylint: disable=missing-function-docstring
|
# pylint: disable=missing-function-docstring
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
import re
|
|
||||||
import pytest
|
import pytest
|
||||||
from mnemonic import Mnemonic
|
from mnemonic import Mnemonic
|
||||||
|
|
||||||
from .common import read_json, write_json
|
from tests.common import read_json, write_json
|
||||||
|
|
||||||
|
|
||||||
TOKENS_FILE_CONTETS = {
|
TOKENS_FILE_CONTETS = {
|
Loading…
Reference in a new issue