def test_update_get(self): """Can we view a form to update newslinks?""" startup = StartupFactory() newslink = NewsLinkFactory(startup=startup) url_name = "newslink_update" self.get( url_name, startup_slug=startup.slug, newslink_slug=newslink.slug, ) self.response_302() with auth_user(self): self.get( url_name, startup_slug=startup.slug, newslink_slug=newslink.slug, ) self.response_403() with perm_user(self, "organizer.change_newslink"): response = self.get_check_200( url_name, startup_slug=startup.slug, newslink_slug=newslink.slug, ) form = self.get_context("form") self.assertIsInstance(form, NewsLinkForm) context_newslink = self.get_context("newslink") context_startup = self.get_context("startup") self.assertEqual(newslink.pk, context_newslink.pk) self.assertEqual(startup.pk, context_startup.pk) self.assertContext("update", True) self.assertTemplateUsed(response, "newslink/form.html") self.assertTemplateUsed(response, "newslink/base.html") self.assertTemplateUsed(response, "base.html")
def test_delete_get(self): """Can we view a form to delete a NewsLink?""" startup = StartupFactory() newslink = NewsLinkFactory(startup=startup) url_name = "newslink_delete" self.get( url_name, startup_slug=startup.slug, newslink_slug=newslink.slug, ) self.response_302() with auth_user(self): self.get( url_name, startup_slug=startup.slug, newslink_slug=newslink.slug, ) self.response_403() with perm_user(self, "organizer.delete_newslink"): response = self.get_check_200( url_name, startup_slug=startup.slug, newslink_slug=newslink.slug, ) context_newslink = self.get_context("newslink") context_startup = self.get_context("startup") self.assertEqual(newslink.pk, context_newslink.pk) self.assertEqual(startup.pk, context_startup.pk) self.assertTemplateUsed(response, "newslink/confirm_delete.html") self.assertTemplateUsed(response, "newslink/base.html") self.assertTemplateUsed(response, "base.html")
def test_delete_get(self): """Can we view a form to delete a Post?""" post = PostFactory() url_name = "post_delete" self.get( url_name, year=post.pub_date.year, month=post.pub_date.month, slug=post.slug, ) self.response_302() with auth_user(self): self.get( url_name, year=post.pub_date.year, month=post.pub_date.month, slug=post.slug, ) self.response_403() with perm_user(self, "blog.delete_post"): response = self.get_check_200( url_name, year=post.pub_date.year, month=post.pub_date.month, slug=post.slug, ) context_post = self.get_context("post") self.assertEqual(post.pk, context_post.pk) self.assertTemplateUsed( response, "post/confirm_delete.html" ) self.assertTemplateUsed( response, "post/base.html" ) self.assertTemplateUsed(response, "base.html")
def test_create_get(self): """Can we view the form to create NewsLinks?""" startup = StartupFactory() url_name = "newslink_create" self.get(url_name, startup_slug=startup.slug) self.response_302() with auth_user(self): self.get(url_name, startup_slug=startup.slug) self.response_403() with perm_user(self, "organizer.add_newslink"): response = self.get_check_200(url_name, startup_slug=startup.slug) form = self.get_context("form") self.assertIsInstance(form, NewsLinkForm) initial_startup_pk = form.initial.get("startup") self.assertIsNotNone( initial_startup_pk, "An initial value for the Startup must be " "provided to the NewsLinkForm", ) self.assertEqual( startup.pk, initial_startup_pk, f"Startup FK {startup.pk} not set in form, " f"found {initial_startup_pk} in form instead", ) context_startup = self.get_context("startup") self.assertEqual(startup.pk, context_startup.pk) self.assertContext("update", False) self.assertTemplateUsed(response, "newslink/form.html") self.assertTemplateUsed(response, "newslink/base.html") self.assertTemplateUsed(response, "base.html")
def test_tag_create_get(self): """Can we view a form to create Tags?""" url_name = "tag_create" self.get(url_name) self.response_302() with auth_user(self): self.get(url_name) self.response_403() with perm_user(self, "organizer.add_tag"): response = self.get_check_200(url_name) form = self.get_context("form") self.assertIsInstance(form, TagForm) self.assertContext("update", False) self.assertTemplateUsed(response, "tag/form.html") self.assertTemplateUsed(response, "tag/base.html") self.assertTemplateUsed(response, "base.html")
def test_delete_get(self): """Can we view a form to delete a Startup?""" startup = StartupFactory() url_name = "startup_delete" self.get(url_name, slug=startup.slug) self.response_302() with auth_user(self): self.get(url_name, slug=startup.slug) self.response_403() with perm_user(self, "organizer.delete_startup"): response = self.get_check_200(url_name, slug=startup.slug) context_startup = self.get_context("startup") self.assertEqual(startup.pk, context_startup.pk) self.assertTemplateUsed(response, "startup/confirm_delete.html") self.assertTemplateUsed(response, "startup/base.html") self.assertTemplateUsed(response, "base.html")
def test_tag_delete_get(self): """Can we view a form to delete a Tag?""" tag = TagFactory() url_name = "tag_delete" self.get(url_name, slug=tag.slug) self.response_302() with auth_user(self): self.get(url_name, slug=tag.slug) self.response_403() with perm_user(self, "organizer.delete_tag"): response = self.get_check_200(url_name, slug=tag.slug) context_tag = self.get_context("tag") self.assertEqual(tag.pk, context_tag.pk) self.assertTemplateUsed(response, "tag/confirm_delete.html") self.assertTemplateUsed(response, "tag/base.html") self.assertTemplateUsed(response, "base.html")
def test_tag_update_get(self): """Can we view a form to update Tags?""" tag = TagFactory() url_name = "tag_update" self.get(url_name, slug=tag.slug) self.response_302() with auth_user(self): self.get(url_name, slug=tag.slug) self.response_403() with perm_user(self, "organizer.change_tag"): response = self.get_check_200(url_name, slug=tag.slug) form = self.get_context("form") self.assertIsInstance(form, TagForm) context_tag = self.get_context("tag") self.assertEqual(tag.pk, context_tag.pk) self.assertContext("update", True) self.assertTemplateUsed(response, "tag/form.html") self.assertTemplateUsed(response, "tag/base.html") self.assertTemplateUsed(response, "base.html")
def test_update_get(self): """Can we view a form to update startups?""" startup = StartupFactory() url_name = "startup_update" self.get(url_name, slug=startup.slug) self.response_302() with auth_user(self): self.get(url_name, slug=startup.slug) self.response_403() with perm_user(self, "organizer.change_startup"): response = self.get_check_200(url_name, slug=startup.slug) form = self.get_context("form") self.assertIsInstance(form, StartupForm) context_startup = self.get_context("startup") self.assertEqual(startup.pk, context_startup.pk) self.assertContext("update", True) self.assertTemplateUsed(response, "startup/form.html") self.assertTemplateUsed(response, "startup/base.html") self.assertTemplateUsed(response, "base.html")
def test_create_get(self): """Can we view the form to create Posts?""" url_name = "post_create" self.get(url_name) self.response_302() with auth_user(self): self.get(url_name) self.response_403() with perm_user(self, "blog.add_post"): response = self.get_check_200(url_name) form = self.get_context("form") self.assertIsInstance(form, PostForm) self.assertContext("update", False) self.assertTemplateUsed( response, "post/form.html" ) self.assertTemplateUsed( response, "post/base.html" ) self.assertTemplateUsed(response, "base.html")
def test_update_get(self): """Can we view a form to update posts?""" post = PostFactory() url_name = "post_update" self.get( url_name, year=post.pub_date.year, month=post.pub_date.month, slug=post.slug, ) self.response_302() with auth_user(self): self.get( url_name, year=post.pub_date.year, month=post.pub_date.month, slug=post.slug, ) self.response_403() with perm_user(self, "blog.change_post"): response = self.get_check_200( url_name, year=post.pub_date.year, month=post.pub_date.month, slug=post.slug, ) form = self.get_context("form") self.assertIsInstance(form, PostForm) context_post = self.get_context("post") self.assertEqual(post.pk, context_post.pk) self.assertContext("update", True) self.assertTemplateUsed( response, "post/form.html" ) self.assertTemplateUsed( response, "post/base.html" ) self.assertTemplateUsed(response, "base.html")