コード例 #1
0
ファイル: test_models.py プロジェクト: sheenaze/qa4sm
    def test_deleteable(self):
        run = ValidationRun()
        assert run.is_unpublished

        run.doi = '10.1000/182'
        assert not run.is_unpublished

        run.doi = ''
        assert run.is_unpublished
コード例 #2
0
ファイル: test_views.py プロジェクト: bakcsa83/qa4sm
    def test_change_validation_name(self):
        # create new no-named result
        run = ValidationRun()
        run.user = self.testuser
        run.start_time = datetime.now(tzlocal())
        run.interval_from = datetime(1978, 1, 1, tzinfo=UTC)
        run.interval_to = datetime(2018, 1, 1, tzinfo=UTC)
        run.save()
        result_id = str(run.id)

        assert result_id, "Error saving the test validation run."

        #try to change name of other user's validation
        url = reverse('result', kwargs={'result_uuid': result_id})

        self.client.login(**self.credentials2)
        response = self.client.patch(
            url,
            'save_name=false',
            content_type='application/x-www-form-urlencoded;')
        self.assertEqual(response.status_code, 403)

        # log in as owner of result and check invalid saving mode
        self.client.login(**self.credentials)
        response = self.client.patch(
            url,
            'save_name=false',
            content_type='application/x-www-form-urlencoded;')
        self.assertEqual(response.status_code, 400)

        # log in as owner of result and check valid saving mode
        self.client.login(**self.credentials)
        response = self.client.patch(
            url,
            'save_name=true&new_name="new_name"',
            content_type='application/x-www-form-urlencoded;')
        self.assertEqual(response.status_code, 200)

        run.doi = '10.1000/182'
        run.save()

        response = self.client.patch(
            url,
            'save_name=true&new_name="new_name"',
            content_type='application/x-www-form-urlencoded;')
        self.assertEqual(response.status_code, 405)

        run.doi = ''
        run.save()
        run.name_tag = 'new_name'
        run.save()
        assert ValidationRun.objects.filter(name_tag='new_name').exists()
コード例 #3
0
ファイル: test_views.py プロジェクト: bakcsa83/qa4sm
    def test_delete_result(self):
        # create result to delete:
        run = ValidationRun()
        run.user = self.testuser
        run.start_time = datetime.now(tzlocal())
        run.interval_from = datetime(1978, 1, 1, tzinfo=UTC)
        run.interval_to = datetime(2018, 1, 1, tzinfo=UTC)
        run.save()
        result_id = str(run.id)

        assert result_id, "Error saving the test validation run."

        url = reverse('result', kwargs={'result_uuid': result_id})

        # try deleting other user's result - should be blocked
        self.client.login(**self.credentials2)
        response = self.client.delete(url)
        self.assertEqual(response.status_code, 403)

        # log in as owner of result
        self.client.login(**self.credentials)

        # try deleting a result that already has a DOI, should be blocked
        run.doi = '10.1000/182'
        run.save()
        response = self.client.delete(url)
        self.assertEqual(response.status_code, 405)

        # remove DOI again
        run.doi = ''
        run.save()

        # try to delete own result, should succeed
        response = self.client.delete(url)
        self.assertEqual(response.status_code, 200)

        assert not ValidationRun.objects.filter(
            pk=result_id).exists(), "Validation run didn't get deleted."
コード例 #4
0
    def test_autocleanupvalidations(self):

        ended_vals = ValidationRun.objects.filter(
            end_time__isnull=False).count()

        ## unexpired validation
        run1 = ValidationRun()
        run1.start_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 4)
        run1.end_time = timezone.now()
        run1.user = self.testuser
        run1.save()
        runid1 = run1.id

        ## 20% of warning period has passed
        run2 = ValidationRun()
        run2.start_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 4)
        run2.end_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS -
            settings.VALIDATION_EXPIRY_WARNING_DAYS * 0.8)
        run2.user = self.testuser
        run2.save()
        runid2 = run2.id

        ## 80% of warning period has passed
        run3 = ValidationRun()
        run3.start_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 4)
        run3.end_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS -
            settings.VALIDATION_EXPIRY_WARNING_DAYS * 0.2)
        run3.user = self.testuser
        run3.save()
        runid3 = run3.id

        ## just expired validation
        run4 = ValidationRun()
        run4.start_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 4)
        run4.end_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS)
        run4.user = self.testuser
        run4.save()
        runid4 = run4.id

        ## long expired validation
        run5 = ValidationRun()
        run5.start_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 4)
        run5.end_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 2)
        run5.user = self.testuser
        run5.save()
        runid5 = run5.id

        # test what happens if there is no user assigned to a validation
        no_user_run = ValidationRun()
        no_user_run.start_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 4)
        no_user_run.end_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS)
        no_user_run.user = None
        no_user_run.save()
        no_user_run_id = no_user_run.id

        # test what happens if there is no user assigned to a validation, but validation has been published
        no_user_run_published = ValidationRun()
        no_user_run_published.start_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS * 4)
        no_user_run_published.end_time = timezone.now() - timedelta(
            days=settings.VALIDATION_EXPIRY_DAYS)
        no_user_run_published.user = None
        no_user_run_published.doi = '10101/101.010'
        no_user_run_published.save()
        no_user_run_published_id = no_user_run_published.id

        ended_vals2 = ValidationRun.objects.filter(
            end_time__isnull=False).count()
        assert ended_vals + 7 == ended_vals2
        assert runid1
        assert runid2
        assert runid3
        assert runid4
        assert runid5
        assert no_user_run_id
        assert no_user_run_published_id

        # run the command
        args = []
        opts = {}
        call_command('autocleanupvalidations', *args, **opts)

        ## reload from db because the validations have been changed.
        run1 = ValidationRun.objects.get(pk=runid1)
        run2 = ValidationRun.objects.get(pk=runid2)
        run3 = ValidationRun.objects.get(pk=runid3)
        run4 = ValidationRun.objects.get(pk=runid4)
        run5 = ValidationRun.objects.get(pk=runid5)
        non_user_val = ValidationRun.objects.filter(pk=no_user_run_id)
        no_user_run_published = ValidationRun.objects.get(
            pk=no_user_run_published_id)

        ## with the last command call, the user should have been notified about most of our test validations
        ## but the validations should not have been deleted yet
        assert not run1.expiry_notified
        assert run2.expiry_notified
        assert run3.expiry_notified
        assert run4.expiry_notified
        assert run5.expiry_notified
        assert len(
            non_user_val
        ) == 0  # there should be no validation anymore, because it was already removed
        assert not no_user_run_published.expiry_notified  # no notification sent

        ## the validations may have been extended in the previous step, undo that to get them really deleted in the next call
        run1.last_extended = None
        run1.save()
        run2.last_extended = None
        run2.save()
        run3.last_extended = None
        run3.save()
        run4.last_extended = None
        run4.save()
        run5.last_extended = None
        run5.save()

        call_command('autocleanupvalidations', *args, **opts)

        ## the two expired validations should be have been deleted now
        ended_vals3 = ValidationRun.objects.filter(
            end_time__isnull=False).count()
        assert ended_vals + 4 == ended_vals3