'Test publishing the latest, approved version when the app is
unlisted, with a current version also already public.'

@mock.patch('mkt.webapps.tasks.index_webapps')
@mock.patch('mkt.webapps.tasks.update_cached_manifests')
@mock.patch('mkt.webapps.models.Webapp.update_supported_locales')
@mock.patch('mkt.webapps.models.Webapp.update_name_from_package_manifest')
def test_publicise_version_new_unlisted(self, update_name, update_locales, update_cached_manifests, index_webapps):

    self.app.update(status=mkt.STATUS_UNLISTED)
    ver = version_factory(addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_APPROVED))
    eq_(self.app.latest_version, ver)
    ok_((self.app.current_version != ver))
    index_webapps.delay.reset_mock()
    eq_(update_name.call_count, 0)
    eq_(update_locales.call_count, 0)
    eq_(update_cached_manifests.delay.call_count, 0)
    res = self.post()
    eq_(res.status_code, 302)
    eq_(ver.reload().all_files[0].status, mkt.STATUS_PUBLIC)
    eq_(self.get_webapp().current_version, ver)
    eq_(update_name.call_count, 1)
    eq_(update_locales.call_count, 1)
    eq_(update_cached_manifests.delay.call_count, 1)
