@@ -42,7 +42,7 @@ def test_no_changes():
4242
4343
4444@pytest .mark .django_db
45- def test_remove_resource ():
45+ def test_resource_obsoletion ():
4646 with TemporaryDirectory () as root :
4747 # Database setup
4848 settings .MEDIA_ROOT = root
@@ -52,10 +52,18 @@ def test_remove_resource():
5252 project = ProjectFactory .create (
5353 name = "test-rm" , locales = [locale ], repositories = [repo ]
5454 )
55- ResourceFactory .create (project = project , path = "a.ftl" , format = "fluent" )
56- ResourceFactory .create (project = project , path = "b.po" , format = "gettext" )
55+ res_a = ResourceFactory .create (project = project , path = "a.ftl" , format = "fluent" )
56+ res_b = ResourceFactory .create (project = project , path = "b.po" , format = "gettext" )
5757 res_c = ResourceFactory .create (project = project , path = "c.ftl" , format = "fluent" )
58+ entity_a = EntityFactory .create (resource = res_a , string = "Window" )
59+ entity_b = EntityFactory .create (resource = res_b , string = "Close" )
5860 entity_c = EntityFactory .create (resource = res_c , string = "Hello" )
61+ translation_a = TranslationFactory .create (
62+ entity = entity_a , locale = locale , string = "Fenetre"
63+ )
64+ translation_b = TranslationFactory .create (
65+ entity = entity_b , locale = locale , string = "Ferme"
66+ )
5967 translation_c = TranslationFactory .create (
6068 entity = entity_c , locale = locale , string = "Bonjour"
6169 )
@@ -70,6 +78,12 @@ def test_remove_resource():
7078 },
7179 )
7280
81+ # check TranslatedResource objects before resource obsoletion
82+ assert {
83+ translated .resource .path
84+ for translated in TranslatedResource .objects .current ()
85+ } == {"a.ftl" , "b.po" , "c.ftl" , "common" , "playground" }
86+
7387 # Paths setup
7488 mock_checkout = Mock (
7589 Checkout ,
@@ -80,7 +94,7 @@ def test_remove_resource():
8094 )
8195 paths = find_paths (project , Checkouts (mock_checkout , mock_checkout ))
8296
83- # Test
97+ # Test sync_resources_from_repo
8498 assert sync_resources_from_repo (
8599 project , locale_map , mock_checkout , paths , now
86100 ) == (0 , set (), {"c.ftl" })
@@ -94,8 +108,18 @@ def test_remove_resource():
94108 "b.po" ,
95109 }
96110 assert TranslatedResource .objects .filter (resource = res_c ).exists ()
111+ assert {
112+ translated .resource .path
113+ for translated in TranslatedResource .objects .current ()
114+ } == {"a.ftl" , "b.po" , "common" , "playground" }
97115 assert Entity .objects .filter (pk = entity_c .pk ).exists ()
98- assert Translation .objects .filter (pk = translation_c .pk ).exists ()
116+
117+ assert (
118+ Translation .objects .filter (
119+ pk__in = [translation_a .pk , translation_b .pk , translation_c .pk ]
120+ ).count ()
121+ == 3
122+ )
99123
100124
101125@pytest .mark .django_db
0 commit comments