def test_get_context_data(self): """Test getting context data.""" user = UserFactory.create(**{'is_superuser': True}) # 1 contribution, 1 comment project_1 = ProjectFactory.create() category_1 = CategoryFactory.create(project=project_1) contribution_1 = ObservationFactory.create( project=project_1, category=category_1) CommentFactory.create(commentto=contribution_1) # 2 contributions (1 deleted), 2 comments project_2 = ProjectFactory.create(add_admins=[user]) category_2 = CategoryFactory.create(project=project_2) contribution_2 = ObservationFactory.create( project=project_2, category=category_2) CommentFactory.create(commentto=contribution_2) contribution_3 = ObservationFactory.create( project=project_2, category=category_2) CommentFactory.create(commentto=contribution_3) contribution_3.delete() # 2 contributions (1 deleted), 3 comments (1 deleted) project_3 = ProjectFactory.create(add_moderators=[user]) category_3 = CategoryFactory.create(project=project_3) contribution_4 = ObservationFactory.create( project=project_3, category=category_3) CommentFactory.create(commentto=contribution_4) comment_to_delete = CommentFactory.create(commentto=contribution_4) comment_to_delete.delete() contribution_5 = ObservationFactory.create( project=project_3, category=category_3) CommentFactory.create(commentto=contribution_5) contribution_5.delete() # 1 contribution, 2 comments (1 deleted) project_4 = ProjectFactory.create(add_contributors=[user]) category_4 = CategoryFactory.create(project=project_4) contribution_6 = ObservationFactory.create( project=project_4, category=category_4) CommentFactory.create(commentto=contribution_6) comment_to_delete = CommentFactory.create(commentto=contribution_6) comment_to_delete.delete() view = ManageProjects() context = view.get_context_data() self.assertEqual(len(context.get('projects')), 4) for project in context.get('projects'): project.refresh_from_db() self.assertEqual(project.contributions_count, 1) self.assertEqual(project.comments_count, 1) self.assertEqual(project.media_count, 0)
def test_get_context_data(self): """Test getting context data.""" user = UserFactory.create(**{'is_superuser': True}) # 1 contribution, 1 comment project_1 = ProjectFactory.create() category_1 = CategoryFactory.create(project=project_1) contribution_1 = ObservationFactory.create(project=project_1, category=category_1) CommentFactory.create(commentto=contribution_1) # 2 contributions (1 deleted), 2 comments project_2 = ProjectFactory.create(add_admins=[user]) category_2 = CategoryFactory.create(project=project_2) contribution_2 = ObservationFactory.create(project=project_2, category=category_2) CommentFactory.create(commentto=contribution_2) contribution_3 = ObservationFactory.create(project=project_2, category=category_2) CommentFactory.create(commentto=contribution_3) contribution_3.delete() # 2 contributions (1 deleted), 3 comments (1 deleted) project_3 = ProjectFactory.create(add_moderators=[user]) category_3 = CategoryFactory.create(project=project_3) contribution_4 = ObservationFactory.create(project=project_3, category=category_3) CommentFactory.create(commentto=contribution_4) comment_to_delete = CommentFactory.create(commentto=contribution_4) comment_to_delete.delete() contribution_5 = ObservationFactory.create(project=project_3, category=category_3) CommentFactory.create(commentto=contribution_5) contribution_5.delete() # 1 contribution, 2 comments (1 deleted) project_4 = ProjectFactory.create(add_contributors=[user]) category_4 = CategoryFactory.create(project=project_4) contribution_6 = ObservationFactory.create(project=project_4, category=category_4) CommentFactory.create(commentto=contribution_6) comment_to_delete = CommentFactory.create(commentto=contribution_6) comment_to_delete.delete() view = ManageProjects() context = view.get_context_data() self.assertEqual(len(context.get('projects')), 4) for project in context.get('projects'): project.refresh_from_db() self.assertEqual(project.contributions_count, 1) self.assertEqual(project.comments_count, 1) self.assertEqual(project.media_count, 0)
def test_get_with_superuser(self): """Test GET with superuser.""" view = ManageProjects.as_view() self.request.user = UserFactory.create(**{"is_superuser": True}) response = view(self.request).render() self.assertEqual(response.status_code, 200)
def test_get_with_anonymous(self): """Test GET with anonymous user.""" view = ManageProjects.as_view() self.request.user = AnonymousUser() response = view(self.request) self.assertTrue(isinstance(response, HttpResponseRedirect))
def test_get_with_superuser(self): """Test GET with superuser.""" view = ManageProjects.as_view() self.request.user = UserFactory.create(**{'is_superuser': True}) response = view(self.request).render() self.assertEqual(response.status_code, 200)
def test_get_with_user(self): """Test GET with user.""" view = ManageProjects.as_view() self.request.user = UserFactory.create(**{"is_superuser": False}) response = view(self.request).render() self.assertEqual(response.status_code, 200) self.assertContains(response, "No rights to access superuser tools.")
def test_get_with_user(self): """Test GET with user.""" view = ManageProjects.as_view() self.request.user = UserFactory.create(**{'is_superuser': False}) response = view(self.request).render() self.assertEqual(response.status_code, 200) self.assertContains(response, 'No rights to access superuser tools.')