def test_block_duplicate_version(self): eq_(self.addon.versions.count(), 1) assert tasks.repackage_jetpack(self.builder_data()) eq_(self.addon.versions.count(), 2) # Make a new temp file for urlretrieve. tmp_file = self.create_temp_file() self.urllib.urlretrieve.return_value = (tmp_file, None) assert not tasks.repackage_jetpack(self.builder_data()) eq_(self.addon.versions.count(), 2)
def test_block_duplicate_version(self): eq_(self.addon.versions.count(), 1) assert tasks.repackage_jetpack(self.builder_data()) eq_(self.addon.versions.count(), 2) # Make a new temp file for urlretrieve. tmp_file = self.create_temp_file() self.urllib.urlretrieve.return_value = (tmp_file.name, None) assert not tasks.repackage_jetpack(self.builder_data()) eq_(self.addon.versions.count(), 2)
def test_unreviewed_file_not_on_mirror(self): # Make sure the mirror dir is clear. mirrordir = settings.MIRROR_STAGE_PATH + "/3615" rmtree(mirrordir) self.file.update(status=amo.STATUS_UNREVIEWED) new_file = tasks.repackage_jetpack(self.builder_data()) assert not storage.exists(new_file.mirror_file_path)
def test_new_version(self): num_versions = self.addon.versions.count() new_file = tasks.repackage_jetpack(self.builder_data()) eq_(num_versions + 1, self.addon.versions.count()) new_version = self.addon.versions.latest() new_version.all_files = [new_file]
def test_unreviewed_file_not_on_mirror(self): # Make sure the mirror dir is clear. mirrordir = user_media_path('mirror_stage') + '/3615' rmtree(mirrordir) self.file.update(status=amo.STATUS_UNREVIEWED) new_file = tasks.repackage_jetpack(self.builder_data()) assert not storage.exists(new_file.mirror_file_path)
def test_unreviewed_file_not_on_mirror(self): # Make sure the mirror dir is clear. mirrordir = settings.MIRROR_STAGE_PATH + '/3615' rmtree(mirrordir) self.file.update(status=amo.STATUS_UNREVIEWED) new_file = tasks.repackage_jetpack(self.builder_data()) assert not storage.exists(new_file.mirror_file_path)
def test_supported_apps(self): version = tasks.repackage_jetpack(self.builder_data()).version old_apps = self.file.version.compatible_apps eq_(version.compatible_apps.keys(), old_apps.keys()) for app, appver in version.compatible_apps.items(): eq_(old_apps[app].max, appver.max) eq_(old_apps[app].min, appver.min)
def test_supported_apps(self): # Create AppVersions to match what's in the xpi. AppVersion.objects.create(application_id=amo.FIREFOX.id, version="3.6") AppVersion.objects.create(application_id=amo.FIREFOX.id, version="4.0b6") # Make sure the new appver matches the old appver. new = tasks.repackage_jetpack(self.builder_data()).version for old_app in self.file.version.apps.all(): new_app = new.apps.filter(application=old_app.application) eq_(new_app.values_list("min", "max")[0], (old_app.min_id, old_app.max_id))
def test_cancel_only_affects_bulk(self): # Get the data so a row is set in redis. data = self.builder_data() # Clear out everything. self.upgrader.cancel() # Put the file back in redis. self.upgrader.file(self.file.id, {"uuid": self.uuid, "file": self.file.id, "version": "1.0b4"}) # Try to clear again, this should skip the ownerless task above. self.upgrader.cancel() # The task should still work and return a new file. assert tasks.repackage_jetpack(data)
def test_supported_apps(self): # Create AppVersions to match what's in the xpi. AppVersion.objects.create(application=amo.FIREFOX.id, version='3.6') AppVersion.objects.create(application=amo.FIREFOX.id, version='4.0b6') # Make sure the new appver matches the old appver. new = tasks.repackage_jetpack(self.builder_data()).version for old_app in self.file.version.apps.all(): new_app = new.apps.filter(application=old_app.application) eq_( new_app.values_list('min', 'max')[0], (old_app.min_id, old_app.max_id))
def test_cancel_only_affects_bulk(self): # Get the data so a row is set in redis. data = self.builder_data() # Clear out everything. self.upgrader.cancel() # Put the file back in redis. self.upgrader.file(self.file.id, { 'uuid': self.uuid, 'version': '1.0b4' }) # Try to clear again, this should skip the ownerless task above. self.upgrader.cancel() # The task should still work and return a new file. assert tasks.repackage_jetpack(data)
def test_new_version_number(self): tasks.repackage_jetpack(self.builder_data()) new_version = self.addon.versions.latest() # From jetpack.xpi. eq_(new_version.version, '1.3')
def test_unreviewed_file_not_on_mirror(self): # Make sure the mirror dir is clear. shutil.rmtree(os.path.dirname(self.file.mirror_file_path)) self.file.update(status=amo.STATUS_UNREVIEWED) new_file = tasks.repackage_jetpack(self.builder_data()) assert not os.path.exists(new_file.mirror_file_path)
def test_file_on_mirror(self): # Make sure the mirror dir is clear. shutil.rmtree(os.path.dirname(self.file.mirror_file_path)) new_file = tasks.repackage_jetpack(self.builder_data()) assert os.path.exists(new_file.mirror_file_path)
def test_result_not_success(self): data = self.builder_data(result='fail', msg='oops') eq_(tasks.repackage_jetpack(data), None)
def test_result_not_success(self): data = self.builder_data(result="fail", msg="oops") eq_(tasks.repackage_jetpack(data), None)
def test_new_file_hash(self): new_file = tasks.repackage_jetpack(self.builder_data()) hash_ = hashlib.sha256() hash_.update(open(self.xpi_path, 'rb').read()) eq_(new_file.hash, 'sha256:' + hash_.hexdigest())
def test_bad_addon_id(self): data = self.builder_data(addon=22) with self.assertRaises(models.ObjectDoesNotExist): tasks.repackage_jetpack(data)
def test_bad_file_id(self): data = self.builder_data(file_id=234234) # Stick the file in the upgrader so it doesn't fail the uuid check. self.upgrader.file(234234, {'file': 234234, 'uuid': self.uuid}) with self.assertRaises(models.ObjectDoesNotExist): tasks.repackage_jetpack(data)
def test_urllib_failure(self): self.urllib.urlretrieve.side_effect = StopIteration with self.assertRaises(StopIteration): tasks.repackage_jetpack(self.builder_data())
def test_addon_current_version(self): new_file = tasks.repackage_jetpack(self.builder_data()) addon = Addon.objects.get(id=self.addon.id) eq_(addon.current_version, new_file.version)
def test_new_file_status(self): new_file = tasks.repackage_jetpack(self.builder_data()) eq_(new_file.status, self.file.status)
def test_clear_redis_after_success(self): # Get the data so a row is set in redis. data = self.builder_data() assert tasks.repackage_jetpack(data) eq_(self.upgrader.file(self.file.id), {}) eq_(self.upgrader.version(), None)
def test_cancel(self): # Get the data so a row is set in redis. data = self.builder_data() self.upgrader.cancel() eq_(tasks.repackage_jetpack(data), None)
def test_email_sent(self): assert tasks.repackage_jetpack(self.builder_data()) eq_(len(mail.outbox), 1)
def test_file_on_mirror(self): # Make sure the mirror dir is clear. if storage.exists(os.path.dirname(self.file.mirror_file_path)): rmtree(os.path.dirname(self.file.mirror_file_path)) new_file = tasks.repackage_jetpack(self.builder_data()) assert storage.exists(new_file.mirror_file_path)