def test_create_channel_status500(self):
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/add_channel.cgi' % epiphan_url, status=500)

        with pytest.raises(requests.HTTPError) as e:
            response = WebUiChannel.create_channel(client=self.c)
        assert '500 Server Error' in e.value.message
    def test_create_channel_status200(self):
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/add_channel.cgi' % epiphan_url,
                status=200,
                body='{"success": false}')

        with pytest.raises(IndiscernibleResponseFromWebUiError) as e:
            response = WebUiChannel.create_channel(client=self.c)
        assert 'expect response status 302, but got (200)' in e.value.message
    def test_create_channel_ok(self):
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/add_channel.cgi' % epiphan_url,
                status=302,
                location='/admin/channel57/mediasources')
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/channel57/mediasources' % epiphan_url, status=200)

        response = WebUiChannel.create_channel(client=self.c)
        assert int(response) == 57
    def test_create_channel_missing_location(self):
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/add_channel.cgi' % epiphan_url,
                status=302)
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/channel57/mediasources' % epiphan_url, status=200)

        with pytest.raises(IndiscernibleResponseFromWebUiError) as e:
            response = WebUiChannel.create_channel(client=self.c)
        assert 'location header missing' in e.value.message
    def test_create_channel_status301(self):
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/add_channel.cgi' % epiphan_url,
                status=301,
                location='/admin/channel57/mediasources')
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/channel57/mediasources' % epiphan_url, status=200)

        with pytest.raises(IndiscernibleResponseFromWebUiError) as e:
            response = WebUiChannel.create_channel(client=self.c)
        assert 'expect response STATUS 302, but got (301)' in e.value.message
    def test_create_channel_location_missing_id(self):
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/add_channel.cgi' % epiphan_url,
                status=302,
                location='/admin/channelXX/mediasources')
        httpretty.register_uri(
                httpretty.GET,
                '%s/admin/channelXX/mediasources' % epiphan_url, status=200)

        with pytest.raises(IndiscernibleResponseFromWebUiError) as e:
            response = WebUiChannel.create_channel(client=self.c)
        assert 'cannot parse channel created from location' in e.value.message