Example #1
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)
Example #2
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)
Example #3
0
 def test_ignore_deleted_versions(self, m_storage, mv_mock):
     # Apps only have 1 file and version delete only deletes one.
     self.f1.delete()
     self.version.delete()
     mv_mock.reset_mock()
     # Create a new version/file just like the one we deleted.
     version = Version.objects.create(addon=self.addon)
     File.objects.create(version=version, platform=self.p, filename='f2')
     cron.hide_disabled_files()
     # Mock shouldn't have been called.
     assert not mv_mock.called, mv_mock.call_args
Example #4
0
 def test_ignore_deleted_versions(self, m_storage, mv_mock):
     # Apps only have 1 file and version delete only deletes one.
     self.f1.delete()
     self.version.delete()
     mv_mock.reset_mock()
     # Create a new version/file just like the one we deleted.
     version = Version.objects.create(addon=self.addon)
     File.objects.create(version=version, platform=self.p, filename='f2')
     cron.hide_disabled_files()
     # Mock shouldn't have been called.
     assert not mv_mock.called, mv_mock.call_args
Example #5
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_OBSOLETE)
     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)
Example #6
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)
Example #7
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)
Example #8
0
 def test_move_disabled_file(self, os_mock, 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)
     #really only want to mock os.remove, so stick real os.path.join back in
     os_mock.path.join.side_effect = os.path.join
     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.
     os_mock.remove.assert_called_with(f1.mirror_file_path)
     eq_(os_mock.remove.call_count, 1)
Example #9
0
 def test_move_disabled_file(self, os_mock, 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)
     #really only want to mock os.remove, so stick real os.path.join back in
     os_mock.path.join.side_effect = os.path.join
     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.
     os_mock.remove.assert_called_with(f1.mirror_file_path)
     eq_(os_mock.remove.call_count, 1)
Example #10
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)
Example #11
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)
     # 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)
     # There's only 2 files, both should have been moved.
     eq_(mv_mock.call_count, 2)
     eq_(m_storage.delete.call_count, 2)
Example #12
0
 def test_move_user_disabled_addon(self, m_storage, 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]
     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)
     # There's only 2 files, both should have been moved.
     eq_(mv_mock.call_count, 2)
     eq_(m_storage.delete.call_count, 2)
Example #13
0
 def test_move_user_disabled_addon(self, m_storage, 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)
     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)
Example #14
0
 def test_move_admin_disabled_addon(self, os_mock, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(
         status=amo.STATUS_DISABLED)
     File.objects.update(status=amo.STATUS_PUBLIC)
     #really only want to mock os.remove, so stick real os.path.join back in
     os_mock.path.join.side_effect = os.path.join
     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)
     os_mock.remove.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]
     os_mock.remove.call_args = os_mock.remove.call_args_list[0]
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     os_mock.remove.assert_called_with(f1.mirror_file_path)
     # There's only 2 files, both should have been moved.
     eq_(mv_mock.call_count, 2)
     eq_(os_mock.remove.call_count, 2)
Example #15
0
 def test_move_admin_disabled_addon(self, os_mock, mv_mock):
     Addon.objects.filter(id=self.addon.id).update(
         status=amo.STATUS_DISABLED)
     File.objects.update(status=amo.STATUS_PUBLIC)
     #really only want to mock os.remove, so stick real os.path.join back in
     os_mock.path.join.side_effect = os.path.join
     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)
     os_mock.remove.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]
     os_mock.remove.call_args = os_mock.remove.call_args_list[0]
     mv_mock.assert_called_with(f1.file_path, f1.guarded_file_path,
                                self.msg)
     os_mock.remove.assert_called_with(f1.mirror_file_path)
     # There's only 2 files, both should have been moved.
     eq_(mv_mock.call_count, 2)
     eq_(os_mock.remove.call_count, 2)