예제 #1
0
    def test_move_disabled_addon_ioerror(self, mv_mock, storage_exists):
        # raise an IOError for the first file, we need to make sure
        # that the second one is still being properly processed
        mv_mock.side_effect = [IOError, None]
        storage_exists.return_value = True

        # Use Addon.objects.update so the signal handler isn't called.
        Addon.objects.filter(id=self.addon.id).update(
            status=amo.STATUS_APPROVED, disabled_by_user=True)
        File.objects.update(status=amo.STATUS_APPROVED)

        cron.hide_disabled_files()

        # Check that we called `move_stored_file` for f2 properly
        f2 = self.f2
        mv_mock.assert_called_with(f2.file_path, f2.guarded_file_path)

        # Check that we called `move_stored_file` for f1 properly
        f1 = self.f1
        mv_mock.call_args = mv_mock.call_args_list[0]
        mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path)

        # Make sure we called `mv` twice despite an `IOError` for the first
        # file
        assert mv_mock.call_count == 2
예제 #2
0
    def test_move_disabled_addon_ioerror(self, mv_mock, storage_exists):
        # raise an IOError for the first file, we need to make sure
        # that the second one is still being properly processed
        mv_mock.side_effect = [IOError, None]
        storage_exists.return_value = True

        # Use Addon.objects.update so the signal handler isn't called.
        Addon.objects.filter(id=self.addon.id).update(
            status=amo.STATUS_PUBLIC, disabled_by_user=True)
        File.objects.update(status=amo.STATUS_PUBLIC)

        cron.hide_disabled_files()

        # Check that we called `move_stored_file` for f2 properly
        f2 = self.f2
        mv_mock.assert_called_with(f2.file_path, f2.guarded_file_path)

        # Check that we called `move_stored_file` for f1 properly
        f1 = self.f1
        mv_mock.call_args = mv_mock.call_args_list[0]
        mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path)

        # Make sure we called `mv` twice despite an `IOError` for the first
        # file
        assert mv_mock.call_count == 2
예제 #3
0
 def test_leave_nondisabled_files(self, os_mock):
     # All these addon/file status pairs should stay.
     stati = ((amo.STATUS_PUBLIC, amo.STATUS_PUBLIC),
              (amo.STATUS_PUBLIC, amo.STATUS_AWAITING_REVIEW))
     for addon_status, file_status in stati:
         self.addon.update(status=addon_status)
         File.objects.update(status=file_status)
         cron.hide_disabled_files()
         assert not os_mock.path.exists.called, (addon_status, file_status)
예제 #4
0
 def test_leave_nondisabled_files(self, os_mock):
     # All these addon/file status pairs should stay.
     stati = ((amo.STATUS_PUBLIC, amo.STATUS_PUBLIC),
              (amo.STATUS_PUBLIC, amo.STATUS_AWAITING_REVIEW))
     for addon_status, file_status in stati:
         self.addon.update(status=addon_status)
         File.objects.update(status=file_status)
         cron.hide_disabled_files()
         assert not os_mock.path.exists.called, (addon_status, file_status)
예제 #5
0
 def test_move_disabled_file(self, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(status=amo.STATUS_APPROVED)
     File.objects.filter(id=self.f1.id).update(status=amo.STATUS_DISABLED)
     File.objects.filter(id=self.f2.id).update(status=amo.STATUS_AWAITING_REVIEW)
     cron.hide_disabled_files()
     # Only f1 should have been moved.
     f1 = self.f1
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path, self.msg)
     assert mv_mock.call_count == 1
예제 #6
0
 def test_move_disabled_file(self, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(status=amo.STATUS_PUBLIC)
     File.objects.filter(id=self.f1.id).update(status=amo.STATUS_DISABLED)
     File.objects.filter(id=self.f2.id).update(
         status=amo.STATUS_AWAITING_REVIEW)
     cron.hide_disabled_files()
     # Only f1 should have been moved.
     f1 = self.f1
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     assert mv_mock.call_count == 1
예제 #7
0
 def test_move_admin_disabled_addon(self, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(status=amo.STATUS_DISABLED)
     File.objects.update(status=amo.STATUS_APPROVED)
     cron.hide_disabled_files()
     # Check that f2 was moved.
     f2 = self.f2
     mv_mock.assert_called_with(f2.file_path, f2.guarded_file_path, self.msg)
     # Check that f1 was moved as well.
     f1 = self.f1
     mv_mock.call_args = mv_mock.call_args_list[0]
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path, self.msg)
     # There's only 2 files, both should have been moved.
     assert mv_mock.call_count == 2
예제 #8
0
 def test_move_disabled_file(self, m_storage, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(status=amo.STATUS_LITE)
     File.objects.filter(id=self.f1.id).update(status=amo.STATUS_DISABLED)
     File.objects.filter(id=self.f2.id).update(status=amo.STATUS_UNREVIEWED)
     cron.hide_disabled_files()
     # Only f1 should have been moved.
     f1 = self.f1
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     eq_(mv_mock.call_count, 1)
     # It should have been removed from mirror stagins.
     m_storage.delete.assert_called_with(f1.mirror_file_path)
     eq_(m_storage.delete.call_count, 1)
예제 #9
0
 def test_move_disabled_file(self, m_storage, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(status=amo.STATUS_LITE)
     File.objects.filter(id=self.f1.id).update(status=amo.STATUS_DISABLED)
     File.objects.filter(id=self.f2.id).update(status=amo.STATUS_UNREVIEWED)
     cron.hide_disabled_files()
     # Only f1 should have been moved.
     f1 = self.f1
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     assert mv_mock.call_count == 1
     # It should have been removed from mirror stagins.
     m_storage.delete.assert_called_with(f1.mirror_file_path)
     assert m_storage.delete.call_count == 1
예제 #10
0
 def test_leave_nondisabled_files(self, os_mock):
     # All these addon/file status pairs should stay.
     stati = [(amo.STATUS_PUBLIC, amo.STATUS_PUBLIC),
              (amo.STATUS_PUBLIC, amo.STATUS_UNREVIEWED),
              (amo.STATUS_PUBLIC, amo.STATUS_BETA),
              (amo.STATUS_LITE, amo.STATUS_UNREVIEWED),
              (amo.STATUS_LITE, amo.STATUS_LITE),
              (amo.STATUS_LITE_AND_NOMINATED, amo.STATUS_UNREVIEWED),
              (amo.STATUS_LITE_AND_NOMINATED, amo.STATUS_LITE)]
     for addon_status, file_status in stati:
         self.addon.update(status=addon_status)
         File.objects.update(status=file_status)
         cron.hide_disabled_files()
         assert not os_mock.path.exists.called, (addon_status, file_status)
예제 #11
0
 def test_leave_nondisabled_files(self, os_mock):
     # All these addon/file status pairs should stay.
     stati = [(amo.STATUS_PUBLIC, amo.STATUS_PUBLIC),
              (amo.STATUS_PUBLIC, amo.STATUS_UNREVIEWED),
              (amo.STATUS_PUBLIC, amo.STATUS_BETA),
              (amo.STATUS_LITE, amo.STATUS_UNREVIEWED),
              (amo.STATUS_LITE, amo.STATUS_LITE),
              (amo.STATUS_LITE_AND_NOMINATED, amo.STATUS_UNREVIEWED),
              (amo.STATUS_LITE_AND_NOMINATED, amo.STATUS_LITE)]
     for addon_status, file_status in stati:
         self.addon.update(status=addon_status)
         File.objects.update(status=file_status)
         cron.hide_disabled_files()
         assert not os_mock.path.exists.called, (addon_status, file_status)
예제 #12
0
def test_extract_version_to_git_deleted_version():
    addon = addon_factory(file_kw={'filename': 'webextension_no_id.xpi'})

    version = addon.current_version
    version.delete()

    hide_disabled_files()

    extract_version_to_git(version.pk)

    repo = AddonGitRepository(addon.pk)

    assert repo.git_repository_path == os.path.join(
        settings.GIT_FILE_STORAGE_PATH, id_to_path(addon.id), 'addon')
    assert os.listdir(repo.git_repository_path) == ['.git']
예제 #13
0
def test_extract_version_to_git_deleted_version():
    addon = addon_factory(file_kw={'filename': 'webextension_no_id.xpi'})

    version = addon.current_version
    version.delete()

    hide_disabled_files()

    extract_version_to_git(version.pk)

    repo = AddonGitRepository(addon.pk)

    assert repo.git_repository_path == os.path.join(
        settings.GIT_FILE_STORAGE_PATH, id_to_path(addon.id), 'addon')
    assert os.listdir(repo.git_repository_path) == ['.git']
예제 #14
0
 def test_move_admin_disabled_addon(self, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(
         status=amo.STATUS_DISABLED)
     File.objects.update(status=amo.STATUS_PUBLIC)
     cron.hide_disabled_files()
     # Check that f2 was moved.
     f2 = self.f2
     mv_mock.assert_called_with(f2.file_path, f2.guarded_file_path,
                                self.msg)
     # Check that f1 was moved as well.
     f1 = self.f1
     mv_mock.call_args = mv_mock.call_args_list[0]
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     # There's only 2 files, both should have been moved.
     assert mv_mock.call_count == 2
예제 #15
0
파일: test_cron.py 프로젝트: diox/olympia
 def test_move_user_disabled_addon(self, mv_mock):
     # Use Addon.objects.update so the signal handler isn't called.
     Addon.objects.filter(id=self.addon.id).update(
         status=amo.STATUS_APPROVED, disabled_by_user=True)
     File.objects.update(status=amo.STATUS_APPROVED)
     cron.hide_disabled_files()
     # Check that f2 was moved.
     f2 = self.f2
     mv_mock.assert_called_with(f2.file_path, f2.guarded_file_path,
                                self.msg)
     # Check that f1 was moved as well.
     f1 = self.f1
     mv_mock.call_args = mv_mock.call_args_list[0]
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     # There's only 2 files, both should have been moved.
     assert mv_mock.call_count == 2
예제 #16
0
 def test_move_user_disabled_addon(self, mv_mock):
     # Use Addon.objects.update so the signal handler isn't called.
     Addon.objects.filter(id=self.addon.id).update(status=amo.STATUS_PUBLIC,
                                                   disabled_by_user=True)
     File.objects.update(status=amo.STATUS_PUBLIC)
     cron.hide_disabled_files()
     # Check that f2 was moved.
     f2 = self.f2
     mv_mock.assert_called_with(f2.file_path, f2.guarded_file_path,
                                self.msg)
     # Check that f1 was moved as well.
     f1 = self.f1
     mv_mock.call_args = mv_mock.call_args_list[0]
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     # There's only 2 files, both should have been moved.
     assert mv_mock.call_count == 2
예제 #17
0
 def test_move_admin_disabled_addon(self, m_storage, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(
         status=amo.STATUS_DISABLED)
     File.objects.update(status=amo.STATUS_PUBLIC)
     cron.hide_disabled_files()
     # Check that f2 was moved.
     f2 = self.f2
     mv_mock.assert_called_with(f2.file_path, f2.guarded_file_path,
                                self.msg)
     m_storage.delete.assert_called_with(f2.mirror_file_path)
     # Check that f1 was moved as well.
     f1 = self.f1
     mv_mock.call_args = mv_mock.call_args_list[0]
     m_storage.delete.call_args = m_storage.delete.call_args_list[0]
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     m_storage.delete.assert_called_with(f1.mirror_file_path)
     # There's only 2 files, both should have been moved.
     eq_(mv_mock.call_count, 2)
     eq_(m_storage.delete.call_count, 2)
예제 #18
0
def test_extract_version_source_to_git_deleted_version():
    addon = addon_factory(file_kw={'filename': 'webextension_no_id.xpi'})

    version = addon.current_version
    version.delete()

    hide_disabled_files()

    # Generate source file
    source = temp.NamedTemporaryFile(suffix='.zip', dir=settings.TMP_PATH)
    with zipfile.ZipFile(source, 'w') as zip_file:
        zip_file.writestr('manifest.json', '{}')
    source.seek(0)
    version.update(source=source)

    extract_version_source_to_git(version.pk)

    repo = AddonGitRepository(addon.pk, package_type='source')

    assert repo.git_repository_path == os.path.join(
        settings.GIT_FILE_STORAGE_PATH, id_to_path(addon.id), 'source')
    assert os.listdir(repo.git_repository_path) == ['.git']
예제 #19
0
def test_extract_version_source_to_git_deleted_version():
    addon = addon_factory(file_kw={'filename': 'webextension_no_id.xpi'})

    version = addon.current_version
    version.delete()

    hide_disabled_files()

    # Generate source file
    source = temp.NamedTemporaryFile(suffix='.zip', dir=settings.TMP_PATH)
    with zipfile.ZipFile(source, 'w') as zip_file:
        zip_file.writestr('manifest.json', '{}')
    source.seek(0)
    version.update(source=source)

    extract_version_source_to_git(version.pk)

    repo = AddonGitRepository(addon.pk, package_type='source')

    assert repo.git_repository_path == os.path.join(
        settings.GIT_FILE_STORAGE_PATH, id_to_path(addon.id), 'source')
    assert os.listdir(repo.git_repository_path) == ['.git']