<commit_before>describe ManageIQ::Providers::Lenovo::PhysicalInfraManager::Refresher do
  before(:all) do
    vcr_path = File.dirname(described_class.name.underscore)
    options = {:allow_playback_repeats => true}

    VCR.insert_cassette("#{vcr_path}/mock_aicc", options)
    VCR.insert_cassette("#{vcr_path}/mock_cabinet", options)
    VCR.insert_cassette("#{vcr_path}/mock_config_patterns", options)
  end
  after(:all) do
    while VCR.cassettes.last
      VCR.eject_cassette
    end
  end

  let(:auth) do
    FactoryGirl.create(:authentication,
                       :userid   => 'lxcc',
                       :password => '<PASSWORD>',
                       :authtype => 'default')
  end

  let(:ems) do
    ems = FactoryGirl.create(:physical_infra,
                             :name      => "LXCA",
                             :hostname  => "10.243.9.123",
                             :port      => "443",
                             :ipaddress => "https://10.243.9.123:443")
    ems.authentications = [auth]
    ems
  end

  let(:targets) { [ems] }

  let(:refresher) { described_class.new(targets) }

  it 'will parse the legacy inventory' do
    result = refresher.parse_legacy_inventory(ems)

    expect(result[:physical_servers].size).to eq(2)
  end

  it 'will save the inventory' do
    ems.authentications = [auth]

    refresher.save_inventory(ems, nil, {})
  end

  it 'will execute post_process_refresh_classes' do
    expect(refresher.post_process_refresh_classes).to eq([])
  end
end<commit_msg>Add spec test for a full refresh<commit_after>describe ManageIQ::Providers::Lenovo::PhysicalInfraManager::Refresher do
  before(:all) do
    vcr_path = File.dirname(described_class.name.underscore)
    options = {:allow_playback_repeats => true}

    VCR.insert_cassette("#{vcr_path}/mock_aicc", options)
    VCR.insert_cassette("#{vcr_path}/mock_cabinet", options)
    VCR.insert_cassette("#{vcr_path}/mock_config_patterns", options)
  end
  after(:all) do
    while VCR.cassettes.last
      VCR.eject_cassette
    end
  end

  let(:auth) do
    FactoryGirl.create(:authentication,
                       :userid   => 'lxcc',
                       :password => '<PASSWORD>',
                       :authtype => 'default')
  end

  let(:ems) do
    ems = FactoryGirl.create(:physical_infra,
                             :name      => "LXCA",
                             :hostname  => "10.243.9.123",
                             :port      => "443",
                             :ipaddress => "https://10.243.9.123:443")
    ems.authentications = [auth]
    ems
  end

  let(:targets) { [ems] }

  let(:refresher) { described_class.new(targets) }

  it 'will parse the legacy inventory' do
    result = refresher.parse_legacy_inventory(ems)

    expect(result[:physical_servers].size).to eq(2)
  end

  it 'will save the inventory' do
    ems.authentications = [auth]

    refresher.save_inventory(ems, nil, {})
  end

  it 'will execute post_process_refresh_classes' do
    expect(refresher.post_process_refresh_classes).to eq([])
  end

  it 'will perform a full refresh' do
    # Perform the refresh twice to verify that a second run with existing data
    # does not change anything
    2.times do
      EmsRefresh.refresh(ems)
      ems.reload

      assert_table_counts
      assert_guest_table_contents
    end
  end

  def assert_table_counts
    expect(PhysicalServer.count).to eq(2)
    expect(GuestDevice.count).to eq(5)
  end

  def assert_guest_table_contents
    nic = GuestDevice.where(:device_name => "Broadcom 2-port 1GbE NIC Card for IBM").first
    ports = nic.child_devices

    expect(ports[0].device_name).to eq("Physical Port 1")
    expect(ports[0].address).to eq("00:0A:F7:25:67:38")
    expect(ports[1].device_name).to eq("Physical Port 2")
    expect(ports[1].address).to eq("00:0A:F7:25:67:39")
  end
end
{'fraction_non_alphanumeric': 0.11923276308968378, 'fraction_numerical': 0.020995334370139968, 'mean_word_length': 2.5897674418604653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1376358', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1247, 'n_words': 242}