Example #1
0
    def test_part(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        c2 = yield self._mk_client('bar')
        yield c1.read_message()  # C2's join

        c2.close()
        response = yield c1.read_message()

        self.assertEqual(
            {
                'sender': c2.config['id'],
                'kind': 'part',
                'body': None
            }, json.loads(response))

        c1.close()

        # Wait for the channel to be removed.
        yield gen.sleep(0.001)

        with self.assertRaises(ChannelDoesNotExist):
            Channels.get(self.channel_id)
Example #2
0
    def setUp(self):
        super(BaseAsyncTest, self).setUp()
        Channels.reset()

        application = make_application()
        server = httpserver.HTTPServer(application)
        socket, self.port = testing.bind_unused_port()
        server.add_socket(socket)
Example #3
0
    def post(self):
        channel_id = self.get_argument('id')
        meta = self.get_argument('meta')

        try:
            Channels.create(channel_id, meta)
            self.write({"id": channel_id, "meta": meta})
        except ChannelAlreadyExists:
            self.set_status(409)  # Conflict
            self.write({"error": "The requested channel already exists."})
Example #4
0
 def test_remove(self):
     Channels.create(self.channel_id, self.meta)
     self.assertEqual(1, Channels.count())
     Channels.remove(self.channel_id)
     self.assertEqual(0, Channels.count())
     Channels.remove(self.channel_id)
     self.assertEqual(0, Channels.count())
Example #5
0
File: chat.py Project: sbuss/qotr
    def on_close(self):
        if not self.channel:
            return

        self.channel.connections -= 1

        if self.channel.has(self):
            self.channel.part(self)
            self.broadcast(Message(MT.part, sender=self))

        if self.channel.connections <= 0:
            L.debug('Deleting channel: %s', self.channel_id)
            Channels.remove(self.channel_id)
Example #6
0
    def on_close(self):
        if not self.channel:
            return

        self.channel.connections -= 1

        if self.channel.has(self):
            self.channel.part(self)
            self.broadcast(Message(MT.part, sender=self))

        if self.channel.connections <= 0:
            L.debug('Deleting channel: %s', self.channel_id)
            Channels.remove(self.channel_id)
Example #7
0
    def post(self):
        channel_id = self.get_argument('id')
        meta = self.get_argument('meta')

        try:
            Channels.create(channel_id, meta)
            self.write({
                "id": channel_id,
                "meta": meta
            })
        except ChannelAlreadyExists:
            self.set_status(409) # Conflict
            self.write({
                "error": "The requested channel already exists."
            })
Example #8
0
    def test_join(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        yield self._mk_client('bar')
        yield c1.read_message()  # C2's join

        self.assertEqual(2, len(channel.clients))
Example #9
0
 def test_join_part(self):
     channel = Channels.create(self.channel_id, self.meta)
     channel.join(self.member)
     self.assertTrue(channel.has(self.member))
     self.assertEqual({
         self.member.id: self.member.nick
     }, channel.members)
     channel.part(self.member)
     self.assertEqual({}, channel.members)
Example #10
0
    def test_join(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        yield self._mk_client('bar')
        yield c1.read_message() # C2's join

        self.assertEqual(2, len(channel.clients))
Example #11
0
    def test_nick(self):
        channel = Channels.get(self.channel_id)
        nick_1 = 'foo'
        nick_2 = 'bar'

        c1 = yield self._mk_client(nick_1)
        yield self._mk_client(nick_2)
        yield c1.read_message() # C2's join

        self.assertEqual({nick_1, nick_2}, set(channel.members.values()))
Example #12
0
    def test_nick(self):
        channel = Channels.get(self.channel_id)
        nick_1 = 'foo'
        nick_2 = 'bar'

        c1 = yield self._mk_client(nick_1)
        yield self._mk_client(nick_2)
        yield c1.read_message()  # C2's join

        self.assertEqual({nick_1, nick_2}, set(channel.members.values()))
Example #13
0
    def test_stats(self):
        channel = Channels.create("test-channel", "common")
        response = json.loads(self.fetch('/channels/').body.decode('utf8'))

        self.assertEqual({"connections": 0, "channels": 1}, response)

        channel.connections += 1
        response = json.loads(self.fetch('/channels/').body.decode('utf8'))

        self.assertEqual({"connections": 1, "channels": 1}, response)
Example #14
0
    def test_existing(self):
        self.assertFalse(Channels.exists(self.channel_id))
        Channels.create(self.channel_id, self.meta)
        self.assertTrue(Channels.exists(self.channel_id))

        with self.assertRaises(ChannelAlreadyExists):
            Channels.create(self.channel_id, self.meta)
Example #15
0
    def test_ping(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c = yield self._mk_client('foo')
        send(c, m('ping'))
        response = yield c.read_message()

        self.assertEqual({
            "kind": "pong",
            "body": None,
            "sender": None
        }, json.loads(response))
Example #16
0
    def test_ping(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c = yield self._mk_client('foo')
        send(c, m('ping'))
        response = yield c.read_message()

        self.assertEqual({
            "kind": "pong",
            "body": None,
            "sender": None
        }, json.loads(response))
Example #17
0
File: chat.py Project: sbuss/qotr
 def open(self, channel_id):
     self.channel_id = channel_id
     try:
         self.channel = Channels.get(self.channel_id)
         self.id = self.channel.new_id()
         # Tell the user their id and the channel's meta data.
         Message(MT.config, body={
             "id": self.id,
             "meta": self.channel.meta
         }).send(self)
         self.channel.connections += 1
     except ChannelDoesNotExist:
         self.respond_with_error("Channel does not exist.")
         self.close()
Example #18
0
 def open(self, channel_id):
     self.channel_id = channel_id
     try:
         self.channel = Channels.get(self.channel_id)
         self.id = self.channel.new_id()
         # Tell the user their id and the channel's meta data.
         Message(MT.config, body={
             "id": self.id,
             "meta": self.channel.meta
         }).send(self)
         self.channel.connections += 1
     except ChannelDoesNotExist:
         self.respond_with_error("Channel does not exist.")
         self.close()
Example #19
0
    def test_nick_change(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        c2 = yield self._mk_client('bar')

        send(c1, m('nick', 'foo-new'))
        response = yield c2.read_message()

        self.assertEqual({
            "kind": "nick",
            "body": "foo-new",
            "sender": c1.config['id']
        }, json.loads(response))
Example #20
0
    def test_part(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        c2 = yield self._mk_client('bar')
        yield c1.read_message() # C2's join

        c2.close()
        response = yield c1.read_message()

        self.assertEqual({
            'sender': c2.config['id'],
            'kind': 'part',
            'body': None
        }, json.loads(response))

        c1.close()

        # Wait for the channel to be removed.
        yield gen.sleep(0.001)

        with self.assertRaises(ChannelDoesNotExist):
            Channels.get(self.channel_id)
Example #21
0
    def test_nick_change(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        c2 = yield self._mk_client('bar')

        send(c1, m('nick', 'foo-new'))
        response = yield c2.read_message()

        self.assertEqual(
            {
                "kind": "nick",
                "body": "foo-new",
                "sender": c1.config['id']
            }, json.loads(response))
Example #22
0
    def test_chat(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        c2 = yield self._mk_client('bar')
        yield c1.read_message() # C2's join

        send(c1, m('chat', 'hey!'))
        response = yield c2.read_message()

        self.assertEqual({
            'sender': c1.config['id'],
            'kind': 'chat',
            'body': 'hey!'
        }, json.loads(response))
Example #23
0
    def test_chat(self):
        channel = Channels.get(self.channel_id)
        self.assertEqual(0, len(channel.clients))

        c1 = yield self._mk_client('foo')
        c2 = yield self._mk_client('bar')
        yield c1.read_message()  # C2's join

        send(c1, m('chat', 'hey!'))
        response = yield c2.read_message()

        self.assertEqual(
            {
                'sender': c1.config['id'],
                'kind': 'chat',
                'body': 'hey!'
            }, json.loads(response))
Example #24
0
    def test_create(self):
        meta = "common"
        channel_id = "test-channel"

        body = "&".join([
            "id={channel_id}",
            "meta={meta}",
        ]).format(**locals())

        response = json.loads(
            self.fetch('/channels/new', method='POST',
                       body=body).body.decode('utf8'))

        self.assertEqual({"meta": meta, "id": channel_id}, response)

        channel = Channels.get(channel_id)
        self.assertEqual(meta, channel.meta)
Example #25
0
    def test_stats(self):
        channel = Channels.create("test-channel", "common")
        response = json.loads(self.fetch(
            '/channels/'
        ).body.decode('utf8'))

        self.assertEqual({
            "connections": 0,
            "channels": 1
        }, response)

        channel.connections += 1
        response = json.loads(self.fetch(
            '/channels/'
        ).body.decode('utf8'))

        self.assertEqual({
            "connections": 1,
            "channels": 1
        }, response)
Example #26
0
    def test_create(self):
        meta = "common"
        channel_id = "test-channel"

        body = "&".join([
            "id={channel_id}",
            "meta={meta}",
        ]).format(**locals())

        response = json.loads(self.fetch(
            '/channels/new', method='POST',
            body=body
        ).body.decode('utf8'))

        self.assertEqual({
            "meta": meta,
            "id": channel_id
        }, response)

        channel = Channels.get(channel_id)
        self.assertEqual(meta, channel.meta)
Example #27
0
 def setUp(self):
     super(TestChatHandler, self).setUp()
     Channels.create(self.channel_id, self.meta)
Example #28
0
 def test_reset(self):
     Channels.create(self.channel_id, self.meta)
     self.assertTrue(Channels.exists(self.channel_id))
     Channels.reset()
     self.assertFalse(Channels.exists(self.channel_id))
Example #29
0
 def test_channel_delete(self):
     key = 'test-channel'
     Channels.create(key, 'common')
     yield gen.sleep(config.cleanup_period * 1.1)
     self.assertFalse(Channels.exists(key))
Example #30
0
 def setUp(self):
     super(TestChatHandler, self).setUp()
     Channels.create(self.channel_id, self.meta)
Example #31
0
    def get(self):

        self.write({
            "connections": Channels.connections(),
            "channels": Channels.count()
        })
Example #32
0
 def get_app(self):
     Channels.reset()
     return make_application()
Example #33
0
    def get(self):

        self.write({
            "connections": Channels.connections(),
            "channels": Channels.count()
        })
Example #34
0
 def test_does_not_exist(self):
     with self.assertRaises(ChannelDoesNotExist):
         Channels.get(self.channel_id)
Example #35
0
 def test_channel_no_delete(self):
     key = 'test-channel'
     c = Channels.create(key, 'common')
     c.join(Mock(nick='foo'))
     yield gen.sleep(config.cleanup_period * 1.1)
     self.assertTrue(Channels.exists(key))
Example #36
0
 def test_create(self):
     Channels.create(self.channel_id, self.meta)
     channel = Channels.get(self.channel_id)
     self.assertEqual(self.meta, channel.meta)
Example #37
0
 def get_app(self):
     Channels.reset()
     return make_application()
Example #38
0
 def setUp(self):
     super(TestChannels, self).setUp()
     Channels.reset()