Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/dashboard group team update #120

Merged
merged 4 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions signal_analog/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ def update(self, name=None, description=None, resource_id=None, dry_run=False):

if 'id' in self.options or resource_id:
dashboard_group = super(DashboardGroup, self).read(resource_id=resource_id)
# Preserving the teams configuration since the options gets overwritten when the dashboards are updated.
teams = self.options['teams']
self.options = self.__update_dashboard_resources__(dashboard_group)
self.options['teams'] = teams
return super(DashboardGroup, self).update(name=name, description=description, resource_id=resource_id)
else:
query_result = self.__find_existing_resources__()
Expand All @@ -194,7 +197,7 @@ def update(self, name=None, description=None, resource_id=None, dry_run=False):
"Updates the Dashboard Group named: \"{0}\". If it doesn't exist, will create a new one. "
"API call being executed: \n"
"PUT {1} \nRequest Body: \n {2}".format(self.options['name'], (
self.base_url + self.endpoint + '/' + self.options['id']), self.options))
self.base_url + self.endpoint + '/' + self.options['id']), self.options))
return None

return super(DashboardGroup, self)\
Expand Down Expand Up @@ -497,7 +500,7 @@ def update(self, name=None, description=None, resource_id=None, dry_run=False):
click.echo("Updates the Dashboard named: \"{0}\". If it doesn't exist, will create a new one. "
"API call being executed: \n"
"PUT {1} \nRequest Body: \n {2}".format(self.options['name'], (
self.base_url + self.endpoint + '/' + dashboard['id']), dashboard))
self.base_url + self.endpoint + '/' + dashboard['id']), dashboard))
return None

try:
Expand Down
9 changes: 4 additions & 5 deletions tests/mocks/dashboard_group_update_success.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"http_interactions": [
{
"http_interactions": [{
"recorded_at": "2018-02-28T17:03:25",
"request": {
"body": {
Expand Down Expand Up @@ -98,7 +97,7 @@
"response": {
"body": {
"encoding": null,
"string": "{\n \"created\" : 1519837403765,\n \"creator\" : \"ClusPSzAYAA\",\n \"dashboards\" : [ \"DXIz3LaAYAA\" ],\n \"description\" : \"\",\n \"id\" : \"DXIz3LYAgAA\",\n \"lastUpdated\" : 1519837403765,\n \"lastUpdatedBy\" : \"ClusPSzAYAA\",\n \"name\" : \"spaceX lol\",\n \"teams\" : [ ]\n}"
"string": "{\n \"created\" : 1519837403765,\n \"creator\" : \"ClusPSzAYAA\",\n \"dashboards\" : [ \"DXIz3LaAYAA\" ],\n \"description\" : \"\",\n \"id\" : \"DXIz3LYAgAA\",\n \"lastUpdated\" : 1519837403765,\n \"lastUpdatedBy\" : \"ClusPSzAYAA\",\n \"name\" : \"spaceX lol\",\n \"teams\" : []\n}"
},
"headers": {
"Connection": [
Expand Down Expand Up @@ -380,7 +379,7 @@
"request": {
"body": {
"encoding": "utf-8",
"string": "{\"created\": 1519837403765, \"creator\": \"ClusPSzAYAA\", \"dashboards\": [\"DXIz3LaAYAA\"], \"description\": \"updated_dashboard_group_description\", \"id\": \"DXIz3LYAgAA\", \"lastUpdated\": 1519837403765, \"lastUpdatedBy\": \"ClusPSzAYAA\", \"name\": \"updated_dashboard_group_name\", \"teams\": []}"
"string": "{\"created\": 1519837403765, \"creator\": \"ClusPSzAYAA\", \"dashboards\": [\"DXIz3LaAYAA\"], \"description\": \"updated_dashboard_group_description\", \"id\": \"DXIz3LYAgAA\", \"lastUpdated\": 1519837403765, \"lastUpdatedBy\": \"ClusPSzAYAA\", \"name\": \"updated_dashboard_group_name\", \"teams\": [\"updated_team_id\"]}"
},
"headers": {
"Accept": [
Expand Down Expand Up @@ -411,7 +410,7 @@
"response": {
"body": {
"encoding": null,
"string": "{\n \"created\" : 1519837403765,\n \"creator\" : \"ClusPSzAYAA\",\n \"dashboards\" : [ ],\n \"description\" : \"updated_dashboard_group_description\",\n \"id\" : \"DXIz3LYAgAA\",\n \"lastUpdated\" : 1519837414408,\n \"lastUpdatedBy\" : \"ClusPSzAYAA\",\n \"name\" : \"updated_dashboard_group_name\",\n \"teams\" : [ ]\n}"
"string": "{\n \"created\" : 1519837403765,\n \"creator\" : \"ClusPSzAYAA\",\n \"dashboards\" : [ ],\n \"description\" : \"updated_dashboard_group_description\",\n \"id\" : \"DXIz3LYAgAA\",\n \"lastUpdated\" : 1519837414408,\n \"lastUpdatedBy\" : \"ClusPSzAYAA\",\n \"name\" : \"updated_dashboard_group_name\",\n \"teams\" : [\"updated_team_id\"]\n}"
},
"headers": {
"Connection": [
Expand Down
41 changes: 26 additions & 15 deletions tests/test_signal_analog_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
except ImportError:
from io import StringIO

import betamax
import json
import sys
from contextlib import contextmanager
Expand Down Expand Up @@ -803,7 +804,7 @@ def test_dashboard_create_with_filters_time_start_first_character_is_not_negativ
.create()


def test_dashboard_create_with_filters_time_start_unexpected_last_character_failure(chart):
def test_dashboard_create_with_filters_time_start_unexpected_last_character_failure(session, chart):
with pytest.raises(ValueError):
time = FilterTime()\
.with_start("-1z")\
Expand Down Expand Up @@ -1085,26 +1086,36 @@ def test_dashboard_group_create_interactive_failure(confirm, sfx_recorder, sessi


def test_dashboard_group_update_success(sfx_recorder, session):
# Enforcing the request body helps to prevent a defect from being masked due to over-mocking
# the requests/responses.
with betamax.Betamax.configure() as config:
initial_cassette_options = config.default_cassette_options['match_requests_on']
config.default_cassette_options['match_requests_on'] = ['body', 'method', 'uri']

name = 'spaceX lol'
updated_name = 'updated_dashboard_group_name'
with sfx_recorder.use_cassette('dashboard_group_update_success',
serialize_with='prettyjson'):
name = 'spaceX lol'
updated_name = 'updated_dashboard_group_name'
updated_team_id = 'updated_team_id'

with sfx_recorder.use_cassette('dashboard_group_update_success',
serialize_with='prettyjson'):
dashboard_group = DashboardGroup(session=session)\
.with_name(name)\
.with_api_token('foo')

dashboard_group = DashboardGroup(session=session)\
.with_name(name)\
.with_api_token('foo')
create_result = dashboard_group.create()

create_result = dashboard_group.create()
update_result = dashboard_group\
.with_id(create_result['id'])\
.with_teams(updated_team_id)\
.update(name='updated_dashboard_group_name',
description='updated_dashboard_group_description')

update_result = dashboard_group\
.with_id(create_result['id'])\
.update(name='updated_dashboard_group_name',
description='updated_dashboard_group_description')
assert create_result['name'] == name
assert update_result['name'] == updated_name
assert updated_team_id in update_result['teams']

assert create_result['name'] == name
assert update_result['name'] == updated_name
with betamax.Betamax.configure() as config:
config.default_cassette_options['match_requests_on'] = initial_cassette_options


def test_dashboard_group_update_failure(sfx_recorder, session):
Expand Down