Coverage for apis_core/collections/tests/tests.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:51 +0000

1from django.contrib.auth.models import User 

2from django.test import TestCase 

3from faker import Faker 

4 

5from apis_core.collections.models import SkosCollection, SkosCollectionContentObject 

6 

7fake = Faker() 

8 

9 

10class SkosCollectionTestCase(TestCase): 

11 def test_name(self): 

12 name = fake.name() 

13 skc = SkosCollection.objects.create(name=name) 

14 self.assertEqual(str(skc), name) 

15 

16 def test_parent_name(self): 

17 nameparent = fake.name() 

18 namechild = fake.name() 

19 parent = SkosCollection.objects.create(name=nameparent) 

20 child = SkosCollection.objects.create(name=namechild, parent=parent) 

21 self.assertEqual(str(child.parent), nameparent) 

22 self.assertEqual(len(parent.children()), 1) 

23 

24 def test_parent_children(self): 

25 parent = SkosCollection.objects.create() 

26 SkosCollection.objects.create(parent=parent) 

27 self.assertEqual(len(parent.children()), 1) 

28 

29 def test_parent_children_tree_as_list(self): 

30 parent = SkosCollection.objects.create() 

31 child1 = SkosCollection.objects.create(parent=parent) 

32 child2 = SkosCollection.objects.create(parent=child1) 

33 self.assertEqual(parent.children_tree_as_list(), [parent, child1, child2]) 

34 

35 

36class SkosCollectionContentObjectTestCase(TestCase): 

37 def setUp(self): 

38 self.collection_name = fake.color_name() 

39 self.collection = SkosCollection.objects.create(name=self.collection_name) 

40 

41 def test_collection(self): 

42 user = User.objects.create(username=fake.name()) 

43 scco = SkosCollectionContentObject( 

44 collection=self.collection, content_object=user 

45 ) 

46 self.assertEqual(str(scco), f"{user} -> {self.collection_name}")