예제 #1
0
파일: tests.py 프로젝트: papedaniel/oioioi
 def test_cansee(self):
     controller = CodeSharingController()
     user1 = User.objects.get(pk=1001)
     user2 = User.objects.get(pk=1002)
     user3 = User.objects.get(pk=1003)
     user4 = User.objects.get(pk=1004)
     problem = Problem.objects.get(pk=1)
     # user2 doesn't allow code sharing (no row in model, defaults to false)
     self.assertFalse(controller.can_see_code(problem, user1, user2))
     # user1 doesn't allow code sharing (disabled option in preferences)
     self.assertFalse(controller.can_see_code(problem, user2, user1))
     # user1 and user3 are not friends
     self.assertFalse(controller.can_see_code(problem, user1, user3))
     # user3 doesn't have submissions
     self.assertFalse(controller.can_see_code(problem, user2, user3))
     # user2 doesn't allow code sharing (no row in model, defaults to false)
     self.assertFalse(controller.can_see_code(problem, user3, user2))
     #
     # [!!!] Everything in order
     #
     self.assertTrue(controller.can_see_code(problem, user3, user4))
     self.assertTrue(controller.can_see_code(problem, user2, user4))
     # No submission
     self.assertFalse(controller.can_see_code(problem, user4, user3))
     # Not friends
     self.assertFalse(controller.can_see_code(problem, user1, user4))
     # Not allowed
     self.assertFalse(controller.can_see_code(problem, user4, user2))
예제 #2
0
def problem_site_shared_solutions(request, problem):
    controller = CodeSharingController()
    submissions = controller.shared_with_me(problem, request.user)
    return TemplateResponse(request,
        'gamification/shared_submissions_tab.html',
        {'submissions': submissions,
         'submissions_on_page': getattr(settings, 'SUBMISSIONS_ON_PAGE', 20)}
    )
예제 #3
0
def problem_site_shared_solutions(request, problem):
    controller = CodeSharingController()
    submissions = controller.shared_with_me(problem, request.user)
    return TemplateResponse(
        request, 'gamification/shared_submissions_tab.html', {
            'submissions': submissions,
            'submissions_on_page': getattr(settings, 'SUBMISSIONS_ON_PAGE', 20)
        })
예제 #4
0
 def test_sharedwithme(self):
     controller = CodeSharingController()
     problem = Problem.objects.get(pk=1)
     user1 = User.objects.get(pk=1001)
     user2 = User.objects.get(pk=1002)
     user4 = User.objects.get(pk=1004)
     user4_submission = Submission.objects.get(pk=1)
     self.assertEquals(list(controller.shared_with_me(problem, user1).all()), [])
     self.assertEquals(list(controller.shared_with_me(problem, user2).all()), [user4_submission])
     self.assertEquals(list(controller.shared_with_me(problem, user4).all()), [])
예제 #5
0
 def test_sharedwithme(self):
     controller = CodeSharingController()
     problem = Problem.objects.get(pk=1)
     user1 = User.objects.get(pk=1001)
     user2 = User.objects.get(pk=1002)
     user4 = User.objects.get(pk=1004)
     user4_submission = Submission.objects.get(pk=1)
     self.assertEquals(
         list(controller.shared_with_me(problem, user1).all()), [])
     self.assertEquals(
         list(controller.shared_with_me(problem, user2).all()),
         [user4_submission])
     self.assertEquals(
         list(controller.shared_with_me(problem, user4).all()), [])
예제 #6
0
 def test_cansee(self):
     controller = CodeSharingController()
     user1 = User.objects.get(pk=1001)
     user2 = User.objects.get(pk=1002)
     user3 = User.objects.get(pk=1003)
     user4 = User.objects.get(pk=1004)
     problem = Problem.objects.get(pk=1)
     # user2 doesn't allow code sharing (no row in model, defaults to false)
     self.assertFalse(controller.can_see_code(problem, user1, user2))
     # user1 doesn't allow code sharing (disabled option in preferences)
     self.assertFalse(controller.can_see_code(problem, user2, user1))
     # user1 and user3 are not friends
     self.assertFalse(controller.can_see_code(problem, user1, user3))
     # user3 doesn't have submissions
     self.assertFalse(controller.can_see_code(problem, user2, user3))
     # user2 doesn't allow code sharing (no row in model, defaults to false)
     self.assertFalse(controller.can_see_code(problem, user3, user2))
     #
     # [!!!] Everything in order
     #
     self.assertTrue(controller.can_see_code(problem, user3, user4))
     self.assertTrue(controller.can_see_code(problem, user2, user4))
     # No submission
     self.assertFalse(controller.can_see_code(problem, user4, user3))
     # Not friends
     self.assertFalse(controller.can_see_code(problem, user1, user4))
     # Not allowed
     self.assertFalse(controller.can_see_code(problem, user4, user2))