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")
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")
def test_classic_page_str(self): page = ClassicPage( slug="page", name="Page", redirect="http://www.example.com", ) self.assertEqual(page.__str__(), "Page")
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")
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")