Coverage for learning_logs/tests/test_models.py: 85.71%

24 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-08-31 09:09 -0700

1from django.contrib.auth import get_user_model 

2from django.test import TestCase 

3 

4from ..models import Entry, Topic 

5 

6 

7class TopicModelTest(TestCase): 

8 def setUp(self): 

9 User = get_user_model() 

10 self.user = User.objects.create_user( 

11 username="kevin", 

12 email="kevin@example.com", 

13 password="T3stP@5s123", 

14 ) 

15 self.topic = Topic.objects.create(owner=self.user, text="just a test") 

16 self.entry = Entry.objects.create(topic=self.topic, text="Entry text") 

17 self.long_entry = Entry.objects.create( 

18 topic=self.topic, 

19 text="This is a long Entry text that should be concatenated.", 

20 ) 

21 

22 """ 

23 def test_topic_content(self): 

24 topic = Topic.objects.get(id=1) 

25 self.text = f"{topic.text}" 

26 self.assertEqual(self.text, "just a test") 

27 """ 

28 

29 def test_topic___str__(self): 

30 self.assertEqual(str(self.topic), self.topic.text) 1d

31 

32 def test_topic_get_absolute_url(self): 

33 assert self.topic.get_absolute_url() == f"/topics/{self.topic.id}/" 1e

34 

35 """ 

36 def test_entry_content(self): 

37 entry = Entry.objects.get(id=1) 

38 self.text = f"{entry.text}" 

39 self.assertEqual(self.text, "Entry text") 

40 """ 

41 

42 def test_entry__str__(self): 

43 if len(self.entry.text[:]) < 50: 43 ↛ 46line 43 didn't jump to line 46 because the condition on line 43 was always true1b

44 self.assertEqual(str(self.entry), self.entry.text) 1b

45 else: 

46 self.assertEqual(str(self.entry), f"{self.entry.text[:50]} ... ") 

47 

48 def test_long_entry__str__(self): 

49 if len(self.long_entry.text[:]) < 50: 49 ↛ 50line 49 didn't jump to line 50 because the condition on line 49 was never true1c

50 self.assertEqual(str(self.long_entry), self.long_entry.text) 

51 else: 

52 self.assertEqual(str(self.long_entry), f"{self.long_entry.text[:50]}...") 1c