2018-02-24 14:27:51 +00:00
|
|
|
import pytest
|
2018-02-17 20:21:08 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
|
|
|
|
def test_can_list_settings_via_api(preferences, api_client):
|
2018-06-09 13:36:16 +00:00
|
|
|
url = reverse("api:v1:instance:settings")
|
2018-02-17 20:21:08 +00:00
|
|
|
all_preferences = preferences.model.objects.all()
|
|
|
|
expected_preferences = {
|
|
|
|
p.preference.identifier(): p
|
|
|
|
for p in all_preferences
|
2018-06-09 13:36:16 +00:00
|
|
|
if getattr(p.preference, "show_in_api", False)
|
|
|
|
}
|
2018-02-17 20:21:08 +00:00
|
|
|
|
|
|
|
assert len(expected_preferences) > 0
|
|
|
|
|
|
|
|
response = api_client.get(url)
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert len(response.data) == len(expected_preferences)
|
|
|
|
|
|
|
|
for p in response.data:
|
2018-06-09 13:36:16 +00:00
|
|
|
i = "__".join([p["section"], p["name"]])
|
2018-02-17 20:21:08 +00:00
|
|
|
assert i in expected_preferences
|
2018-02-24 14:27:51 +00:00
|
|
|
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"pref,value",
|
|
|
|
[
|
|
|
|
("instance__name", "My instance"),
|
|
|
|
("instance__short_description", "For music lovers"),
|
|
|
|
("instance__long_description", "For real music lovers"),
|
|
|
|
],
|
|
|
|
)
|
2018-02-24 14:27:51 +00:00
|
|
|
def test_instance_settings(pref, value, preferences):
|
|
|
|
preferences[pref] = value
|
|
|
|
|
|
|
|
assert preferences[pref] == value
|