summaryrefslogtreecommitdiff
path: root/spec/unit/python/source_spec.rb
blob: 839ff548f10c8908cb30129f9796701e39efaf56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

RSpec.describe Spandx::Python::Source do
  describe '#lookup' do
    context 'when fetching metadata for a known package from https://pypi.org' do
      subject { described_class.default }

      let(:result) do
        VCR.use_cassette('pypi/pytest-5.4.1') do
          subject.lookup('pytest', '5.4.1')
        end
      end

      specify { expect(result).not_to be_nil }
      specify { expect(result['info']).not_to be_nil }
      specify { expect(result['info']['name']).to eql('pytest') }
      specify { expect(result['info']['version']).to eql('5.4.1') }
    end

    context 'when fetching metadata for a known package from https://test.pypi.org' do
      subject { described_class.new({ 'name' => 'pypi', 'url' => 'https://test.pypi.org/simple', 'verify_ssl' => true }) }

      let(:result) do
        VCR.use_cassette('test.pypi/pip-18.1') do
          subject.lookup('pip', '18.1')
        end
      end

      specify { expect(result).not_to be_nil }
      specify { expect(result['info']).not_to be_nil }
      specify { expect(result['info']['name']).to eql('pip') }
      specify { expect(result['info']['version']).to eql('18.1') }
    end
  end

  describe '.sources_from' do
    context 'when the source is invalid' do
      subject { described_class.sources_from(json) }

      let(:json) do
        {
          '_meta' => {
            'sources' => [
              { name: 'pypi', url: '<%= @index_url %>', 'verify_ssl' => true }
            ]
          }
        }
      end

      it 'returns the default source' do
        expect(subject).to match_array([described_class.default])
      end
    end
  end
end