Ejemplo n.º 1
0
 def test_resize_video_no_encode(self, get_encoded):
     raise SkipTest
     waffle.models.Switch.objects.update(name='video-encode', active=False)
     resize_video(files['good'], self.mock)
     assert not get_encoded.called
     assert isinstance(self.mock.sizes, dict)
     assert self.mock.save.called
Ejemplo n.º 2
0
 def test_resize_video(self, get_encoded, _preview_save):
     name = tempfile.mkstemp()[1]
     get_encoded.return_value = name
     resize_video(files['good'], self.preview.pk, lib=dummy.Video)
     mode = oct(os.stat(self.preview.image_path)[stat.ST_MODE])
     assert mode.endswith('644'), mode
     assert _preview_save.called
Ejemplo n.º 3
0
 def test_resize_error(self, _resize_video):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.side_effect = ValueError
     with self.assertRaises(ValueError):
         resize_video(files['good'], self.mock, user=user)
     assert self.mock.delete.called
     assert UserLog.objects.filter(
         user=user, activity_log__action=amo.LOG.VIDEO_ERROR.id).exists()
Ejemplo n.º 4
0
 def test_resize_error(self, _resize_video):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.side_effect = ValueError
     with self.assertRaises(ValueError):
         resize_video(files['good'], self.mock, user=user)
     assert self.mock.delete.called
     assert UserLog.objects.filter(
         user=user, activity_log__action=amo.LOG.VIDEO_ERROR.id).exists()
Ejemplo n.º 5
0
 def test_resize_failed(self, _resize_video, _preview_delete):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.return_value = None
     resize_video(self.tmp_good,
                  self.preview.pk,
                  user_pk=user.pk,
                  lib=dummy.Video)
     assert _preview_delete.called
Ejemplo n.º 6
0
 def test_resize_error(self, _resize_video, _preview_delete):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.side_effect = ValueError
     with self.assertRaises(ValueError):
         resize_video(files['good'], self.preview.pk, user_pk=user.pk,
                      lib=dummy.Video)
     assert _preview_delete.called
     assert UserLog.objects.filter(
         user=user, activity_log__action=mkt.LOG.VIDEO_ERROR.id).exists()
Ejemplo n.º 7
0
 def test_resize_error(self, _resize_video, _preview_delete):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.side_effect = ValueError
     with self.assertRaises(ValueError):
         resize_video(self.tmp_good, self.preview.pk, user_pk=user.pk,
                      lib=dummy.Video)
     assert _preview_delete.called
     assert UserLog.objects.filter(
         user=user, activity_log__action=mkt.LOG.VIDEO_ERROR.id).exists()
Ejemplo n.º 8
0
 def test_resize_failed(self, _resize_video):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.return_value = None
     resize_video(files['good'], self.mock, user=user)
     assert self.mock.delete.called
Ejemplo n.º 9
0
def generate_app_from_spec(name, categories, type, status, num_previews=1,
                           num_ratings=1, locale_names=('en-US', 'es-ES'),
                           preview_files=(),
                           video_files=(),
                           developer_name='Fake App Developer',
                           developer_email='*****@*****.**',
                           privacy_policy='Fake privacy policy',
                           premium_type='free', description=None,
                           default_locale='en-US', rereview=False,
                           special_regions={}, inapp_id=None,
                           inapp_secret=None, popularity=0, **spec):
    status = STATUS_CHOICES_API_LOOKUP[status]
    names = generate_localized_names(name, locale_names)
    if type == 'hosted':
        app = generate_hosted_app(
            names[default_locale], categories, developer_name, status=status,
            default_locale=default_locale, **spec)
    else:
        app = generate_packaged_app(
            names, type, categories, developer_name,
            default_locale=default_locale, status=status, **spec)
    generate_icon(app)
    if not preview_files:
        generate_previews(app, num_previews)
    if video_files:
        for i, f in enumerate(video_files):
            t = tempfile.mktemp()
            copy_stored_file(f, t, src_storage=local_storage,
                             dst_storage=private_storage)
            p = Preview.objects.create(addon=app, filetype="video/webm",
                                       caption="video " + str(i),
                                       position=i)
            resize_video(t, p.pk)
    if preview_files:
        for i, f in enumerate(preview_files):
            p = Preview.objects.create(addon=app, filetype="image/png",
                                       caption="screenshot " + str(i),
                                       position=i + len(video_files))
            t = tempfile.mktemp()
            copy_stored_file(f, t, src_storage=local_storage,
                             dst_storage=private_storage)
            resize_preview(t, p.pk)
    generate_ratings(app, num_ratings)
    app.name = names
    if not description:
        description = GENERIC_DESCRIPTION
    app.description = description
    app.privacy_policy = privacy_policy
    app.support_email = developer_email
    premium_type = mkt.ADDON_PREMIUM_API_LOOKUP[premium_type]
    app.premium_type = premium_type
    app.default_locale = default_locale
    if popularity:
        app.popularity.create(value=popularity)
    if premium_type != mkt.ADDON_FREE and status != mkt.STATUS_NULL:
        acct = get_or_create_payment_account(developer_email, developer_name)
        product_uri = Reference().product_create(acct, app)
        AddonPaymentAccount.objects.create(addon=app, payment_account=acct,
                                           account_uri=acct.uri,
                                           product_uri=product_uri)
        if premium_type in (mkt.ADDON_PREMIUM, mkt.ADDON_PREMIUM_INAPP):
            price = get_or_create_price(spec.get('price', '0.99'))
            AddonPremium.objects.create(addon=app, price=price)
        if premium_type in (mkt.ADDON_FREE_INAPP, mkt.ADDON_PREMIUM_INAPP):
            UserInappKey.create(acct.user, secret=inapp_secret,
                                public_id=inapp_id,
                                access_type=ACCESS_PURCHASE)

    for optField in ('support_url', 'homepage', 'is_offline'):
        if optField in spec:
            setattr(app, optField, spec[optField])
    # Status has to be updated at the end because STATUS_DELETED apps can't
    # be saved.
    app.status = status
    app.save()
    for (region, region_status) in special_regions.iteritems():
        app.geodata.update(**{'region_%s_nominated' % (region,):
                              datetime.datetime.now(),
                              'region_%s_status' % (region,):
                              STATUS_CHOICES_API_LOOKUP[region_status]})
    addon_review_aggregates(app.pk)
    if rereview:
        RereviewQueue.objects.get_or_create(addon=app)
    try:
        u = UserProfile.objects.get(email=developer_email)
    except UserProfile.DoesNotExist:
        u = create_user(developer_email)
        u.display_name = developer_name
        u.save()
    AddonUser.objects.create(user=u, addon=app)
    return app
Ejemplo n.º 10
0
 def test_resize_failed(self, _resize_video):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.return_value = None
     resize_video(files['good'], self.mock, user=user)
     assert self.mock.delete.called
Ejemplo n.º 11
0
 def test_resize_video_no_encode(self, get_encoded):
     waffle.models.Switch.objects.update(name='video-encode', active=False)
     resize_video(files['good'], self.mock, lib=dummy.Video)
     assert not get_encoded.called
     assert self.mock.save.called
Ejemplo n.º 12
0
 def test_resize_image(self, _preview_save):
     resize_video(self.tmp_bad, self.preview.pk, lib=dummy.Video)
     eq_(self.preview.sizes, {})
     assert not _preview_save.called
Ejemplo n.º 13
0
 def test_resize_image(self):
     resize_video(files['bad'], self.mock, lib=dummy.Video)
     assert not isinstance(self.mock.sizes, dict)
     assert not self.mock.save.called
Ejemplo n.º 14
0
 def test_resize_video_no_encode(self, get_encoded, _preview_save):
     waffle.models.Switch.objects.update(name='video-encode', active=False)
     resize_video(self.tmp_good, self.preview.pk, lib=dummy.Video)
     assert not get_encoded.called
     assert _preview_save.called
Ejemplo n.º 15
0
 def test_resize_video(self, get_encoded, _preview_save):
     name = tempfile.mkstemp()[1]
     get_encoded.return_value = name
     resize_video(self.tmp_good, self.preview.pk, lib=dummy.Video)
     assert _preview_save.called
Ejemplo n.º 16
0
 def test_resize_video(self, get_encoded, _preview_save):
     name = tempfile.mkstemp()[1]
     get_encoded.return_value = name
     resize_video(self.tmp_good, self.preview.pk, lib=dummy.Video)
     assert _preview_save.called
Ejemplo n.º 17
0
 def test_resize_image(self):
     resize_video(files['bad'], self.mock, lib=dummy.Video)
     assert not isinstance(self.mock.sizes, dict)
     assert not self.mock.save.called
Ejemplo n.º 18
0
def generate_app_from_spec(name, categories, type, status, num_previews=1,
                           num_ratings=1, locale_names=('en-US', 'es-ES'),
                           preview_files=(),
                           video_files=(),
                           developer_name='Fake App Developer',
                           developer_email='*****@*****.**',
                           privacy_policy='Fake privacy policy',
                           premium_type='free', description=None,
                           default_locale='en-US', rereview=False,
                           special_regions={}, inapp_id=None,
                           inapp_secret=None, popularity=0, tarako=False,
                           **spec):
    status = STATUS_CHOICES_API_LOOKUP[status]
    names = generate_localized_names(name, locale_names)
    if type == 'hosted':
        app = generate_hosted_app(
            names[default_locale], categories, developer_name, status=status,
            default_locale=default_locale, **spec)
    else:
        app = generate_packaged_app(
            names, type, categories, developer_name,
            default_locale=default_locale, status=status, **spec)
    generate_icon(app)
    if not preview_files:
        generate_previews(app, num_previews)
    if video_files:
        for i, f in enumerate(video_files):
            t = tempfile.mktemp()
            copy_stored_file(f, t, src_storage=local_storage,
                             dst_storage=private_storage)
            p = Preview.objects.create(addon=app, filetype="video/webm",
                                       caption="video " + str(i),
                                       position=i)
            resize_video(t, p.pk)
    if preview_files:
        for i, f in enumerate(preview_files):
            p = Preview.objects.create(addon=app, filetype="image/png",
                                       caption="screenshot " + str(i),
                                       position=i + len(video_files))
            t = tempfile.mktemp()
            copy_stored_file(f, t, src_storage=local_storage,
                             dst_storage=private_storage)
            resize_preview(t, p.pk)
    generate_ratings(app, num_ratings)
    app.name = names
    if not description:
        description = GENERIC_DESCRIPTION
    app.description = description
    app.privacy_policy = privacy_policy
    app.support_email = developer_email
    premium_type = mkt.ADDON_PREMIUM_API_LOOKUP[premium_type]
    app.premium_type = premium_type
    app.default_locale = default_locale
    if popularity:
        app.popularity.create(value=popularity)
    if premium_type != mkt.ADDON_FREE and status != mkt.STATUS_NULL:
        acct = get_or_create_payment_account(developer_email, developer_name)
        product_uri = Reference().product_create(acct, app)
        AddonPaymentAccount.objects.create(addon=app, payment_account=acct,
                                           account_uri=acct.uri,
                                           product_uri=product_uri)
        if premium_type in (mkt.ADDON_PREMIUM, mkt.ADDON_PREMIUM_INAPP):
            price = get_or_create_price(spec.get('price', '0.99'))
            AddonPremium.objects.create(addon=app, price=price)
        if premium_type in (mkt.ADDON_FREE_INAPP, mkt.ADDON_PREMIUM_INAPP):
            UserInappKey.create(acct.user, secret=inapp_secret,
                                public_id=inapp_id,
                                access_type=ACCESS_PURCHASE)

    for optField in ('support_url', 'homepage', 'is_offline'):
        if optField in spec:
            setattr(app, optField, spec[optField])
    # Status has to be updated at the end because STATUS_DELETED apps can't
    # be saved.
    app.status = status
    app.save()
    for (region, region_status) in special_regions.iteritems():
        app.geodata.update(**{'region_%s_nominated' % (region,):
                              datetime.datetime.now(),
                              'region_%s_status' % (region,):
                              STATUS_CHOICES_API_LOOKUP[region_status]})
    if tarako:
        AdditionalReview.objects.create(app=app, queue='tarako')
    addon_review_aggregates(app.pk)
    if rereview:
        RereviewQueue.objects.get_or_create(addon=app)
    try:
        u = UserProfile.objects.get(email=developer_email)
    except UserProfile.DoesNotExist:
        u = create_user(developer_email)
        u.display_name = developer_name
        u.save()
    AddonUser.objects.create(user=u, addon=app)
    return app
Ejemplo n.º 19
0
 def test_resize_image(self, _preview_save):
     resize_video(files['bad'], self.preview.pk, lib=dummy.Video)
     eq_(self.preview.sizes, {})
     assert not _preview_save.called
Ejemplo n.º 20
0
 def test_resize_video_no_encode(self, get_encoded, _preview_save):
     waffle.models.Switch.objects.update(name='video-encode', active=False)
     resize_video(files['good'], self.preview.pk, lib=dummy.Video)
     assert not get_encoded.called
     assert _preview_save.called
Ejemplo n.º 21
0
 def test_resize_image(self):
     raise SkipTest
     resize_video(files['bad'], self.mock)
     assert not isinstance(self.mock.sizes, dict)
     assert not self.mock.save.called
Ejemplo n.º 22
0
 def test_resize_failed(self, _resize_video, _preview_delete):
     user = UserProfile.objects.create(email='*****@*****.**')
     _resize_video.return_value = None
     resize_video(self.tmp_good, self.preview.pk, user_pk=user.pk,
                  lib=dummy.Video)
     assert _preview_delete.called