def test_get_yaml_translations_english(self):

        yaml_file = "basic.yaml"
        loader = TranslatableModelLoader(base_path=self.base_path)
        translations = loader.get_yaml_translations(yaml_file)

        self.assertIsInstance(translations, dict)
        self.assertSetEqual(set(["model1", "model2"]), set(translations.keys()))

        model1_translations = translations["model1"]
        self.assertIsInstance(model1_translations, dict)
        self.assertSetEqual(set(["en"]), set(model1_translations.keys()))
        model1_english = model1_translations["en"]
        self.assertIsInstance(model1_english, dict)
        self.assertSetEqual(set(["field1", "field2"]), set(model1_english.keys()))
        self.assertEqual("value 1-1", model1_english["field1"])
        self.assertEqual("value 1-2", model1_english["field2"])

        model2_translations = translations["model2"]
        self.assertIsInstance(model2_translations, dict)
        self.assertSetEqual(set(["en"]), set(model2_translations.keys()))
        model2_english = model2_translations["en"]
        self.assertIsInstance(model2_english, dict)
        self.assertSetEqual(set(["field1", "field2"]), set(model2_english.keys()))
        self.assertEqual("value 2-1", model2_english["field1"])
        self.assertEqual("value 2-2", model2_english["field2"])
    def test_get_yaml_translations_translated_missing_reqd_slug(self):
        yaml_file = "translationmissingreqdslug.yaml"
        loader = TranslatableModelLoader(base_path=self.base_path)

        # required slugs only apply to default language (en) so no error should be raised
        translations = loader.get_yaml_translations(yaml_file, required_slugs=["model1", "model2"])
        self.assertSetEqual(set(["en", "de"]), set(translations["model1"].keys()))
        self.assertSetEqual(set(["en"]), set(translations["model2"].keys()))
 def test_get_yaml_translations_field_map(self):
     yaml_file = "basic.yaml"
     loader = TranslatableModelLoader(base_path=self.base_path)
     translations = loader.get_yaml_translations(
         yaml_file,
         field_map={"field1": "new_field1"}
     )
     model1 = translations["model1"]["en"]
     self.assertSetEqual(set(["new_field1", "field2"]), set(model1.keys()))
     self.assertEqual("value 1-1", model1["new_field1"])
 def test_get_yaml_translations_english_missing_file_with_reqd_slugs(self):
     yaml_file = "doesnotexist.yaml"
     loader = TranslatableModelLoader(base_path=self.base_path)
     # With required slugs, a missing english yaml file should raise Exception
     with self.assertRaises(CouldNotFindYAMLFileError):
         loader.get_yaml_translations(yaml_file, required_slugs=["model1", "model2"])
 def test_get_yaml_translations_english_missing_reqd_slug(self):
     yaml_file = "missingreqdslug.yaml"
     loader = TranslatableModelLoader(base_path=self.base_path)
     with self.assertRaises(MissingRequiredModelsError):
         loader.get_yaml_translations(yaml_file, required_slugs=["model1", "model2"])
 def test_get_yaml_translations_english_missing_reqd_field(self):
     yaml_file = "missingreqdfield.yaml"
     loader = TranslatableModelLoader(base_path=self.base_path)
     with self.assertRaises(MissingRequiredFieldError):
         loader.get_yaml_translations(yaml_file, required_fields=["field1"])
 def test_get_yaml_translations_english_missing_yaml_no_reqd_slugs(self):
     yaml_file = "doesnotexist.yaml"
     loader = TranslatableModelLoader(base_path=self.base_path)
     # If no required slugs, no error should be raised
     loader.get_yaml_translations(yaml_file)