|
| 1 | +# Copyright 2024 Red Hat, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import pytest |
| 16 | +from rest_framework import status |
| 17 | +from rest_framework.test import APIClient |
| 18 | + |
| 19 | +from aap_eda.conf import settings_registry |
| 20 | +from tests.integration.constants import api_url_v1 |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture(autouse=True) |
| 24 | +def register() -> None: |
| 25 | + settings_registry.persist_registry_data() |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.django_db |
| 29 | +def test_list_system_settings(superuser_client: APIClient): |
| 30 | + response = superuser_client.get(f"{api_url_v1}/settings/system/") |
| 31 | + assert response.status_code == status.HTTP_200_OK |
| 32 | + data = response.data |
| 33 | + assert len(data) == 10 |
| 34 | + assert data["INSIGHTS_TRACKING_STATE"] is False |
| 35 | + assert data["AUTOMATION_ANALYTICS_GATHER_INTERVAL"] == 14400 |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.django_db |
| 39 | +def test_partial_update_system_settings(superuser_client: APIClient): |
| 40 | + pword = "secret" |
| 41 | + body = {"REDHAT_USERNAME": "auser", "REDHAT_PASSWORD": pword} |
| 42 | + response = superuser_client.patch( |
| 43 | + f"{api_url_v1}/settings/system/", data=body |
| 44 | + ) |
| 45 | + assert response.status_code == status.HTTP_200_OK |
| 46 | + data = response.data |
| 47 | + assert len(data) == 10 |
| 48 | + assert data["REDHAT_USERNAME"] == "auser" |
| 49 | + assert data["REDHAT_PASSWORD"] == "$encrypted$" |
| 50 | + |
| 51 | + |
| 52 | +@pytest.mark.django_db |
| 53 | +def test_list_settings_forbidden(user_client: APIClient): |
| 54 | + response = user_client.get(f"{api_url_v1}/settings/system/") |
| 55 | + assert response.status_code == status.HTTP_403_FORBIDDEN |
| 56 | + |
| 57 | + |
| 58 | +@pytest.mark.django_db |
| 59 | +def test_update_settings_forbidden(user_client: APIClient): |
| 60 | + response = user_client.patch(f"{api_url_v1}/settings/system/", data={}) |
| 61 | + assert response.status_code == status.HTTP_403_FORBIDDEN |
| 62 | + |
| 63 | + |
| 64 | +@pytest.mark.django_db |
| 65 | +def test_update_settings_wrong_type(superuser_client: APIClient): |
| 66 | + data = {"AUTOMATION_ANALYTICS_GATHER_INTERVAL": "not number"} |
| 67 | + response = superuser_client.patch( |
| 68 | + f"{api_url_v1}/settings/system/", data=data |
| 69 | + ) |
| 70 | + assert response.status_code == status.HTTP_400_BAD_REQUEST |
0 commit comments