import py
import autopath
from httpmp2.handlers import CommandPipe, ClientEventPage
from httpmp2.httpserver import Request

class FakeEngine(object):
    def __init__(self):
        self.clients = {}

    def add_client(self, id, client):
        self.clients[id] = client

class TestCommandPipe(object):
    def setup_class(cls):
        CommandPipe.engine = FakeEngine()
        cls.request = req = Request()
        req.path = '/out'
        req.method = 'GET'
        req.httpver = 'HTTP/1.0'
        req.headers = {}
        cls.cp = CommandPipe(None, req, None)

    def test_get_new_id(self):
        id1 = self.cp.get_new_id()
        id2 = self.cp.get_new_id()
        assert id1 < id2

    def test_get_id(self):
        id1 = self.cp.get_id()
        id2 = self.cp.get_id()
        assert id2 > id1
        self.request.path += '?channelid=%s' % (id2,)
        id3 = int(self.cp.get_id())
        assert id2 == id3


