Пример #1
0
    def test_it(self):
        logs_count = Modellog.objects.count()

        #test creation log
        prof = Profile(name="TestName",
                       surname="TestSur",
                       bio='no bio',
                       birth=datetime.datetime(1987, 12, 11, 0, 0))
        prof.save()
        latest = Modellog.objects.latest()
        prof_type = ContentType.objects.get_for_model(prof)
        self.assertEqual(logs_count + 1, Modellog.objects.count())
        self.assertEqual(latest.action, 'C')
        self.assertEqual(latest.inst_pk, prof.pk)
        self.assertEqual(latest.app, prof_type.app_label)
        self.assertEqual(latest.model, prof_type.model)

        #test modification log
        prof.name = "NewName"
        prof.save()
        self.assertEqual(logs_count + 2, Modellog.objects.count())
        self.assertEqual(Modellog.objects.latest().action, 'E')

        #test deletion log
        prof.delete()
        self.assertEqual(Modellog.objects.latest().action, 'D')
        self.assertEqual(logs_count + 3, Modellog.objects.count())

        #test another creation log
        self.go('/')  # let pk be greater than 1
        req = Request(method='GET', path='/', get='', post='')
        req.save()
        self.assertEqual(logs_count + 5, Modellog.objects.count())
        latest = Modellog.objects.latest()
        req_type = ContentType.objects.get_for_model(req)
        self.assertEqual(latest.inst_pk, req.pk)
        self.assertEqual(latest.app, req_type.app_label)
        self.assertEqual(latest.model, req_type.model)
Пример #2
0
 def process_request(self, request):
     req = Request(method=request.method, path=request.path,
                   get=request.GET, post=request.POST)
     req.save()
     return None