def test_set_queries(client, site):
    # URIs
    dev_uri = site.list_uri('device')
    attr_uri = site.list_uri('attribute')
    ifc_uri = site.list_uri('interface')
    query_uri = site.query_uri('interface')

    # Pre-load the Attributes
    client.post(attr_uri, data=load('attributes.json'))

    # Create Devices
    dev1_resp = client.create(dev_uri, hostname='foo-bar1')
    dev2_resp = client.create(dev_uri, hostname='foo-bar2')

    dev1 = get_result(dev1_resp)
    dev2 = get_result(dev2_resp)

    # Create Interfaces
    dev1_eth0_resp = client.create(
        ifc_uri, device=dev1['id'], name='eth0',
        attributes={'vlan': '300', 'scope': 'region'},
    )
    dev1_eth1_resp = client.create(
        ifc_uri, device=dev1['id'], name='eth1',
        attributes={'vlan': '300', 'scope': 'global'},
    )
    dev2_eth0_resp = client.create(
        ifc_uri, device=dev2['id'], name='eth0',
        attributes={'scope': 'region'},
    )
    dev2_eth1_resp = client.create(
        ifc_uri, device=dev2['id'], name='eth1',
        attributes={'vlan': '400', 'scope': 'metro'},
    )

    dev1_eth0 = get_result(dev1_eth0_resp)
    dev1_eth1 = get_result(dev1_eth1_resp)
    dev2_eth0 = get_result(dev2_eth0_resp)
    dev2_eth1 = get_result(dev2_eth1_resp)

    # Populate the Interface objects and retreive them for testing.
    interfaces_resp = client.get(ifc_uri)
    interfaces = get_result(interfaces_resp)

    # INTERSECTION: vlan=300
    wanted = [dev1_eth0, dev1_eth1]
    expected = filter_interfaces(interfaces, wanted)
    assert_success(
        client.retrieve(query_uri, query='vlan=300'),
        expected
    )

    # INTERSECTION: vlan=300 scope=region
    wanted = [dev1_eth0]
    expected = filter_interfaces(interfaces, wanted)
    assert_success(
        client.retrieve(query_uri, query='vlan=300 scope=region'),
        expected
    )

    # DIFFERENCE: -scope=region
    wanted = [dev1_eth1, dev2_eth1]
    expected = filter_interfaces(interfaces, wanted)
    assert_success(
        client.retrieve(query_uri, query='-scope=region'),
        expected
    )

    # UNION: scope=global +vlan=400
    wanted = [dev1_eth1, dev2_eth1]
    expected = filter_interfaces(interfaces, wanted)
    assert_success(
        client.retrieve(query_uri, query='scope=global +vlan=400'),
        expected
    )

    # ERROR: bad query
    assert_error(
        client.retrieve(query_uri, query='bacon=delicious'),
        status.HTTP_400_BAD_REQUEST
    )
Test set queries for Interfaces.
dataset/ETHPy150Open dropbox/nsot/tests/api_tests/test_interfaces.py/test_set_queries