# -*- coding: utf-8 -*-
# Copyright 2015 grafana-dashboard-builder contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from grafana_dashboards.context import DictDefaultingToPlaceholder

__author__ = 'Jakub Plichta <jakub.plichta@gmail.com>'


def test_dict():
    d = DictDefaultingToPlaceholder({'a': 1})

    assert d['a'] == 1
    assert d['b'] == '{b}'

@@ -682,16 +682,25 @@
 ceholder
+, Context
 %0A%0A__auth
@@ -864,8 +864,2115 @@
 = '%7Bb%7D'%0A
+%0A%0Adef test_context_expands_scalar_value():%0A    data = %7B%0A        'single': 'first',%0A        'wrapped': '%7Bsingle%7D',%0A        'double-wrapped': '%7Bwrapped%7D'%0A    %7D%0A    contexts = %5Bcontext for context in Context.create_context(data, keys_to_expand=('expanded-list', 'expanded-dict'))%5D%0A    assert len(contexts) == 1%0A    expected = %7B'double-wrapped': 'first', 'single': 'first', 'wrapped': 'first'%7D%0A    to_expand = %7B'single': '%7Bsingle%7D', 'wrapped': '%7Bwrapped%7D', 'double-wrapped': '%7Bdouble-wrapped%7D'%7D%0A    assert contexts%5B0%5D.expand_placeholders(to_expand) == expected%0A%0A%0Adef test_context_expands_list_value():%0A    data = %7B%0A        'single': 'first',%0A        'expanded-list': %5B%0A            'list0',%0A            'list1'%0A        %5D%0A    %7D%0A    contexts = %5Bcontext for context in Context.create_context(data, keys_to_expand=('expanded-list', 'expanded-dict'))%5D%0A    assert len(contexts) == 2%0A    expected0 = %7B'single': 'first', 'expanded-list': 'list0'%7D%0A    expected1 = %7B'single': 'first', 'expanded-list': 'list1'%7D%0A    to_expand = %7B'single': '%7Bsingle%7D', 'expanded-list': '%7Bexpanded-list%7D'%7D%0A    assert contexts%5B0%5D.expand_placeholders(to_expand) == expected0%0A    assert contexts%5B1%5D.expand_placeholders(to_expand) == expected1%0A%0A%0Adef test_context_expands_dict_value():%0A    data = %7B%0A        'single': 'first',%0A        'expanded-dict': %5B%0A            %7B%0A                'dict0': %7B%0A                    'dict-value': '00'%0A                %7D%0A            %7D,%0A            %7B%0A                'dict1': %7B%0A                    'dict-value': '10'%0A                %7D%0A            %7D%0A        %5D%0A    %7D%0A    contexts = %5Bcontext for context in Context.create_context(data, keys_to_expand=('expanded-list', 'expanded-dict'))%5D%0A    assert len(contexts) == 2%0A    expected0 = %7B'single': 'first', 'expanded-dict': 'dict0', 'dict-value': '00'%7D%0A    expected1 = %7B'single': 'first', 'expanded-dict': 'dict1', 'dict-value': '10'%7D%0A    to_expand = %7B'single': '%7Bsingle%7D', 'expanded-dict': '%7Bexpanded-dict%7D', 'dict-value': '%7Bdict-value%7D'%7D%0A    assert contexts%5B0%5D.expand_placeholders(to_expand) == expected0%0A    assert contexts%5B1%5D.expand_placeholders(to_expand) == expected1%0A

Add context expansion tests