Exemplo n.º 1
0
    def load(self):
        """Load Classic CS Unplugged pages.

        Raise:
            MissingRequiredFieldError: when no object can be found with the matching
                attribute.
        """
        classic_pages = self.load_yaml_file(self.structure_file_path)

        for (slug, page_data) in classic_pages.items():
            try:
                name = page_data["name"]
            except (TypeError, KeyError):
                raise MissingRequiredFieldError(
                    self.structure_file_path,
                    [
                        "name",
                    ],
                    "Classic CS Unplugged page"
                )

            redirect_url = urljoin("https://classic.csunplugged.org/", slug)

            classic_page = ClassicPage(
                slug=slug,
                name=name,
                redirect=redirect_url,
            )
            classic_page.save()
            self.log("Added Classic CS Unplugged page: {}".format(name))
        self.log("All Classic CS Unplugged pages loaded!\n")
Exemplo n.º 2
0
 def test_classic_page_model_get_absolute_url(self):
     page = ClassicPage(
         slug="page",
         name="Page",
         redirect="http://www.example.com",
     )
     self.assertEqual(page.get_absolute_url(), "http://www.example.com")
Exemplo n.º 3
0
 def test_classic_page_str(self):
     page = ClassicPage(
         slug="page",
         name="Page",
         redirect="http://www.example.com",
     )
     self.assertEqual(page.__str__(), "Page")
Exemplo n.º 4
0
 def test_classic_page_model_type(self):
     page = ClassicPage(
         slug="page",
         name="Page",
         redirect="http://www.example.com",
     )
     self.assertEqual(page.model_type(), "Classic CS Unplugged page")
Exemplo n.º 5
0
 def test_rebuild_index_command_classic_page_model(self):
     page = ClassicPage(
         slug="page",
         name="Page",
         redirect="http://www.example.com",
     )
     page.save()
     management.call_command("rebuild_index", "--noinput")