debian-mirror-gitlab/spec/presenters/packages/pypi/package_presenter_spec.rb

65 lines
2.5 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Packages::Pypi::PackagePresenter do
using RSpec::Parameterized::TableSyntax
2021-09-04 01:27:46 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
2020-07-28 23:09:34 +05:30
let_it_be(:package_name) { 'sample-project' }
let_it_be(:package1) { create(:pypi_package, project: project, name: package_name, version: '1.0.0') }
let_it_be(:package2) { create(:pypi_package, project: project, name: package_name, version: '2.0.0') }
let(:packages) { [package1, package2] }
2021-09-04 01:27:46 +05:30
let(:file) { package.package_files.first }
let(:filename) { file.file_name }
2020-07-28 23:09:34 +05:30
2021-09-04 01:27:46 +05:30
subject(:presenter) { described_class.new(packages, project_or_group).body}
2020-07-28 23:09:34 +05:30
2021-09-04 01:27:46 +05:30
describe '#body' do
shared_examples_for "pypi package presenter" do
where(:version, :expected_version, :with_package1) do
'>=2.7' | '>=2.7' | true
'"><script>alert(1)</script>' | '&quot;&gt;&lt;script&gt;alert(1)&lt;/script&gt;' | true
'>=2.7, !=3.0' | '&gt;=2.7, !=3.0' | false
2020-07-28 23:09:34 +05:30
end
2021-09-04 01:27:46 +05:30
with_them do
let(:python_version) { version }
let(:expected_python_version) { expected_version }
let(:package) { with_package1 ? package1 : package2 }
2020-07-28 23:09:34 +05:30
2021-09-04 01:27:46 +05:30
before do
package.pypi_metadatum.required_python = python_version
end
it { is_expected.to include expected_file }
end
2020-07-28 23:09:34 +05:30
end
2021-09-04 01:27:46 +05:30
context 'for project' do
let(:project_or_group) { project }
let(:expected_file) { "<a href=\"http://localhost/api/v4/projects/#{project.id}/packages/pypi/files/#{file.file_sha256}/#{filename}#sha256=#{file.file_sha256}\" data-requires-python=\"#{expected_python_version}\">#{filename}</a><br>" }
it_behaves_like 'pypi package presenter'
2020-07-28 23:09:34 +05:30
end
2021-09-04 01:27:46 +05:30
context 'for group' do
let(:project_or_group) { group }
let(:expected_file) { "<a href=\"http://localhost/api/v4/groups/#{group.id}/-/packages/pypi/files/#{file.file_sha256}/#{filename}#sha256=#{file.file_sha256}\" data-requires-python=\"#{expected_python_version}\">#{filename}</a><br>" }
it_behaves_like 'pypi package presenter'
2020-07-28 23:09:34 +05:30
end
2022-03-02 08:16:31 +05:30
context 'with package files pending destruction' do
let_it_be(:package_file_pending_destruction) { create(:package_file, :pending_destruction, package: package1, file_name: "package_file_pending_destruction") }
let(:project_or_group) { project }
it { is_expected.not_to include(package_file_pending_destruction.file_name)}
end
2020-07-28 23:09:34 +05:30
end
end