Skip to content

Commit 3869ca1

Browse files
committed
Improve "Organization preferences"
Use new methods `{get,update,patch}_preferences` to avoid confusion.
1 parent 5ef5f4c commit 3869ca1

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

grafana_client/elements/organization.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def organization_preference_get(self):
183183
"""
184184
:return:
185185
"""
186-
warnings.warn("Deprecated, please use `organization_preferences_get`", DeprecationWarning)
187-
return self.organization_preferences_get()
186+
warnings.warn("This method is deprecated, please use `get_preferences`", DeprecationWarning)
187+
return self.get_preferences()
188188

189189
def organization_preference_update(self, theme="", home_dashboard_id=0, timezone="utc"):
190190
"""
@@ -194,11 +194,11 @@ def organization_preference_update(self, theme="", home_dashboard_id=0, timezone
194194
:param timezone:
195195
:return:
196196
"""
197-
warnings.warn("Deprecated, please use `organization_preferences_update`", DeprecationWarning)
197+
warnings.warn("This method is deprecated, please use `update_preferences`", DeprecationWarning)
198198
preferences = PersonalPreferences(theme=theme, homeDashboardId=home_dashboard_id, timezone=timezone)
199-
return self.organization_preferences_update(preferences)
199+
return self.update_preferences(preferences)
200200

201-
def organization_preferences_get(self):
201+
def get_preferences(self):
202202
"""
203203
Retrieve preferences of current organization.
204204
@@ -208,15 +208,15 @@ def organization_preferences_get(self):
208208
r = self.client.GET(update_preference)
209209
return r
210210

211-
def organization_preferences_update(self, preferences: PersonalPreferences):
211+
def update_preferences(self, preferences: PersonalPreferences):
212212
"""
213213
Update preferences of current organization as a whole.
214214
215215
From the `preferences` instance, only attributes with values `not None` will be submitted.
216216
However, Grafana will reset all undefined attributes to its internal defaults.
217217
218218
If you want to update specific preference attributes, without touching the others,
219-
please use the `organization_preferences_patch` method.
219+
please use the `patch_preferences` method.
220220
221221
:param preferences:
222222
:return:
@@ -230,7 +230,7 @@ def organization_preferences_update(self, preferences: PersonalPreferences):
230230
)
231231
return r
232232

233-
def organization_preferences_patch(self, preferences: PersonalPreferences):
233+
def patch_preferences(self, preferences: PersonalPreferences):
234234
"""
235235
Update specific preferences of current organization.
236236

test/elements/test_organization.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,24 @@ def test_organization_preference_update(self, m):
3232
self.assertEqual(preference["message"], "Preferences updated")
3333

3434
@requests_mock.Mocker()
35-
def test_organization_preferences_get(self, m):
35+
def test_get_preferences(self, m):
3636
m.get("http://localhost/api/org/preferences", json={"theme": "", "homeDashboardId": 0, "timezone": ""})
3737

38-
result = self.grafana.organizations.organization_preferences_get()
38+
result = self.grafana.organizations.get_preferences()
3939
self.assertEqual(result["homeDashboardId"], 0)
4040

4141
@requests_mock.Mocker()
42-
def test_organization_preferences_update(self, m):
42+
def test_update_preferences(self, m):
4343
m.put("http://localhost/api/org/preferences", json={"message": "Preferences updated"})
44-
preference = self.grafana.organizations.organization_preferences_update(
44+
preference = self.grafana.organizations.update_preferences(
4545
PersonalPreferences(theme="", homeDashboardId=999, timezone="utc")
4646
)
4747
self.assertEqual(preference["message"], "Preferences updated")
4848

4949
@requests_mock.Mocker()
50-
def test_organization_preferences_patch(self, m):
50+
def test_patch_preferences(self, m):
5151
m.patch("http://localhost/api/org/preferences", json={"message": "Preferences updated"})
52-
preference = self.grafana.organizations.organization_preferences_patch(
53-
PersonalPreferences(homeDashboardUID="zgjG8dKVz")
54-
)
52+
preference = self.grafana.organizations.patch_preferences(PersonalPreferences(homeDashboardUID="zgjG8dKVz"))
5553
self.assertEqual(preference["message"], "Preferences updated")
5654

5755
@requests_mock.Mocker()

0 commit comments

Comments
 (0)