def test_import_indicators(): assert Indicator.objects.count() == 0 def get_indicators(): return [(x.slug, x.deleted is not None) for x in Indicator.objects.all()] # Initial import to an empty table indicators.import_indicators([ ('a', {'fetch': 'a', 'title': 'A', 'ylabel': 'A'}), ('b', {'fetch': 'b', 'title': 'B', 'ylabel': 'B'}), ]) assert get_indicators() == [('a', False), ('b', False)] # Add new indicator indicators.import_indicators([ ('a', {'fetch': 'a', 'title': 'A', 'ylabel': 'A'}), ('b', {'fetch': 'b', 'title': 'B', 'ylabel': 'B'}), ('c', {'fetch': 'c', 'title': 'C', 'ylabel': 'C'}), ]) assert get_indicators() == [('a', False), ('b', False), ('c', False)] # Remove an existing indicator indicators.import_indicators([ ('a', {'fetch': 'a', 'title': 'A', 'ylabel': 'A'}), ('b', {'fetch': 'b', 'title': 'B', 'ylabel': 'B'}), ]) assert get_indicators() == [('a', False), ('b', False), ('c', True)] # Add an removed indicator again indicators.import_indicators([ ('a', {'fetch': 'a', 'title': 'A', 'ylabel': 'A'}), ('b', {'fetch': 'b', 'title': 'B', 'ylabel': 'B'}), ('c', {'fetch': 'c', 'title': 'C', 'ylabel': 'C'}), ]) assert get_indicators() == [('a', False), ('b', False), ('c', False)]
def test_import_indicators(): assert Indicator.objects.count() == 0 def get_indicators(): return [(x.slug, x.deleted is not None) for x in Indicator.objects.all()] # Initial import to an empty table indicators.import_indicators([ ('a', { 'fetch': 'a', 'title': 'A', 'ylabel': 'A' }), ('b', { 'fetch': 'b', 'title': 'B', 'ylabel': 'B' }), ]) assert get_indicators() == [('a', False), ('b', False)] # Add new indicator indicators.import_indicators([ ('a', { 'fetch': 'a', 'title': 'A', 'ylabel': 'A' }), ('b', { 'fetch': 'b', 'title': 'B', 'ylabel': 'B' }), ('c', { 'fetch': 'c', 'title': 'C', 'ylabel': 'C' }), ]) assert get_indicators() == [('a', False), ('b', False), ('c', False)] # Remove an existing indicator indicators.import_indicators([ ('a', { 'fetch': 'a', 'title': 'A', 'ylabel': 'A' }), ('b', { 'fetch': 'b', 'title': 'B', 'ylabel': 'B' }), ]) assert get_indicators() == [('a', False), ('b', False), ('c', True)] # Add an removed indicator again indicators.import_indicators([ ('a', { 'fetch': 'a', 'title': 'A', 'ylabel': 'A' }), ('b', { 'fetch': 'b', 'title': 'B', 'ylabel': 'B' }), ('c', { 'fetch': 'c', 'title': 'C', 'ylabel': 'C' }), ]) assert get_indicators() == [('a', False), ('b', False), ('c', False)]
def handle(self, *args, **options): self._info(options['verbosity'], 'Importing indicators...') indicators.import_indicators(indicators.INDICATORS) self._info(options['verbosity'], 'Updating indicators...') indicators.update_indicators(indicators.INDICATORS)