|
17 | 17 | ChangedEntityLocale, |
18 | 18 | Entity, |
19 | 19 | Locale, |
| 20 | + ProjectLocale, |
20 | 21 | Repository, |
21 | 22 | TranslatedResource, |
22 | 23 | Translation, |
@@ -242,7 +243,11 @@ def test_add_resources(): |
242 | 243 | assert { |
243 | 244 | (tr.resource.path, tr.locale.code) |
244 | 245 | for tr in TranslatedResource.objects.filter(resource__project=project) |
245 | | - } == {("file.ftl", "de-Test"), ("file.xliff", "de-Test")} |
| 246 | + } == { |
| 247 | + ("file.ftl", "de-Test"), |
| 248 | + ("file.po", "de-Test"), |
| 249 | + ("file.xliff", "de-Test"), |
| 250 | + } |
246 | 251 |
|
247 | 252 | # Add an XLIFF translation |
248 | 253 | TranslationFactory.create( |
@@ -848,3 +853,82 @@ def test_add_project_locale(): |
848 | 853 | tr.locale.code: tr.total_strings |
849 | 854 | for tr in TranslatedResource.objects.filter(resource__project=project) |
850 | 855 | } == {"fr-Test": 1, "de-Test": 1} |
| 856 | + |
| 857 | + |
| 858 | +@pytest.mark.django_db |
| 859 | +def test_locales_from_repo(): |
| 860 | + mock_vcs = MockVersionControl(changed=[]) |
| 861 | + with mock_setup(mock_vcs) as (repo, _): |
| 862 | + LocaleFactory.create(code="fr-Test", name="Test French") |
| 863 | + |
| 864 | + # Database setup |
| 865 | + project = ProjectFactory.create( |
| 866 | + name="test-repo-locales", |
| 867 | + locales=[], |
| 868 | + repositories=[repo], |
| 869 | + set_locales_from_repo=True, |
| 870 | + system_project=False, |
| 871 | + ) |
| 872 | + |
| 873 | + # Filesystem setup |
| 874 | + makedirs(repo.checkout_path) |
| 875 | + build_file_tree( |
| 876 | + repo.checkout_path, |
| 877 | + { |
| 878 | + "en-US": {"messages.json": '{ "key": { "message": "Entity" } }'}, |
| 879 | + "de-Test": {"messages.json": "{}"}, |
| 880 | + "fr-Test": {"messages.json": "{}"}, |
| 881 | + }, |
| 882 | + ) |
| 883 | + |
| 884 | + sync_project_task(project.pk) |
| 885 | + |
| 886 | + assert { |
| 887 | + pl.locale.code for pl in ProjectLocale.objects.filter(project=project) |
| 888 | + } == {"de-Test", "fr-Test"} |
| 889 | + assert { |
| 890 | + tr.locale.code: tr.total_strings |
| 891 | + for tr in TranslatedResource.objects.filter(resource__project=project) |
| 892 | + } == {"fr-Test": 1, "de-Test": 1} |
| 893 | + |
| 894 | + |
| 895 | +@pytest.mark.django_db |
| 896 | +def test_locales_from_config(): |
| 897 | + mock_vcs = MockVersionControl(changed=[]) |
| 898 | + with mock_setup(mock_vcs) as (repo, _): |
| 899 | + LocaleFactory.create(code="fr-Test", name="Test French") |
| 900 | + |
| 901 | + # Database setup |
| 902 | + project = ProjectFactory.create( |
| 903 | + name="test-config-locales", |
| 904 | + configuration_file="l10n.toml", |
| 905 | + locales=[], |
| 906 | + repositories=[repo], |
| 907 | + set_locales_from_repo=True, |
| 908 | + system_project=False, |
| 909 | + ) |
| 910 | + |
| 911 | + # Filesystem setup |
| 912 | + makedirs(repo.checkout_path) |
| 913 | + build_file_tree( |
| 914 | + repo.checkout_path, |
| 915 | + { |
| 916 | + "foo": {"en": {"messages.json": '{ "key": { "message": "Entity" } }'}}, |
| 917 | + "l10n.toml": dedent("""\ |
| 918 | + locales = ["de-Test", "fr-Test"] |
| 919 | + [[paths]] |
| 920 | + reference = "foo/en/**" |
| 921 | + l10n = "foo/{locale}/**" |
| 922 | + """), |
| 923 | + }, |
| 924 | + ) |
| 925 | + |
| 926 | + sync_project_task(project.pk) |
| 927 | + |
| 928 | + assert { |
| 929 | + pl.locale.code for pl in ProjectLocale.objects.filter(project=project) |
| 930 | + } == {"de-Test", "fr-Test"} |
| 931 | + assert { |
| 932 | + tr.locale.code: tr.total_strings |
| 933 | + for tr in TranslatedResource.objects.filter(resource__project=project) |
| 934 | + } == {"fr-Test": 1, "de-Test": 1} |
0 commit comments