Esempio n. 1
0
 def test_rf_program_two_indicators_update_only(self):
     p = RFProgramFactory(
         tiers=['Tier1', 'Tier2'], levels=1,
     )
     expected_pks = []
     levels = sorted(p.levels.all(), key=operator.attrgetter('level_depth'))
     for level in levels:
         expected_pks.append(RFIndicatorFactory(program=p, level=level).pk)
     indicator = RFIndicatorFactory(program=p, level=levels[1], name='Test Name')
     expected_pks.append(indicator.pk)
     full_data = ProgramPageProgramSerializer.get_for_pk(p.pk).data
     with self.assertNumQueries(5):
         data = ProgramPageUpdateSerializer.update_indicator_pk(p.pk, indicator.pk).data
     self.assertEqual(len(data), 5)
     self.assertEqual(data['pk'], p.pk)
     self.assertEqual(data['indicator_pks_level_order'], data['indicator_pks_chain_order'])
     indicator_pks = data['indicator_pks_level_order']
     self.assertEqual(indicator_pks, expected_pks)
     self.assertEqual(data['indicator']['name'], 'Test Name')
     for indicator_pk in full_data['indicators']:
         self.assertIn(indicator_pk, data['indicators'])
         self.assertEqual(
             full_data['indicators'][indicator_pk]['number'],
             data['indicators'][indicator_pk]['number']
             )
Esempio n. 2
0
def api_program_page_indicator(request, pk, program):
    """Returns single indicator updated JSON and ordering information for program page)"""
    try:
        data = ProgramPageUpdateSerializer.update_indicator_pk(program,
                                                               pk).data
    except Program.DoesNotExist, Indicator.DoesNotExist:
        logger.warn(
            'attempt to access indicator update for bad pk {}'.format(pk))
        return JsonResponse({'success': False, 'msg': 'bad Indicator PK'})