Пример #1
0
def create_site_permission_version(*, user_pk, remote_addr, install_origins,
                                   site_permissions, **kwargs):
    # Can raise if the user does not exist, but that's ok, we don't want to go
    # any further if that's the case.
    user = UserProfile.objects.filter(deleted=False).get(pk=user_pk)
    generator = SitePermissionVersionCreator(
        user=user,
        remote_addr=remote_addr,
        install_origins=install_origins,
        site_permissions=site_permissions,
    )
    generator.create_version()
Пример #2
0
 def test_create_version_existing_addon_but_user_is_not_an_author(self):
     creator = SitePermissionVersionCreator(
         user=user_factory(),
         remote_addr='4.8.15.16',
         install_origins=['https://example.com', 'https://foo.com'],
         site_permissions=['midi-sysex', 'webblah'],
     )
     addon = addon_factory(
         version_kw={'version': '1.0'},
         type=amo.ADDON_SITE_PERMISSION,
         users=[user_factory()],
     )
     self.make_addon_unlisted(addon)
     with self.assertRaises(ImproperlyConfigured):
         creator.create_version(addon=addon)
Пример #3
0
 def test_create_version_no_addon(self):
     creator = SitePermissionVersionCreator(
         user=user_factory(),
         remote_addr='4.8.15.16',
         install_origins=['https://example.com', 'https://foo.com'],
         site_permissions=['midi-sysex', 'webblah'],
     )
     version = creator.create_version()
     assert version
     addon = version.addon
     file_ = version.file
     # Reload to ensure everything was saved in database correctly.
     version.reload()
     addon.reload()
     file_.reload()
     assert version.pk
     assert version.channel == amo.RELEASE_CHANNEL_UNLISTED
     assert version.version == '1.0'
     assert sorted(version.installorigin_set.all().values_list(
         'origin', flat=True)) == [
             'https://example.com',
             'https://foo.com',
         ]
     assert addon.pk
     assert addon.status == amo.STATUS_NULL
     assert addon.type == amo.ADDON_SITE_PERMISSION
     assert list(addon.authors.all()) == [creator.user]
     assert file_.status == amo.STATUS_AWAITING_REVIEW
     assert file_._site_permissions
     assert file_._site_permissions.permissions == ['midi-sysex', 'webblah']
     activity = ActivityLog.objects.for_addons(addon).latest('pk')
     assert activity.user == creator.user
     assert activity.iplog_set.all()[0].ip_address == '4.8.15.16'
Пример #4
0
    def test_create_version_existing_addon_wrong_origins(self):
        creator = SitePermissionVersionCreator(
            user=user_factory(),
            remote_addr='4.8.15.16',
            install_origins=['https://example.com', 'https://foo.com'],
            site_permissions=['midi-sysex', 'webblah'],
        )
        addon = addon_factory(
            version_kw={'version': '1.0'},
            type=amo.ADDON_SITE_PERMISSION,
            users=[creator.user],
        )
        initial_version = addon.versions.get()
        self.make_addon_unlisted(addon)
        with self.assertRaises(ImproperlyConfigured):
            creator.create_version(addon=addon)

        # Both need to match, not just one.
        initial_version.installorigin_set.create(origin='https://example.com')
        with self.assertRaises(ImproperlyConfigured):
            creator.create_version(addon=addon)