import json
from tornado import testing, httpserver

from qotr.server import make_application
from qotr.channels import Channels

class TestChannelHandler(testing.AsyncHTTPTestCase):
    '''
    Test the channel creation handler.
    '''

    port = None
    application = None

    def get_app(self):
        Channels.reset()
        return make_application()

    def test_create(self):
        salt = "common"
        channel_id = "test-channel"

        body = "&".join([
            "id={channel_id}",
            "salt={salt}",
            "key_hash=hmac-key"
        ]).format(**locals())

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

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


    def test_confict(self):
        body = "&".join([
            "id=common",
            "salt=test-channel",
            "key_hash=hmac-key"
        ])

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

        self.assertTrue("error" in response)

@@ -36,21 +36,9 @@
 ting
-, httpserver
 %0A
+
 %0Afro
@@ -429,16 +429,46 @@
 channel%22
+%0A        key_hash = 'hmac-key'
 %0A%0A      
@@ -563,32 +563,34 @@
   %22key_hash=
-hmac-key
+%7Bkey_hash%7D
 %22%0A        %5D)
@@ -825,16 +825,16 @@
 nnel_id%0A
-
         
@@ -847,16 +847,150 @@
 ponse)%0A%0A
+        channel = Channels.get(channel_id)%0A        self.assertEqual(salt, channel.salt)%0A        self.assertEqual(key_hash, key_hash)%0A%0A
 %0A    def

Make sure that the channel creation and storage works