def test_invalid_files(self):
     folder = "glossary-invalid-files"
     glossary_loader = GlossaryTermsLoader(base_path=self.base_path,
                                           content_path=folder)
     glossary_loader.load()
     glossary_objects = GlossaryTerm.objects.all()
     self.assertQuerysetEqual(glossary_objects, ["<GlossaryTerm: Term 1>"])
 def test_basic_config(self):
     folder = "glossary-single"
     glossary_loader = GlossaryTermsLoader(base_path=self.base_path,
                                           content_path=folder)
     glossary_loader.load()
     glossary_objects = GlossaryTerm.objects.all()
     self.assertQuerysetEqual(glossary_objects, ["<GlossaryTerm: Term 1>"])
 def test_multiple_files(self):
     folder = "glossary-multiple"
     glossary_loader = GlossaryTermsLoader(base_path=self.base_path,
                                           content_path=folder)
     glossary_loader.load()
     glossary_objects = GlossaryTerm.objects.order_by("term")
     self.assertQuerysetEqual(
         glossary_objects,
         [
             "<GlossaryTerm: Term 1>", "<GlossaryTerm: Term 2>",
             "<GlossaryTerm: Term 3>"
         ],
     )
 def tests_empty_file(self):
     folder = "glossary-empty-file"
     glossary_loader = GlossaryTermsLoader(base_path=self.base_path,
                                           content_path=folder)
     self.assertRaises(
         NoHeadingFoundInMarkdownFileError,
         glossary_loader.load,
     )
 def test_title_empty_content(self):
     folder = "glossary-missing-content"
     glossary_loader = GlossaryTermsLoader(base_path=self.base_path,
                                           content_path=folder)
     self.assertRaises(
         EmptyMarkdownFileError,
         glossary_loader.load,
     )
 def test_missing_title(self):
     folder = "glossary-missing-title"
     glossary_loader = GlossaryTermsLoader(base_path=self.base_path,
                                           content_path=folder)
     self.assertRaises(
         NoHeadingFoundInMarkdownFileError,
         glossary_loader.load,
     )
    def test_translation(self):
        folder = "glossary-translation"

        glossary_loader = GlossaryTermsLoader(base_path=self.base_path,
                                              content_path=folder)
        glossary_loader.load()

        glossary_objects = GlossaryTerm.objects.all()
        self.assertEqual(2, len(glossary_objects))

        translated_term = GlossaryTerm.objects.get(slug="glossary-term-1")
        untranslated_term = GlossaryTerm.objects.get(slug="glossary-term-2")

        self.assertSetEqual(set(["en", "de"]), set(translated_term.languages))
        self.assertSetEqual(set(["en"]), set(untranslated_term.languages))

        self.assertEqual("Term 1 English", translated_term.term)
        self.assertIn("English definition.", translated_term.definition)
        with translation.override("de"):
            self.assertEqual("Term 1 German", translated_term.term)
            self.assertIn("German definition.", translated_term.definition)
 def create_glossary_terms_loader(self, **kwargs):
     """Create glossary terms loader."""
     return GlossaryTermsLoader(**kwargs)