Coverage for src/tests/core/domain/value_objects/test_text.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module that tests the Text value object.""" 

2 

3import dataclasses 

4 

5import pytest 

6 

7from kwai_core.domain.value_objects.identifier import IntIdentifier 

8from kwai_core.domain.value_objects.name import Name 

9from kwai_core.domain.value_objects.owner import Owner 

10from kwai_core.domain.value_objects.text import DocumentFormat, Locale, LocaleText, Text 

11from kwai_core.domain.value_objects.unique_id import UniqueId 

12 

13 

14@pytest.fixture() 

15def content(locale: Locale): 

16 """Create a fixture for Content.""" 

17 return LocaleText( 

18 locale=locale, 

19 format=DocumentFormat.MARKDOWN, 

20 title="Test", 

21 content="Test", 

22 summary="Test", 

23 author=Owner( 

24 id=IntIdentifier(1), 

25 uuid=UniqueId.generate(), 

26 name=Name(first_name="Jigoro", last_name="Kano"), 

27 ), 

28 ) 

29 

30 

31@pytest.mark.parametrize("locale", [Locale.NL]) 

32def test_add_translation(locale, request): 

33 """Test the add_translation method.""" 

34 content = request.getfixturevalue("content") 

35 text = Text().add_translation(content) 

36 assert text.contains_translation(locale), ( 

37 f"There should be a translation available for {locale}" 

38 ) 

39 

40 

41@pytest.mark.parametrize("locale", [Locale.NL]) 

42def test_remove_translation(locale, request): 

43 """Test the remove_translation method.""" 

44 content = request.getfixturevalue("content") 

45 text = Text().add_translation(content).remove_translation(content) 

46 assert not text.contains_translation(locale), ( 

47 f"There should be no translation available for {locale}" 

48 ) 

49 

50 

51@pytest.mark.parametrize("locale", [Locale.NL]) 

52def test_replace_translation(locale, request): 

53 """Test the replace_translation method.""" 

54 content = request.getfixturevalue("content") 

55 new_content = dataclasses.replace(content, content="Updated") 

56 text = Text().add_translation(content).replace_translation(new_content) 

57 assert text.contains_translation(locale), ( 

58 f"There should be a translation available for {locale}" 

59 ) 

60 assert text.get_translation(locale).content == "Updated", ( 

61 "The text should be updated" 

62 )