@@ -299,6 +299,70 @@ def test_add_resource():
299299 }
300300
301301
302+ @pytest .mark .django_db
303+ def test_add_resource_with_comments ():
304+ with TemporaryDirectory () as root :
305+ # Database setup
306+ settings .MEDIA_ROOT = root
307+ locale = LocaleFactory .create (code = "fr-Test" )
308+ locale_map = {locale .code : locale }
309+ repo = RepositoryFactory (url = "http://example.com/repo" )
310+ project = ProjectFactory .create (
311+ name = "test-add-comments" , locales = [locale ], repositories = [repo ]
312+ )
313+
314+ # Filesystem setup: FTL file with a license header, a resource comment (###)
315+ # and a group comment (##).
316+ c_ftl = dedent (
317+ """\
318+ # This Source Code Form is subject to the terms of the Mozilla Public
319+ # License, v. 2.0.
320+
321+ ### Resource-level comment for this file.
322+
323+ ## Group comment for the first section.
324+
325+ key-1 = Message 1
326+ key-2 = Message 2
327+ """
328+ )
329+ makedirs (repo .checkout_path )
330+ build_file_tree (
331+ repo .checkout_path ,
332+ {
333+ "en-US" : {"c.ftl" : c_ftl },
334+ "fr-Test" : {},
335+ },
336+ )
337+
338+ # Paths setup
339+ mock_checkout = Mock (
340+ Checkout ,
341+ path = repo .checkout_path ,
342+ changed = [join ("en-US" , "c.ftl" )],
343+ removed = [],
344+ renamed = [],
345+ )
346+ paths = find_paths (project , Checkouts (mock_checkout , mock_checkout ))
347+
348+ # Test
349+ assert sync_resources_from_repo (
350+ project , locale_map , mock_checkout , paths , now
351+ ) == (2 , {"c.ftl" }, set ())
352+ res_c = project .resources .get (path = "c.ftl" )
353+ assert res_c .comment == "Resource-level comment for this file."
354+ assert res_c .meta == [
355+ [
356+ "info" ,
357+ "This Source Code Form is subject to the terms of the Mozilla Public\n "
358+ "License, v. 2.0." ,
359+ ]
360+ ]
361+ sections = list (res_c .sections .all ())
362+ assert len (sections ) == 1
363+ assert sections [0 ].comment == "Group comment for the first section."
364+
365+
302366@pytest .mark .django_db
303367def test_update_resource ():
304368 with TemporaryDirectory () as root :
0 commit comments