<commit_before>class TestPort < Test::Unit::TestCase
  def test_port

    # https://docs.openstack.org/api-ref/network/v2/?expanded=list-floating-ips-detail,show-port-details-detail#ports
    params = {
      "admin_state_up" => true,
      "allowed_address_pairs" => [],
      "created_at" => "2016-03-08T20:19:41",
      "data_plane_status" => "ACTIVE",
      "description" => "",
      "device_id" => "5e3898d7-11be-483e-9732-b2f5eccd2b2e",
      "device_owner" => "network:router_interface",
      "dns_assignment" => {
        "hostname" => "myport",
        "ip_address" => "10.0.0.1",
        "fqdn" => "myport.my-domain.org"
      },
      "dns_domain" => "my-domain.org.",
      "dns_name" => "myport",
      "extra_dhcp_opts" => [
        {
          "opt_value" => "pxelinux.0",
          "ip_version" => 4,
          "opt_name" => "bootfile-name"
        }
      ],
      "fixed_ips" => [
        {
          "ip_address" => "10.0.0.1",
          "subnet_id" => "a0304c3a-4f08-4c43-88af-d796509c97d2"
        }
      ],
      "id" => "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2",
      "ip_allocation" => "immediate",
      "mac_address" => "fa:16:3e:23:fd:d7",
      "name" => "foobar",
      "network_id" => "a87cc70a-3e15-4acf-8205-9b711a3531b7",
      "port_security_enabled" => false,
      "project_id" => "7e02058126cc4950b75f9970368ba177",
      "revision_number" => 1,
      "security_groups" => [],
      "status" => "ACTIVE",
      "tags" => ["tag1,tag2"],
      "tenant_id" => "7e02058126cc4950b75f9970368ba177",
      "updated_at" => "2016-03-08T20:19:41",
      "qos_policy_id" => "29d5e02e-d5ab-4929-bee4-4a9fc12e22ae",
      "uplink_status_propagation" => false,
      "binding:host_id" => "compute-000",
    }

    port = Yao::Port.new(params)
    assert_equal(port.id, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")

    # friendly_attributes
    assert_equal(port.name, "foobar")
    assert_equal(port.mac_address, "fa:16:3e:23:fd:d7")
    assert_equal(port.status, "ACTIVE")
    assert_equal(port.allowed_address_pairs, [])
    assert_equal(port.device_owner, "network:router_interface")
    assert_equal(port.fixed_ips, [
      {
        "ip_address" => "10.0.0.1",
        "subnet_id" => "a0304c3a-4f08-4c43-88af-d796509c97d2"
      }
    ])
    assert_equal(port.security_groups, [])
    assert_equal(port.device_id, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
    assert_equal(port.network_id, "a87cc70a-3e15-4acf-8205-9b711a3531b7")
    assert_equal(port.tenant_id, "7e02058126cc4950b75f9970368ba177")
    assert_equal(port.admin_state_up, true)

    # map_attribute_to_attribute
    assert_equal(port.host_id, "compute-000")
  end
end<commit_msg>add test of Yao::Port#teant<commit_after>class TestPort < Test::Unit::TestCase

  def setup
    Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
  end

  def test_port

    # https://docs.openstack.org/api-ref/network/v2/?expanded=list-floating-ips-detail,show-port-details-detail#ports
    params = {
      "admin_state_up" => true,
      "allowed_address_pairs" => [],
      "created_at" => "2016-03-08T20:19:41",
      "data_plane_status" => "ACTIVE",
      "description" => "",
      "device_id" => "5e3898d7-11be-483e-9732-b2f5eccd2b2e",
      "device_owner" => "network:router_interface",
      "dns_assignment" => {
        "hostname" => "myport",
        "ip_address" => "10.0.0.1",
        "fqdn" => "myport.my-domain.org"
      },
      "dns_domain" => "my-domain.org.",
      "dns_name" => "myport",
      "extra_dhcp_opts" => [
        {
          "opt_value" => "pxelinux.0",
          "ip_version" => 4,
          "opt_name" => "bootfile-name"
        }
      ],
      "fixed_ips" => [
        {
          "ip_address" => "10.0.0.1",
          "subnet_id" => "a0304c3a-4f08-4c43-88af-d796509c97d2"
        }
      ],
      "id" => "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2",
      "ip_allocation" => "immediate",
      "mac_address" => "fa:16:3e:23:fd:d7",
      "name" => "foobar",
      "network_id" => "a87cc70a-3e15-4acf-8205-9b711a3531b7",
      "port_security_enabled" => false,
      "project_id" => "7e02058126cc4950b75f9970368ba177",
      "revision_number" => 1,
      "security_groups" => [],
      "status" => "ACTIVE",
      "tags" => ["tag1,tag2"],
      "tenant_id" => "7e02058126cc4950b75f9970368ba177",
      "updated_at" => "2016-03-08T20:19:41",
      "qos_policy_id" => "29d5e02e-d5ab-4929-bee4-4a9fc12e22ae",
      "uplink_status_propagation" => false,
      "binding:host_id" => "compute-000",
    }

    port = Yao::Port.new(params)
    assert_equal(port.id, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")

    # friendly_attributes
    assert_equal(port.name, "foobar")
    assert_equal(port.mac_address, "fa:16:3e:23:fd:d7")
    assert_equal(port.status, "ACTIVE")
    assert_equal(port.allowed_address_pairs, [])
    assert_equal(port.device_owner, "network:router_interface")
    assert_equal(port.fixed_ips, [
      {
        "ip_address" => "10.0.0.1",
        "subnet_id" => "a0304c3a-4f08-4c43-88af-d796509c97d2"
      }
    ])
    assert_equal(port.security_groups, [])
    assert_equal(port.device_id, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
    assert_equal(port.network_id, "a87cc70a-3e15-4acf-8205-9b711a3531b7")
    assert_equal(port.tenant_id, "7e02058126cc4950b75f9970368ba177")
    assert_equal(port.admin_state_up, true)

    # map_attribute_to_attribute
    assert_equal(port.host_id, "compute-000")
  end

  def test_port_to_tenant

    stub_request(:get, "http://endpoint.example.com:12345/v2.0/tenants/0123456789abcdef0123456789abcdef")
      .to_return(
        status: 200,
        body: <<-JSON,
        {
          "tenants": [{
            "id": "0123456789abcdef0123456789abcdef"
          }]
        }
        JSON
        headers: {'Content-Type' => 'application/json'}
      )

    port = Yao::Port.new('tenant_id' => '0123456789abcdef0123456789abcdef')
    assert { port.tenant.is_a? Yao::Tenant }
  end
end
{'fraction_non_alphanumeric': 0.16711319490957804, 'fraction_numerical': 0.11604152712659076, 'mean_word_length': 2.937376400791035, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 81, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '2246656', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2469, 'n_words': 242}