99from django .conf import settings
1010from django .utils import timezone
1111
12- from pontoon .base .models import TranslatedResource , Translation , TranslationMemoryEntry
12+ from pontoon .actionlog .models import ActionLog
13+ from pontoon .base .models import (
14+ Entity ,
15+ TranslatedResource ,
16+ Translation ,
17+ TranslationMemoryEntry ,
18+ )
1319from pontoon .base .tests import (
1420 EntityFactory ,
1521 LocaleFactory ,
@@ -63,6 +69,11 @@ def test_add_ftl_translation():
6369 active = True ,
6470 approved = True ,
6571 )
72+ TranslationFactory .create (
73+ entity = Entity .objects .get (resource = res ["c" ], key = "key-c-1" ),
74+ locale = locale ,
75+ string = "key-c-1 = New translation c 1\n " ,
76+ )
6677
6778 project .refresh_from_db ()
6879 assert project .total_strings == 9
@@ -72,8 +83,8 @@ def test_add_ftl_translation():
7283 c_ftl = dedent (
7384 """
7485 key-c-0 = Translation c 0
75- key-c-1 = Translation c 1
76- key-c-2 = Translation c 2
86+ key-c-1 = New translation c 1
87+ key-c-2 = New translation c 2
7788 """
7889 )
7990 makedirs (repo .checkout_path )
@@ -108,15 +119,30 @@ def test_add_ftl_translation():
108119 tr_c2 = next (trans for trans in translations if trans .entity .key == "key-c-2" )
109120 assert not tr_c2 .user
110121
122+ # Test actions
123+ assert {
124+ (action .translation .string , action .action_type )
125+ for action in ActionLog .objects .filter (translation__in = translations )
126+ } == {
127+ ("key-c-1 = Translation c 1\n " , "translation:rejected" ),
128+ ("key-c-1 = New translation c 1\n " , "translation:approved" ),
129+ ("key-c-2 = New translation c 2\n " , "translation:created" ),
130+ }
131+
111132 # Test stats
112133 update_stats (project )
113134 project .refresh_from_db ()
114135 assert project .total_strings == 9
115136 assert project .approved_strings == 9
116137 tm = TranslationMemoryEntry .objects .filter (
117138 entity__resource = res ["c" ], translation__isnull = False
118- )
119- assert len (tm ) == 3
139+ ).values_list ("target" , flat = True )
140+ assert set (tm ) == {
141+ "Translation c 0" ,
142+ "Translation c 1" ,
143+ "New translation c 1" ,
144+ "New translation c 2" ,
145+ }
120146
121147
122148@pytest .mark .django_db
0 commit comments