def test_update_all_stats(self): errors = utils.update_all_stats() self.assertEqual(errors, []) self.assertTrue(not errors) i1 = Item.objects.get(id='item_1_1') self.assertTrue(utils.compare_dicts(i1.stats, self.expected['items']['i1'])) i2 = Item.objects.get(id='item_1_2') self.assertTrue(utils.compare_dicts(i2.stats, self.expected['items']['i2'])) i3 = Item.objects.get(id='item_1_3') self.assertTrue(utils.compare_dicts(i3.stats, self.expected['items']['i3'])) p1 = Project.objects.get(id='project_1_1') self.assertTrue(utils.compare_dicts(p1.stats, self.expected['projects']['p1'])) c1 = Collection.objects.get(id='collection_1_1') self.assertTrue(utils.compare_dicts(c1.stats, self.expected['collections']['c1']))
def handle(self, *args, **options): # check for syntax errors if args: raise CommandError('Use options, not args with this command') # make sure at least one option passed stdopts = ['settings', 'pythonpath', 'verbosity', 'traceback'] ovals = [options[o] for o in options if o not in stdopts] if not any(ovals): raise CommandError('No options passed') # begin processing errors = [] if options['item']: log.info('Updating Item with id=%s' % options['item']) e = utils.update_object_stats_quietly(model=Item, id=options['item']) if e: errors.append(e) log.info('Stats for item %s:' % options['item']) log.info(Item.objects.get(id=options['item']).stats) if options['Items']: log.info('Updating all Items') errors += utils.update_model_stats(Item) if options['project']: log.info('Updating Project with id=%s' % options['project']) e = utils.update_object_stats_quietly(model=Project, id=options['project']) if e: errors.append(e) log.info('Stats for project %s:' % options['project']) log.info(Project.objects.get(id=options['project']).stats) if options['Projects']: log.info('Updating all Projects') errors += utils.update_model_stats(Project) if options['collection']: log.info('Updating Collection with id=%s' % options['collection']) e = utils.update_object_stats_quietly(model=Collection, id=options['collection']) if e: errors.append(e) log.info('Stats for Collection %s:' % options['collection']) log.info(Collection.objects.get(id=options['collection']).stats) if options['Collections']: log.info('Updating all Collections') errors += utils.update_model_stats(Collection) if options['All']: #Disconnect all signals disconnect_signal(post_save, update_item_stats_receiver, sender=Bag) disconnect_signal(post_delete, update_item_stats_receiver, sender=Bag) disconnect_signal(post_save, update_collection_stats_receiver, sender=Item) disconnect_signal(post_delete, update_collection_stats_receiver, sender=Item) log.info('Updating entire system') errors += utils.update_all_stats() #Reconnect all signals reconnect_signal(post_save, update_item_stats_receiver, sender=Bag) reconnect_signal(post_delete, update_item_stats_receiver, sender=Bag) reconnect_signal(post_save, update_collection_stats_receiver, sender=Item) reconnect_signal(post_delete, update_collection_stats_receiver, sender=Item) log.info('Update process completed with %s errors' % len(errors)) for e in errors: log.info(e)