コード例 #1
0
class TestStreamCases(TestCase):
    def setUp(self):
        hub_name = env("TEST_HUB")
        access_key = env("access_key")
        secret_key = env("secret_key")

        if access_key == "" or secret_key == "":
            raise SkipTest("need set access_key or secret_key")
        mac = Mac(access_key, secret_key)
        self.hub = Hub(mac, hub_name)
        self.stream_title = "streamTest" + str(int(random.random() * 1e10))

    def test_stream_create(self):
        items = self.hub.create(key=self.stream_title)
        self.assertEqual(items.status_code, 200)
        self.assertEqual(loads(items.text), {})

    def test_stream_disable(self):
        self.hub.create(key=self.stream_title)
        stream = self.hub.get(key=self.stream_title)
        self.assertEqual({}, loads(stream.disable(-1).text))
        self.assertEqual(-1, stream.refresh().get("disabledTill"))
        stream.disable(0)
        self.assertEqual(0, stream.refresh().get("disabledTill"))

    def test_stream_converts(self):
        stream = self.hub.get(key="test1")
        stream.update_converts(["480p", "720p"])
        self.assertEqual(stream.converts, ["480p", "720p"])

    # 这个测试需要维持推流test1
    def test_stream_saveas(self):
        stream = self.hub.get("test1")
        ret = stream.save_as()
        self.assertEqual(200, ret.status_code)
        now = int(time.time())
        ret = stream.saveas(start=now - 3600)
        self.assertIn(ret.status_code, (200, 619))
        ret = stream.save_as(start=now - 3600, end=now)
        self.assertIn(ret.status_code, (200, 619))
        ret = stream.saveas(start=now - 3600,
                            end=now,
                            fname="test1.m3u8",
                            format="m3u8")
        self.assertEqual(loads(ret.text).get("fname"), "test1.m3u8")
        ret = stream.save_as(start=now - 3600,
                             end=now,
                             fname="test1.mp4",
                             format="mp4")
        self.assertEqual(loads(ret.text).get("fname"), "test1.mp4")
        self.assertTrue(loads(ret.text).get("persistentID"))

    # 这个测试需要维持推流test1
    def test_stream_snashot(self):
        stream = self.hub.get("test1")
        ret = stream.snapshot(fname="test1.jpg")
        self.assertEqual(loads(ret.text)["fname"], "test1.jpg")

    # 这个测试需要维持推流test1
    def test_stream_history(self):
        stream = self.hub.get("test1")
        self.assertEqual(200, stream.history().status_code)
コード例 #2
0
# -*- coding: utf-8 -*-
"""
https://developer.qiniu.com/pili/api/2515/create-a-flow
创建流
"""

from pili import Mac, Hub

# 替换成自己 Qiniu 账号的 AccessKey
access_key = "..."

# 替换成自己 Qiniu 账号的 SecretKey
secret_key = "..."

hub_name = "..."

stream_name = "..."

mac = Mac(access_key, secret_key)

hub = Hub(mac, hub_name)

resp = hub.create(key=stream_name)

print(resp.status_code)
print(resp.headers)
print(resp.text)

print(hub.get(stream_name))
コード例 #3
0
class TestHubCases(TestCase):

    def setUp(self):
        hub_name = env("TEST_HUB")
        access_key = env("access_key")
        secret_key = env("secret_key")

        if access_key == "" or secret_key == "":
            raise SkipTest("need set access_key or secret_key")
        mac = Mac(access_key, secret_key)
        self.hub = Hub(mac, hub_name)

    # 这个测试case需要保持推流test1
    def test_batch_live_status(self):
        items = self.hub.batch_live_status(["test1", "test2"])
        self.assertEqual(items.status_code, 200)
        self.assertIn("test1", loads(items.text).get("items")[0].get("key"))

    def test_create_stream(self):
        self.stream_key = "streamtest" + str(int(random.random()*1e10))+str(time.time())[:10]
        items = self.hub.create(key=self.stream_key)
        self.assertEqual(items.status_code, 200)
        self.assertEqual({}, loads(items.text))

    def test_query_streams(self):
        items = self.hub.get("test1")
        self.assertNotEqual(None, items)

    def test_wm_create(self):
        test_name = "test" + str(int(time.time()))
        items = self.hub.wm_crete(name=test_name, comment="for_test1", left='50%',
                                  top='50%', width='10%', imageURL="http://omhrg3tgg.bkt.clouddn.com/413.png")
        self.assertEqual(items.status_code, 200)
        self.assertEqual(test_name, loads(items.text).get("name"))
        items1 = self.hub.wm_crete(name="test1", comment="for_test1", left='50%',
                                   top='50%', width='10%', imageURL="http://omhrg3tgg.bkt.clouddn.com/413.png")
        self.assertEqual(items1.status_code, 614)

    def test_wm_download(self):
        item = self.hub.wm_download(name="test1522373806")
        self.assertEqual(item.status_code, 200)

    def test_wm_list(self):
        items = self.hub.wm_list(limit=100)
        self.assertIn("items", loads(items.text))

    def test_wm_query(self):
        items = self.hub.wm_query("test1")
        self.assertEqual("test1", loads(items.text).get("name"))

    def test_bandwidth_detail(self):
        items = self.hub.bandwidth_count_detail(str(int(time.time())))
        self.assertIn("items", loads(items.text))

    def test_bandwidth_history(self):
        items = self.hub.bandwidth_count_history(start=int(time.time()) - 100,
                                                 end=int(time.time()), limit=100, marker=None)
        self.assertIn("items", loads(items.text))

    def test_bandwidth_now(self):
        items = self.hub.bandwidth_count_now()
        self.assertIn("total", loads(items.text))