diff --git a/signal_analog/dashboards.py b/signal_analog/dashboards.py index 3ba46388..902c703a 100755 --- a/signal_analog/dashboards.py +++ b/signal_analog/dashboards.py @@ -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__() @@ -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)\ @@ -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: diff --git a/tests/mocks/dashboard_group_update_success.json b/tests/mocks/dashboard_group_update_success.json index b83b23b2..3a88a827 100644 --- a/tests/mocks/dashboard_group_update_success.json +++ b/tests/mocks/dashboard_group_update_success.json @@ -1,6 +1,5 @@ { - "http_interactions": [ - { + "http_interactions": [{ "recorded_at": "2018-02-28T17:03:25", "request": { "body": { @@ -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": [ @@ -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": [ @@ -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": [ diff --git a/tests/test_signal_analog_dashboards.py b/tests/test_signal_analog_dashboards.py index dfe53ef8..8da04e55 100644 --- a/tests/test_signal_analog_dashboards.py +++ b/tests/test_signal_analog_dashboards.py @@ -3,6 +3,7 @@ except ImportError: from io import StringIO +import betamax import json import sys from contextlib import contextmanager @@ -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")\ @@ -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):