from assertpy import assert_that
from cfgtools import (
    ARRAY,
    Configuration,
    STRING,
    read_string,
)


def test_equality():
    xml = """
<config>
  <group name="group1">
    <group name="subGroup1">
      <key name="key1">
        <string>value1</string>
      </key>
    </group>
    <group name="subGroup2">
      <key name="key2">
        <string>value2</string>
      </key>
      <key name="key3">
        <string>value3</string>
      </key>
    </group>
  </group>
  <group name="group3">
    <group name="subGroup3">
      <key name="key4">
        <string>value4</string>
      </key>
    </group>
    <group name="subGroup4">
      <key name="key5">
        <string>value5</string>
      </key>
      <key name="key6">
        <string>value6</string>
      </key>
    </group>
  </group>
  <group name="group4">
    <key name="key7">
      <array>
        <string>array1</string>
        <string>array2</string>
        <string>array3</string>
      </array>
    </key>
  </group>    
</config>
"""
    cfg1 = read_string(xml)

    cfg2 = Configuration()
    group4 = cfg2.add_group("group4")
    group4.add_key("key7", type=ARRAY).add_value("array1").add_value("array2").add_value("array3")

    group1 = cfg2.add_group("group1")
    sub_group_2 = group1.add_group("subGroup2")
    sub_group_2.add_key("key3", type=STRING).add_value("value3")
    sub_group_2.add_key("key2", type=STRING).add_value("value2")
    group1.add_group("subGroup1").add_key("key1", type=STRING).add_value("value1")

    group3 = cfg2.add_group("group3")
    sub_group_4 = group3.add_group("subGroup4")
    sub_group_4.add_key("key6", type=STRING).add_value("value6")
    sub_group_4.add_key("key5", type=STRING).add_value("value5")
    sub_group_3 = group3.add_group("subGroup3")
    sub_group_3.add_key("key4", type=STRING).add_value("value4")

    assert_that(cfg1).is_equal_to(cfg2)
