def setUp(self): """ create a user for testing the Issue views """ u = User.objects.create_user(username="******", email="*****@*****.**", password="******") p = Project(name="Test project", description="This is a test project") p.save() p.team = [u] c = Component(name="Test component", description="This is a test component", project=p, owner=u) c.save() m = Milestone(name="Test milestone", project=p) m.save() self.i = Issue( title="Issue", description="Test description", creator=u, assignee=u, project=p, milestone=m, component=c, status=1, priority=3, ) self.i.save()
class IssueViewTest(TestCase): c = Client() def setUp(self): """ create a user for testing the Issue views """ u = User.objects.create_user(username="******", email="*****@*****.**", password="******") p = Project(name="Test project", description="This is a test project") p.save() p.team = [u] c = Component(name="Test component", description="This is a test component", project=p, owner=u) c.save() m = Milestone(name="Test milestone", project=p) m.save() self.i = Issue( title="Issue", description="Test description", creator=u, assignee=u, project=p, milestone=m, component=c, status=1, priority=3, ) self.i.save() def test_user_list_redirect_response(self): """ Test response code of the user issue list view, when the user isn't logged in """ response = self.c.get(reverse("bubble_user_issue_list")) self.assertRedirects( response=response, expected_url="/accounts/login/?next=%s" % reverse("bubble_user_issue_list") ) def test_user_list_logged_in_response(self): """ Test response code of the user issue list view when the user has logged in """ # ensure we can login successfully self.assertTrue(self.c.login(username="******", password="******")) # test that we get the correct response now (not a redirect) response = self.c.get(reverse("bubble_user_issue_list")) self.assertEqual(response.status_code, 200) def test_issue_redirect_response(self): """ Test response code of the issue detail view, when the user isn't logged in """ url = Issue.objects.all()[0].get_absolute_url() response = self.c.get(url) self.assertRedirects(response=response, expected_url="/accounts/login/?next=%s" % url) def test_issue_logged_in_response(self): """ Test response code of the issue detail view when the user has logged in """ url = Issue.objects.all()[0].get_absolute_url() # ensure we can login successfully self.assertTrue(self.c.login(username="******", password="******")) # test that we get the correct response now (not a redirect) response = self.c.get(url) self.assertEqual(response.status_code, 200) def test_issue_comment_post(self): """ Test posting a comment on an issue. Ensure the form redirects correctly and the comment appears in the content of the page. """ url = Issue.objects.all()[0].get_absolute_url() # ensure we can login successfully self.assertTrue(self.c.login(username="******", password="******")) response = self.c.post(url, {"title": "Testing a comment post", "comment": "This is a test comment..."}) self.assertRedirects(response=response, expected_url=url) get = self.c.get(url) self.assertContains(get, "This is a test comment...") def test_issue_nonexistent(self): """ Ensure that a non-existent comment returns a 404 response. """ # a large non-existent id url = "/issues/999999/" self.assertTrue(self.c.login(username="******", password="******")) get = self.c.get(url) self.assertEqual(get.status_code, 404) def test_issue_components_logged_out(self): """ Test the component list view redirects out to the login page when not logged in. """ url = reverse("bubble_projects_components_list", kwargs={"pk": self.i.pk}) self.assertTrue(self.c.login(username="******", password="******")) def test_issue_components(self): """ Test the component list view gives a valid response """ url = reverse("bubble_projects_components_list", kwargs={"pk": self.i.pk}) self.assertTrue(self.c.login(username="******", password="******")) get = self.c.get(url) self.assertEqual(get.status_code, 200)