Ejemplo n.º 1
0
    def test_modelstats(self):
        PROFILE = 'testsite.profiles.models.Profile'
        REQUEST = 'testsite.mylogging.models.Request'
        management.call_command('modelstats', verbosity=0, interactive=False)
        # just test if this does not raise anything

        result = modelstats()
        self.assertIn(PROFILE, result)
        self.assertIn(REQUEST, result)
        profiles_num_0 = int(result[result.find(PROFILE):].split()[1])
        requests_num_0 = int(result[result.find(REQUEST):].split()[1])
        Profile(name="TestName",
                surname="TestSur",
                bio='no bio',
                birth=datetime.datetime(1987, 12, 11, 0, 0)).save()
        Profile(name="TestName2",
                surname="TestSur",
                bio='no bio',
                birth=datetime.datetime(1987, 12, 11, 0, 0)).save()
        self.go('/')
        self.go('/')
        self.go('/')
        result = modelstats()
        profiles_num_1 = int(result[result.find(PROFILE):].split()[1])
        requests_num_1 = int(result[result.find(REQUEST):].split()[1])
        self.assertEqual(profiles_num_0 + 2, profiles_num_1)
        self.assertEqual(requests_num_0 + 3, requests_num_1)
Ejemplo n.º 2
0
    def test_add(self):
        self.assert_create(Profile,
                           name="TestName",
                           surname="TestSur",
                           bio='no bio',
                           birth=datetime.datetime(1987, 12, 11, 0, 0))

        user2 = Profile(name="TestName2",
                        surname="TestSur2",
                        bio='no bio2',
                        birth=datetime.datetime(1987, 12, 11, 0, 0))
        user2.save()
        self.assert_true(
            user2.contact_set.create(mean='phone', data='+38(044)999-99-99'))
Ejemplo n.º 3
0
    def test_add(self):
        self.assert_create(Profile,
                           name="TestName",
                           surname="TestSur",
                           bio='no bio',
                           birth=datetime.datetime(1987, 12, 11, 0, 0)
                           )

        user2 = Profile(name="TestName2",
                        surname="TestSur2",
                        bio='no bio2',
                        birth=datetime.datetime(1987, 12, 11, 0, 0))
        user2.save()
        self.assert_true(user2.contact_set.create(mean='phone',
                                                  data='+38(044)999-99-99'))
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)