def test_chart_config_transform(self): chart_config = [{ 'category': 'Economics', 'titleId': 'CHART_TITLE-Unemployment_rate', 'title': 'Unemployment Rate', 'statsVars': ['UnemploymentRate_Person'], 'isOverview': True }, { 'category': 'Economics', 'titleId': 'CHART_TITLE-Labor_force', 'title': 'Labor Force', 'statsVars': ['Count_Person_InLaborForce'], 'scaling': 100, 'unit': '%', }, { 'category': 'Economics', 'titleId': 'CHART_TITLE-Total_employed', 'title': 'Number of people employed', 'description': 'Number of people employed', 'statsVars': ['Count_Person_Employed'], 'relatedChart': { 'titleId': 'CHART_TITLE-Percentage_employed', 'title': 'Percentage of people employed', 'description': 'Percentage of people employed', 'scale': True, 'denominator': 'Count_Person', 'scaling': 100, 'unit': '%' } }] with self.context: result = landing_page.build_spec(chart_config) with open('tests/test_data/golden_config.json') as f: expected = json.load(f) assert expected == result
def test_menu_hierarchy(self): chart_config = libutil.get_chart_config() spec = landing_page.build_spec(chart_config, False) got = {} for category, topic_data in spec.items(): got[category] = {} for topic, configs in topic_data.items(): got[category][topic] = [c['title'] for c in configs] # Get expected text with open('tests/test_data/golden_menu_text.json', encoding='utf-8') as f: expect = json.load(f) self.assertEqual(got, expect)
class TestBuildSpec(unittest.TestCase): chart_config = [{ 'category': 'Economics', 'title': 'Unemployment Rate', 'statsVars': ['UnemploymentRate_Person'], 'isOverview': True }, { 'category': 'Economics', 'title': 'Labor Force Participation', 'statsVars': ['Count_Person_InLaborForce'], 'scaling': 100, 'unit': '%', }] result, stat_vars = landing_page.build_spec(chart_config) with open('tests/test_data/golden_config.json') as f: expected = json.load(f) assert expected == result assert ['UnemploymentRate_Person', 'Count_Person_InLaborForce'] == stat_vars