import pytest
import zmq
import time


pytestmark = pytest.mark.discovery

@pytest.mark.device
def test_device_init(device):
    assert device.socket.getsockopt(zmq.TYPE) == zmq.PUB

@pytest.mark.user
def test_user_init(user):
    assert user.socket.getsockopt(zmq.TYPE) == zmq.SUB

@pytest.mark.proxy
def test_proxy_init(proxy):
    assert proxy.socket[0].getsockopt(zmq.TYPE) == zmq.SUB
    assert proxy.socket[1].getsockopt(zmq.TYPE) == zmq.PUB

def test_discovery(device, user, proxy):
    proxy.start()
    device.start()
    user.start()
    time.sleep(1)
    proxy.stop()
    device.stop()
    user.stop()
    assert "Device Name" in user.device_list
