def test_cleanup_extracted_file():
    with freeze_time('2017-01-08 10:01:00'):
        viewer = FileViewer(make_file(1, get_file('webextension.xpi')))

        assert '0108' in viewer.dest
        assert not os.path.exists(viewer.dest)

        viewer.extract()

        assert os.path.exists(viewer.dest)

        # Cleaning up only cleans up yesterdays files so it doesn't touch
        # us today...
        cleanup_extracted_file()

        assert os.path.exists(viewer.dest)

    # Even hours later we don't cleanup yet...
    with freeze_time('2017-01-08 23:59:00'):
        assert os.path.exists(viewer.dest)

        cleanup_extracted_file()

        assert os.path.exists(viewer.dest)

    # But yesterday... we'll cleanup properly
    with freeze_time('2017-01-07 10:01:00'):
        assert os.path.exists(viewer.dest)

        cleanup_extracted_file()

        assert not os.path.exists(viewer.dest)
Beispiel #2
0
def test_parse_search_empty_shortname():
    fname = get_file('search_empty_shortname.xml')

    with pytest.raises(forms.ValidationError) as excinfo:
        utils.parse_search(fname)

    assert (
        excinfo.value[0] ==
        'Could not parse uploaded file, missing or empty <ShortName> element')
def test_parse_search_empty_shortname():
    fname = get_file('search_empty_shortname.xml')

    with pytest.raises(forms.ValidationError) as excinfo:
        utils.parse_search(fname)

    assert (
        excinfo.value[0] ==
        'Could not parse uploaded file, missing or empty <ShortName> element')
Beispiel #4
0
    def create_installable_addon(self):
        activate('en-US')

        # using whatever add-on you already have should work imho, otherwise
        # fall back to a new one for test purposes
        addon = self.create_featured_addon_with_version_for_install()

        # the user the add-on gets created with
        user = UserProfile.objects.get(username='******')

        user, _ = UserProfile.objects.get_or_create(pk=settings.TASK_USER_ID,
                                                    defaults={
                                                        'email':
                                                        '*****@*****.**',
                                                        'username': '******'
                                                    })

        # generate a proper uploaded file that simulates what django requires
        # as request.POST
        file_to_upload = 'webextension_signed_already.xpi'
        file_path = get_file(file_to_upload)

        # make sure we are not using the file in the source-tree but a
        # temporary one to avoid the files get moved somewhere else and
        # deleted from source tree
        with copy_file_to_temp(file_path) as temporary_path:
            data = open(temporary_path).read()
            filedata = SimpleUploadedFile(
                file_to_upload,
                data,
                content_type=mimetypes.guess_type(file_to_upload)[0])

            # now, lets upload the file into the system
            from olympia.devhub.views import handle_upload

            request = RequestFactory().get('/')
            request.user = user

            upload = handle_upload(
                filedata=filedata,
                request=request,
                channel=amo.RELEASE_CHANNEL_LISTED,
                addon=addon,
            )

            # And let's create a new version for that upload.
            create_version_for_upload(upload.addon, upload,
                                      amo.RELEASE_CHANNEL_LISTED)

            # Change status to public
            addon.update(status=amo.STATUS_PUBLIC)
    def create_installable_addon(self):
        activate('en-US')

        # using whatever add-on you already have should work imho, otherwise
        # fall back to a new one for test purposes
        addon = self.create_featured_addon_with_version_for_install()

        # the user the add-on gets created with
        user = UserProfile.objects.get(username='******')

        user, _ = UserProfile.objects.get_or_create(
            pk=settings.TASK_USER_ID,
            defaults={'email': '*****@*****.**', 'username': '******'})

        # generate a proper uploaded file that simulates what django requires
        # as request.POST
        file_to_upload = 'webextension_signed_already.xpi'
        file_path = get_file(file_to_upload)

        # make sure we are not using the file in the source-tree but a
        # temporary one to avoid the files get moved somewhere else and
        # deleted from source tree
        with copy_file_to_temp(file_path) as temporary_path:
            data = open(temporary_path).read()
            filedata = SimpleUploadedFile(
                file_to_upload,
                data,
                content_type=mimetypes.guess_type(file_to_upload)[0])

            # now, lets upload the file into the system
            from olympia.devhub.views import handle_upload

            request = RequestFactory().get('/')
            request.user = user

            upload = handle_upload(
                filedata=filedata,
                request=request,
                channel=amo.RELEASE_CHANNEL_LISTED,
                addon=addon,
            )

            # And let's create a new version for that upload.
            create_version_for_upload(
                upload.addon, upload, amo.RELEASE_CHANNEL_LISTED)

            # Change status to public
            addon.update(status=amo.STATUS_PUBLIC)