Пример #1
0
    def testModelEventChanges(self):
        """
        Test that django model events do change.  A single change
        """
        model_count = ModelActionAudit.view("auditcare/model_actions_by_id",
                                            include_docs=True,
                                            reduce=False).count()

        self.user.email = '*****@*****.**'
        time.sleep(1)
        self.user.save()
        time.sleep(1)

        model_count2 = ModelActionAudit.view("auditcare/model_actions_by_id",
                                             include_docs=True,
                                             reduce=False).count()
        self.assertEqual(model_count + 1, model_count2)

        #Filter for email and see if it shows up
        email_wrapper = history_for_doc(self.user, filter_fields=['email'])
        email_narratives = email_wrapper.change_narratives()
        self.assertEqual(1, len(email_narratives))

        #exclude for email and see if it doesn't show up
        exclude_wrapper = history_for_doc(self.user, exclude_fields=['email'])
        exclude_narratives = exclude_wrapper.change_narratives()
        self.assertEqual(0, len(exclude_narratives))

        #exclude and filter for email and see if it doesn't show up
        exclude_wrapper = history_for_doc(self.user,
                                          filter_fields=['email'],
                                          exclude_fields=['email'])
        exclude_narratives = exclude_wrapper.change_narratives()
        self.assertEqual(0, len(exclude_narratives))

        #Filter for email and see if it shows up
        new_last_name = 'alksjflajdsflkjsadf'
        self.user.last_name = new_last_name
        time.sleep(1)
        self.user.save()

        name_change_wrapper = history_for_doc(
            self.user, filter_fields=['email', 'first_name', 'last_name'])
        name_change_narratives = name_change_wrapper.change_narratives()

        change_generator = name_change_narratives[-1]['changes']

        seen_last_name = False
        seen_old_value = False
        seen_new_value = False
        for ctuple in change_generator:
            if ctuple[0] == 'last_name':
                seen_last_name = True
            if ctuple[1][0] == 'mock':
                seen_old_value = True
            if ctuple[1][1] == new_last_name:
                seen_new_value = True
        self.assertTrue(seen_last_name)
        self.assertTrue(seen_old_value)
        self.assertTrue(seen_new_value)
Пример #2
0
    def testModelEventChanges(self):
        """
        Test that django model events do change.  A single change
        """
        model_count = ModelActionAudit.view("auditcare/model_actions_by_id", include_docs=True, reduce=False).count()

        self.user.email='*****@*****.**'
        time.sleep(1)
        self.user.save()
        time.sleep(1)

        model_count2 = ModelActionAudit.view("auditcare/model_actions_by_id", include_docs=True, reduce=False).count()
        self.assertEqual(model_count+1, model_count2)


        #Filter for email and see if it shows up
        email_wrapper = history_for_doc(self.user, filter_fields=['email'])
        email_narratives = email_wrapper.change_narratives()
        self.assertEqual(1, len(email_narratives))

        #exclude for email and see if it doesn't show up
        exclude_wrapper = history_for_doc(self.user, exclude_fields=['email'])
        exclude_narratives = exclude_wrapper.change_narratives()
        self.assertEqual(0, len(exclude_narratives))

        #exclude and filter for email and see if it doesn't show up
        exclude_wrapper = history_for_doc(self.user, filter_fields=['email'], exclude_fields=['email'])
        exclude_narratives = exclude_wrapper.change_narratives()
        self.assertEqual(0, len(exclude_narratives))


        #Filter for email and see if it shows up
        new_last_name = 'alksjflajdsflkjsadf'
        self.user.last_name= new_last_name
        time.sleep(1)
        self.user.save()

        name_change_wrapper = history_for_doc(self.user, filter_fields=['email', 'first_name', 'last_name'])
        name_change_narratives = name_change_wrapper.change_narratives()

        change_generator = name_change_narratives[-1]['changes']

        seen_last_name = False
        seen_old_value = False
        seen_new_value = False
        for ctuple in change_generator:
            if ctuple[0] == 'last_name':
                seen_last_name = True
            if ctuple[1][0] == 'mock':
                seen_old_value = True
            if ctuple[1][1] == new_last_name:
                seen_new_value = True
        self.assertTrue(seen_last_name)
        self.assertTrue(seen_old_value)
        self.assertTrue(seen_new_value)
Пример #3
0
def model_instance_history(request, model_name, model_uuid, *args, **kwargs):
    # it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()

    if ContentType.objects.filter(name=model_name).count() == 0:
        # it's couchdbkit
        obj = db.get(model_uuid)
    else:
        obj = ContentType.objects.filter(name=model_name)[0].model_class().objects.get(id=model_uuid)

    context['change_history'] = history_for_doc(obj)
    context['model'] = model_name
    context['model_uuid'] = model_uuid
    return render_to_response('auditcare/model_instance_history.html', context)
Пример #4
0
def model_instance_history(request, model_name, model_uuid, *args, **kwargs):
    # it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()

    if ContentType.objects.filter(name=model_name).count() == 0:
        # it's couchdbkit
        obj = db.get(model_uuid)
    else:
        obj = ContentType.objects.filter(name=model_name)[0].model_class().objects.get(id=model_uuid)

    context['change_history'] = history_for_doc(obj)
    context['model'] = model_name
    context['model_uuid'] = model_uuid
    return render_to_response('auditcare/model_instance_history.html', context)
Пример #5
0
def model_instance_history(request, model_name, model_uuid, *args, **kwargs):
    #it's for a particular model
    context=RequestContext(request)
    db = AccessAudit.get_db()
    changes=db.view('auditcare/model_actions_by_id', reduce=False, key=[model_name, model_uuid], include_docs=True).all()
    #context['changes']= sorted([(x['doc']['_id'], x['doc']) for x in changes], key=lambda y: y[1]['event_date'], reverse=True)

    if ContentType.objects.filter(name=model_name).count() == 0:
        #it's couchdbkit
        obj = db.get(model_uuid)
    else:
        obj = ContentType.objects.filter(name=model_name)[0].model_class().objects.get(id=model_uuid)

    context['change_history'] = history_for_doc(obj)
    context['model'] = model_name
    context['model_uuid'] = model_uuid
    return render_to_response('auditcare/model_instance_history.html', context)