Ejemplo n.º 1
0
 def test_move_public_files(self, mv_mock):
     self.addon.update(status=amo.STATUS_APPROVED)
     self.file_.update(status=amo.STATUS_APPROVED)
     cron.unhide_disabled_files()
     mv_mock.assert_called_with(
         self.file_.guarded_file_path, self.file_.file_path, self.msg)
     assert mv_mock.call_count == 1
Ejemplo n.º 2
0
    def test_doesnt_remove_non_empty_directories(self):
        # Add an extra disabled file. The approved one should move, but not the
        # other, so the directory should be left intact.
        self.disabled_file = file_factory(
            version=self.version, status=amo.STATUS_DISABLED)
        self.addon.update(status=amo.STATUS_APPROVED)
        self.file_.update(status=amo.STATUS_APPROVED)
        with storage.open(self.file_.guarded_file_path, 'wb') as fp:
            fp.write(b'content')
        assert not storage.exists(self.file_.file_path)
        assert storage.exists(self.file_.guarded_file_path)
        with storage.open(self.disabled_file.guarded_file_path, 'wb') as fp:
            fp.write(b'disabled content')
        assert not storage.exists(self.disabled_file.file_path)
        assert storage.exists(self.disabled_file.guarded_file_path)

        cron.unhide_disabled_files()

        assert storage.exists(self.file_.file_path)
        assert not storage.exists(self.file_.guarded_file_path)

        # The disabled file shouldn't have moved.
        assert not storage.exists(self.disabled_file.file_path)
        assert storage.exists(self.disabled_file.guarded_file_path)
        # The directory in guarded file path should still exist.
        assert storage.exists(os.path.dirname(self.file_.guarded_file_path))
Ejemplo n.º 3
0
    def test_doesnt_remove_non_empty_directories(self):
        # Add an extra disabled file. The approved one should move, but not the
        # other, so the directory should be left intact.
        self.disabled_file = file_factory(
            version=self.version, status=amo.STATUS_DISABLED)
        self.addon.update(status=amo.STATUS_APPROVED)
        self.file_.update(status=amo.STATUS_APPROVED)
        with storage.open(self.file_.guarded_file_path, 'wb') as fp:
            fp.write(b'content')
        assert not storage.exists(self.file_.file_path)
        assert storage.exists(self.file_.guarded_file_path)
        with storage.open(self.disabled_file.guarded_file_path, 'wb') as fp:
            fp.write(b'disabled content')
        assert not storage.exists(self.disabled_file.file_path)
        assert storage.exists(self.disabled_file.guarded_file_path)

        cron.unhide_disabled_files()

        assert storage.exists(self.file_.file_path)
        assert not storage.exists(self.file_.guarded_file_path)

        # The disabled file shouldn't have moved.
        assert not storage.exists(self.disabled_file.file_path)
        assert storage.exists(self.disabled_file.guarded_file_path)
        # The directory in guarded file path should still exist.
        assert storage.exists(os.path.dirname(self.file_.guarded_file_path))
Ejemplo n.º 4
0
 def test_move_public_files(self, mv_mock):
     self.addon.update(status=amo.STATUS_APPROVED)
     self.file_.update(status=amo.STATUS_APPROVED)
     cron.unhide_disabled_files()
     mv_mock.assert_called_with(
         self.file_.guarded_file_path, self.file_.file_path, self.msg)
     assert mv_mock.call_count == 1
Ejemplo n.º 5
0
 def test_move_not_disabled_files(self, unhide_mock):
     fpath = 'src/olympia/files/fixtures/files/webextension.xpi'
     with amo.tests.copy_file(fpath, self.file_.guarded_file_path):
         # Make sure this works correctly with bytestring base paths
         # and doesn't raise a `UnicodeDecodeError`
         # Reverts what got introduced in #11000 but accidently
         # broke various other unicode-path related things
         # (e.g file viewer extraction)
         cron.unhide_disabled_files()
         assert unhide_mock.called
Ejemplo n.º 6
0
 def test_move_not_disabled_files(self, unhide_mock):
     fpath = 'src/olympia/files/fixtures/files/jetpack.xpi'
     with amo.tests.copy_file(fpath, self.file_.guarded_file_path):
         # Make sure this works correctly with bytestring base paths
         # and doesn't raise a `UnicodeDecodeError`
         # Reverts what got introduced in #11000 but accidently
         # broke various other unicode-path related things
         # (e.g file viewer extraction)
         cron.unhide_disabled_files()
         assert unhide_mock.called
Ejemplo n.º 7
0
    def test_cleans_up_empty_directories_after_moving(self):
        self.addon.update(status=amo.STATUS_APPROVED)
        self.file_.update(status=amo.STATUS_APPROVED)
        with storage.open(self.file_.guarded_file_path, 'wb') as fp:
            fp.write(b'content')
        assert not storage.exists(self.file_.file_path)
        assert storage.exists(self.file_.guarded_file_path)

        cron.unhide_disabled_files()

        assert storage.exists(self.file_.file_path)
        assert not storage.exists(self.file_.guarded_file_path)
        # Empty dir also removed:
        assert not storage.exists(os.path.dirname(self.file_.guarded_file_path))
Ejemplo n.º 8
0
    def test_move_not_disabled_files(self, unhide_mock):
        fpath = 'src/olympia/files/fixtures/files/jetpack.xpi'
        with amo.tests.copy_file(fpath, self.file_.guarded_file_path):
            cron.unhide_disabled_files()
            assert unhide_mock.called

            # Not a unicode string for the path.
            with override_settings(GUARDED_ADDONS_PATH='/tmp/guarded-addons'):
                with self.assertRaises(UnicodeDecodeError):
                    # If the parameter to "os.walk" (called by
                    # amo.utils.walkfiles) isn't a unicode string, it'll return
                    # ascii encoded paths, which will break the File query with
                    # the filename, raising the exception.
                    cron.unhide_disabled_files()
Ejemplo n.º 9
0
    def test_move_not_disabled_files(self, unhide_mock):
        fpath = 'src/olympia/files/fixtures/files/jetpack.xpi'
        with amo.tests.copy_file(fpath, self.file_.guarded_file_path):
            cron.unhide_disabled_files()
            assert unhide_mock.called

            # Not a unicode string for the path.
            with override_settings(GUARDED_ADDONS_PATH='/tmp/guarded-addons'):
                with self.assertRaises(UnicodeDecodeError):
                    # If the parameter to "os.walk" (called by
                    # amo.utils.walkfiles) isn't a unicode string, it'll return
                    # ascii encoded paths, which will break the File query with
                    # the filename, raising the exception.
                    cron.unhide_disabled_files()
Ejemplo n.º 10
0
    def test_cleans_up_empty_directories_after_moving(self):
        self.addon.update(status=amo.STATUS_APPROVED)
        self.file_.update(status=amo.STATUS_APPROVED)
        with storage.open(self.file_.guarded_file_path, 'wb') as fp:
            fp.write(b'content')
        assert not storage.exists(self.file_.file_path)
        assert storage.exists(self.file_.guarded_file_path)

        cron.unhide_disabled_files()

        assert storage.exists(self.file_.file_path)
        assert not storage.exists(self.file_.guarded_file_path)
        # Empty dir also removed:
        assert not storage.exists(
            os.path.dirname(self.file_.guarded_file_path))
Ejemplo n.º 11
0
    def test_leave_disabled_files(self, os_mock):
        self.addon.update(status=amo.STATUS_DISABLED)
        cron.unhide_disabled_files()
        assert not os_mock.path.exists.called

        self.addon.update(status=amo.STATUS_PUBLIC)
        self.file_.update(status=amo.STATUS_DISABLED)
        cron.unhide_disabled_files()
        assert not os_mock.path.exists.called

        self.addon.update(disabled_by_user=True)
        self.file_.update(status=amo.STATUS_PUBLIC)
        cron.unhide_disabled_files()
        assert not os_mock.path.exists.called
Ejemplo n.º 12
0
    def test_leave_disabled_files(self, os_mock):
        self.addon.update(status=amo.STATUS_DISABLED)
        cron.unhide_disabled_files()
        assert not os_mock.path.exists.called

        self.addon.update(status=amo.STATUS_PUBLIC)
        self.file_.update(status=amo.STATUS_DISABLED)
        cron.unhide_disabled_files()
        assert not os_mock.path.exists.called

        self.addon.update(disabled_by_user=True)
        self.file_.update(status=amo.STATUS_PUBLIC)
        cron.unhide_disabled_files()
        assert not os_mock.path.exists.called