コード例 #1
0
    def test_can_save_shared_queryset(self):
        student = Artwork(
            author=self.user,
            title='Empty code',
            shared=1,
            code='// code goes here')
        student.save()

        staff = Artwork(
            author=self.staff_user,
            title='Empty code',
            shared=1,
            code='// code goes here')
        staff.save()

        superuser = Artwork(
            author=self.super_user,
            title='Empty code',
            shared=1,
            code='// code goes here')
        superuser.save()

        public_qs = Artwork.can_save_queryset()
        self.assertEqual(len(public_qs.all()), 0)

        student_qs = Artwork.can_save_queryset(user=self.user)
        self.assertEqual(len(student_qs.all()), 0)

        staff_qs = Artwork.can_save_queryset(user=self.staff_user)
        self.assertEqual(len(staff_qs.all()), 0)

        super_qs = Artwork.can_save_queryset(user=self.super_user)
        self.assertEqual(len(super_qs.all()), 0)
コード例 #2
0
    def test_cant_save_shared(self):
        student = Artwork(
            author=self.user,
            title='Empty code',
            shared=1,
            code='// code goes here')
        self.assertFalse(student.can_save(self.user))
        self.assertFalse(student.can_save(self.staff_user))
        self.assertFalse(student.can_save(self.super_user))

        staff = Artwork(
            author=self.staff_user,
            title='Empty code',
            shared=1,
            code='// code goes here')
        self.assertFalse(staff.can_save(self.user))
        self.assertFalse(staff.can_save(self.staff_user))
        self.assertFalse(staff.can_save(self.super_user))

        superuser = Artwork(
            author=self.super_user,
            title='Empty code',
            shared=1,
            code='// code goes here')
        self.assertFalse(superuser.can_save(self.user))
        self.assertFalse(superuser.can_save(self.staff_user))
        self.assertFalse(superuser.can_save(self.super_user))
コード例 #3
0
    def test_can_see_private_queryset(self):
        student = Artwork(
            author=self.user,
            title='Empty code',
            code='// code goes here')
        student.save()

        staff = Artwork(
            author=self.staff_user,
            title='Empty code',
            code='// code goes here')
        staff.save()

        superuser = Artwork(
            author=self.super_user,
            title='Empty code',
            code='// code goes here')
        superuser.save()

        public_qs = Artwork.can_see_queryset()
        self.assertEqual(len(public_qs.all()), 0)

        student_qs = Artwork.can_see_queryset(user=self.user)
        self.assertEqual(len(student_qs.all()), 1)
        self.assertEqual(student_qs.all()[0].id, student.id)

        staff_qs = Artwork.can_see_queryset(user=self.staff_user)
        self.assertEqual(len(staff_qs.all()), 1)
        self.assertEqual(staff_qs.all()[0].id, staff.id)

        super_qs = Artwork.can_see_queryset(user=self.super_user)
        self.assertEqual(len(super_qs.all()), 1)
        self.assertEqual(super_qs.all()[0].id, superuser.id)
コード例 #4
0
    def test_can_see(self):
        # Everyone can see submissions
        exhibition = Exhibition(title='New Exhibition', description='description goes here', released_at=timezone.now())
        student_artwork = Artwork(title='New Artwork', code='// code goes here', author=self.user)
        staff_artwork = Artwork(title='New Artwork', code='// code goes here', author=self.staff_user)
        submission = Submission(exhibition=exhibition, artwork=student_artwork)

        self.assertTrue(submission.can_see())
        self.assertTrue(submission.can_see(self.user))
        self.assertTrue(submission.can_see(self.staff_user))
        self.assertTrue(submission.can_see(self.super_user))
コード例 #5
0
    def test_str(self):
        
        artwork = Artwork(title='Empty code', code='// code goes here')

        self.assertEquals(
            str(artwork),
            'Empty code'
        )
コード例 #6
0
    def test_can_save_released_exhibition(self):

        exhibition = Exhibition(title='New Exhibition', description='description goes here', released_at=timezone.now())
        self.assertTrue(exhibition.released_yet)

        student_artwork = Artwork(title='New Artwork', code='// code goes here', author=self.user)
        staff_artwork = Artwork(title='New Artwork', code='// code goes here', author=self.staff_user)

        # only authors can submit artwork
        submission = Submission(exhibition=exhibition, artwork=student_artwork)
        self.assertTrue(submission.can_save(self.user))
        self.assertFalse(submission.can_save(self.staff_user))
        self.assertFalse(submission.can_save(self.super_user))

        submission = Submission(exhibition=exhibition, artwork=staff_artwork)
        self.assertFalse(submission.can_save(self.user))
        self.assertTrue(submission.can_save(self.staff_user))
        self.assertFalse(submission.can_save(self.super_user))
コード例 #7
0
    def test_str(self):
        
        exhibition = Exhibition(title='New Exhibition', description='description goes here')
        artwork = Artwork(title='New Artwork', code='// code goes here')

        submission = Submission(exhibition=exhibition, artwork=artwork)

        self.assertEquals(
            str(submission),
            'New Exhibition :: New Artwork'
        )
コード例 #8
0
    def test_can_save_unreleased_exhibition(self):

        exhibition = Exhibition(
            title='New Exhibition', 
            description='description goes here', 
            released_at=timezone.now() + timedelta(hours=24))
        self.assertFalse(exhibition.released_yet)

        student_artwork = Artwork(title='New Artwork', code='// code goes here', author=self.user)
        staff_artwork = Artwork(title='New Artwork', code='// code goes here', author=self.staff_user)

        # students cannot submit to unreleased exhibitions
        submission = Submission(exhibition=exhibition, artwork=student_artwork)
        self.assertFalse(submission.can_save(self.user))
        self.assertFalse(submission.can_save(self.staff_user))
        self.assertFalse(submission.can_save(self.super_user))

        # but staff can
        submission = Submission(exhibition=exhibition, artwork=staff_artwork)
        self.assertFalse(submission.can_save(self.user))
        self.assertTrue(submission.can_save(self.staff_user))
        self.assertFalse(submission.can_save(self.super_user))
コード例 #9
0
    def test_can_see_private(self):
        student = Artwork(
            author=self.user,
            title='Empty code',
            code='// code goes here')
        self.assertTrue(student.can_see(self.user))
        self.assertFalse(student.can_see(self.staff_user))
        self.assertFalse(student.can_see(self.super_user))

        staff = Artwork(
            author=self.staff_user,
            title='Empty code',
            code='// code goes here')
        self.assertFalse(staff.can_see(self.user))
        self.assertTrue(staff.can_see(self.staff_user))
        self.assertFalse(staff.can_see(self.super_user))

        superuser = Artwork(
            author=self.super_user,
            title='Empty code',
            code='// code goes here')
        self.assertFalse(superuser.can_see(self.user))
        self.assertFalse(superuser.can_see(self.staff_user))
        self.assertTrue(superuser.can_see(self.super_user))
コード例 #10
0
def nouv_art(request):
    sauvegarde = False
    form = NouvAlb(request.POST or None, request.FILES)
    if form.is_valid():
        artwork = Artwork()
        artwork.title = form.cleaned_data["title"]
        artwork.photo = form.cleaned_data["photo"]
        artwork.reference = form.cleaned_data["reference"]
        artwork.created_at = form.cleaned_data["created_at"]
        artwork.available = form.cleaned_data["available"]
        artwork.save()
        sauvegarde = True

    return render(request, 'art_form.html', {
        'form': form,
        'sauvegarde': sauvegarde
    })
コード例 #11
0
    def test_save_unique(self):

        exhibition = Exhibition(
            title='New Exhibition',
            description='description goes here',
            released_at=timezone.now(),
            author=self.user)
        exhibition.save()
        artwork = Artwork(title='New Artwork', code='// code goes here', author=self.user)
        artwork.save()
        submission1 = Submission(exhibition=exhibition, artwork=artwork, submitted_by=self.user)
        submission2 = Submission(exhibition=exhibition, artwork=artwork, submitted_by=self.user)

        # submissions must be unique
        self.assertEqual(submission1.save(), None)
        self.assertRaisesRegexp(
            IntegrityError,
            'columns exhibition_id, artwork_id are not unique',
            submission2.save)