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)
Пример #2
0
    def test_can_see_queryset(self):
        now = timezone.now()

        # Released yesterday
        yesterday = Exhibition(
            author=self.user,
            title='Yesterday Exhibition',
            description='description goes here', 
            released_at=now + timedelta(hours=-24))
        yesterday.save()

        # Released today
        today = Exhibition(
            author=self.user,
            title='Today Exhibition',
            description='description goes here',
            released_at=now)
        today.save()

        # Released tomorrow
        tomorrow = Exhibition(
            author=self.user,
            title='Tomorrow Exhibition',
            description='description goes here',
            released_at=now + timedelta(hours=24))
        tomorrow.save()

        public_qs = Exhibition.can_see_queryset(Exhibition.objects)
        self.assertEqual(len(public_qs.all()), 2)
        self.assertEqual(public_qs.all()[0].id, yesterday.id)
        self.assertEqual(public_qs.all()[1].id, today.id)

        student_qs = Exhibition.can_see_queryset(Exhibition.objects, self.user)
        self.assertEqual(len(student_qs.all()), 2)
        self.assertEqual(student_qs.all()[0].id, yesterday.id)
        self.assertEqual(student_qs.all()[1].id, today.id)

        staff_qs = Exhibition.can_see_queryset(Exhibition.objects, self.staff_user)
        self.assertEqual(len(staff_qs.all()), 3)
        self.assertEqual(staff_qs.all()[0].id, yesterday.id)
        self.assertEqual(staff_qs.all()[1].id, today.id)
        self.assertEqual(staff_qs.all()[2].id, tomorrow.id)

        super_qs = Exhibition.can_see_queryset(Exhibition.objects, self.super_user)
        self.assertEqual(len(super_qs.all()), 3)
        self.assertEqual(super_qs.all()[0].id, yesterday.id)
        self.assertEqual(super_qs.all()[1].id, today.id)
        self.assertEqual(super_qs.all()[2].id, tomorrow.id)
Пример #3
0
    def test_can_see_queryset(self):
        now = timezone.now()

        # Released yesterday
        yesterday = Exhibition(author=self.user,
                               title='Yesterday Exhibition',
                               description='description goes here',
                               released_at=now + timedelta(hours=-24))
        yesterday.save()

        # Released today
        today = Exhibition(author=self.user,
                           title='Today Exhibition',
                           description='description goes here',
                           released_at=now)
        today.save()

        # Released tomorrow
        tomorrow = Exhibition(author=self.user,
                              title='Tomorrow Exhibition',
                              description='description goes here',
                              released_at=now + timedelta(hours=24))
        tomorrow.save()

        public_qs = Exhibition.can_see_queryset(Exhibition.objects)
        self.assertEqual(len(public_qs.all()), 2)
        self.assertEqual(public_qs.all()[0].id, yesterday.id)
        self.assertEqual(public_qs.all()[1].id, today.id)

        student_qs = Exhibition.can_see_queryset(Exhibition.objects, self.user)
        self.assertEqual(len(student_qs.all()), 2)
        self.assertEqual(student_qs.all()[0].id, yesterday.id)
        self.assertEqual(student_qs.all()[1].id, today.id)

        staff_qs = Exhibition.can_see_queryset(Exhibition.objects,
                                               self.staff_user)
        self.assertEqual(len(staff_qs.all()), 3)
        self.assertEqual(staff_qs.all()[0].id, yesterday.id)
        self.assertEqual(staff_qs.all()[1].id, today.id)
        self.assertEqual(staff_qs.all()[2].id, tomorrow.id)

        super_qs = Exhibition.can_see_queryset(Exhibition.objects,
                                               self.super_user)
        self.assertEqual(len(super_qs.all()), 3)
        self.assertEqual(super_qs.all()[0].id, yesterday.id)
        self.assertEqual(super_qs.all()[1].id, today.id)
        self.assertEqual(super_qs.all()[2].id, tomorrow.id)