Exemplo n.º 1
0
    def test_transcription_review(self):
        asset = create_asset()

        anon = get_anonymous_user()

        t1 = Transcription(asset=asset,
                           user=anon,
                           text="test",
                           submitted=now())
        t1.full_clean()
        t1.save()

        self.login_user()

        resp = self.client.post(reverse("review-transcription",
                                        args=(t1.pk, )),
                                data={"action": "foobar"})
        data = self.assertValidJSON(resp, expected_status=400)
        self.assertIn("error", data)

        self.assertEqual(
            1,
            Transcription.objects.filter(pk=t1.pk,
                                         accepted__isnull=True).count())

        resp = self.client.post(reverse("review-transcription",
                                        args=(t1.pk, )),
                                data={"action": "accept"})
        data = self.assertValidJSON(resp, expected_status=200)

        self.assertEqual(
            1,
            Transcription.objects.filter(pk=t1.pk,
                                         accepted__isnull=False).count())
Exemplo n.º 2
0
    def test_transcription_double_review(self):
        asset = create_asset()

        anon = get_anonymous_user()

        t1 = Transcription(asset=asset,
                           user=anon,
                           text="test",
                           submitted=now())
        t1.full_clean()
        t1.save()

        self.login_user()

        resp = self.client.post(reverse("review-transcription",
                                        args=(t1.pk, )),
                                data={"action": "accept"})
        data = self.assertValidJSON(resp, expected_status=200)

        resp = self.client.post(reverse("review-transcription",
                                        args=(t1.pk, )),
                                data={"action": "reject"})
        data = self.assertValidJSON(resp, expected_status=400)
        self.assertIn("error", data)
        self.assertEqual("This transcription has already been reviewed",
                         data["error"])
Exemplo n.º 3
0
    def test_asset_reservation_expiration(self):
        """
        Simulate an expired reservation which should not cause the request to fail
        """
        asset = create_asset()

        stale_reservation = AssetTranscriptionReservation(
            user=get_anonymous_user(), asset=asset)
        stale_reservation.full_clean()
        stale_reservation.save()
        # Backdate the object as if it happened 15 minutes ago:
        old_timestamp = datetime.now() - timedelta(minutes=15)
        AssetTranscriptionReservation.objects.update(created_on=old_timestamp,
                                                     updated_on=old_timestamp)

        self.login_user()

        with self.assertNumQueries(3):  # 1 auth query + 1 expiry + 1 acquire
            resp = self.client.post(
                reverse("reserve-asset-for-transcription", args=(asset.pk, )))
        self.assertEqual(204, resp.status_code)

        self.assertEqual(1, AssetTranscriptionReservation.objects.count())
        reservation = AssetTranscriptionReservation.objects.get()
        self.assertEqual(reservation.user_id, self.user.pk)
Exemplo n.º 4
0
    def test_asset_reservation_anonymously(self):
        """
        Test the basic Asset reservation process as an anonymous user
        """

        anon_user = get_anonymous_user()
        self._asset_reservation_test_payload(anon_user.pk)
Exemplo n.º 5
0
    def test_item_detail_view(self):
        """
        Test item detail display with assets
        """

        self.login_user()  # Implicitly create the test account
        anon = get_anonymous_user()

        item = create_item()
        # We'll create 10 assets and transcriptions for some of them so we can
        # confirm that the math is working correctly:
        for i in range(1, 11):
            asset = create_asset(item=item, sequence=i, slug=f"test-{i}")
            if i > 9:
                t = asset.transcription_set.create(asset=asset, user=anon)
                t.submitted = now()
                t.accepted = now()
                t.reviewed_by = self.user
            elif i > 7:
                t = asset.transcription_set.create(asset=asset, user=anon)
                t.submitted = now()
            elif i > 4:
                t = asset.transcription_set.create(asset=asset, user=anon)
            else:
                continue

            t.full_clean()
            t.save()

        response = self.client.get(
            reverse(
                "transcriptions:item-detail",
                args=(item.project.campaign.slug, item.project.slug,
                      item.item_id),
            ))

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(
            response, template_name="transcriptions/item_detail.html")
        self.assertContains(response, item.title)

        # We have 10 total, 6 of which have transcription records and of those
        # 6, 3 have been submitted and one of those was accepted:
        self.assertEqual(40, response.context["not_started_percent"])
        self.assertEqual(30, response.context["in_progress_percent"])
        self.assertEqual(20, response.context["submitted_percent"])
        self.assertEqual(10, response.context["completed_percent"])
Exemplo n.º 6
0
    def test_stale_transcription_submission(self):
        asset = create_asset()

        anon = get_anonymous_user()

        t1 = Transcription(asset=asset, user=anon, text="test")
        t1.full_clean()
        t1.save()

        t2 = Transcription(asset=asset, user=anon, text="test", supersedes=t1)
        t2.full_clean()
        t2.save()

        resp = self.client.post(reverse("submit-transcription",
                                        args=(t1.pk, )))
        data = self.assertValidJSON(resp, expected_status=400)
        self.assertIn("error", data)
Exemplo n.º 7
0
    def test_anonymous_transcription_submission(self):
        asset = create_asset()
        anon = get_anonymous_user()

        transcription = Transcription(asset=asset,
                                      user=anon,
                                      text="previous entry")
        transcription.full_clean()
        transcription.save()

        resp = self.client.post(
            reverse("submit-transcription", args=(transcription.pk, )))
        data = self.assertValidJSON(resp, expected_status=401)
        self.assertIn("key", data)
        self.assertIn("image", data)

        self.assertFalse(
            Transcription.objects.filter(submitted__isnull=False).exists())

        self.completeCaptcha(data["key"])
        self.client.post(
            reverse("submit-transcription", args=(transcription.pk, )))
        self.assertTrue(
            Transcription.objects.filter(submitted__isnull=False).exists())