Coverage for domain / test_models.py: 100%
34 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 12:43 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 12:43 +0000
1from django.test import TransactionTestCase as TestCase
3from .models import Model
4from . import app_label
6from sm.utils import random_string
8import os
9import django
11os.environ["DJANGO_SETTINGS_MODULE"] = "sm.settings"
12django.setup()
15class Tester(TestCase):
16 model = Model
17 teststring = random_string()
18 fixtures = ["%s/fixtures/01_initial.yaml" % app_label]
19 testitem = None
21 def setUp(self):
22 self.testitem, created = self.get_or_create_testitem()
24 def get_or_create_testitem(self):
25 self.testitem, created = self.model.objects.get_or_create(name=self.teststring)
26 return (self.testitem, created)
28 def test_create(self):
29 # Since we want to test if creation works, we
30 # need to manually prune the DB and create a testitem
31 self.model.objects.all().delete()
32 obj, created = self.get_or_create_testitem()
33 self.assertEqual(created, True, "the object was already there?")
34 self.assertIsInstance(obj, self.model, "object not correct model!?")
36 def test_name(self):
37 self.assertEqual(self.testitem.name, self.teststring, "name not correct")
39 def test_name___str__(self):
40 self.assertEqual("%s" % self.testitem, self.teststring, "name not correct")
42 def test_get_absolute_url(self):
43 self.assertEqual(
44 "/%s/detail/%i/" % (app_label, self.testitem.id),
45 self.testitem.get_absolute_url(),
46 "reverse url not correct",
47 )
49 def test_delete(self):
50 res = self.testitem.delete()
51 self.assertEqual(res[0], 1)
52 self.assertTrue("%s.Model" % app_label in res[1])
53 self.assertEqual(res[1]["%s.Model" % app_label], 1)